Java Code Examples for javax.enterprise.inject.spi.InjectionPoint#getBean()

The following examples show how to use javax.enterprise.inject.spi.InjectionPoint#getBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Integer> produceIntegerListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Integer> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Integer.parseInt(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Integer property '" + configProperty.name() + "' value: " + value + " of "
                                + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 2
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Long> produceLongListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Long> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Long.parseLong(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + value + " of " + propertyValue
                                + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 3
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Float> produceFloatListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Float> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Float.parseFloat(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Float property '" + configProperty.name() + "' value: " + value + " of " + propertyValue
                                + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 4
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Double> produceDoubleListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Double> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Double.parseDouble(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Double property '" + configProperty.name() + "' value: " + value + " of "
                                + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 5
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Map<String,String> produceStringStringMapConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] pairs = StringUtils.split(propertyValue, "|");
    
    Map<String,String> map = new LinkedHashMap<>();
    if (pairs != null) {
        for (String pair : pairs) {
            String[] keyValue = StringUtils.split(pair, ";");
            if (keyValue != null && (keyValue.length == 1 || keyValue.length == 2)) {
                map.put(keyValue[0], keyValue.length == 1 ? "" : keyValue[1]);
            } else {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Map<String,String> property '" + configProperty.name() + "' pair: " + pair + " of "
                                + propertyValue + " happening in bean " + injectionPoint.getBean());
            }
        }
    }
    return map;
}
 
Example 6
Source File: DatawaveCommonConfigPropertyProducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Map<String,AuditType> produceStringAuditTypeMapConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] pairs = StringUtils.split(propertyValue, "|");
    
    Map<String,AuditType> map = new LinkedHashMap<>();
    if (pairs != null) {
        for (String pair : pairs) {
            String[] keyValue = StringUtils.split(pair, ";");
            if (keyValue != null && keyValue.length == 2) {
                map.put(keyValue[0], AuditType.valueOf(keyValue[1]));
            } else {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Map<String,AuditType> property '" + configProperty.name() + "' pair: " + pair + " of "
                                + propertyValue + " happening in bean " + injectionPoint.getBean());
            }
        }
    }
    return map;
}
 
Example 7
Source File: InstanceBean.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Instance<?> get(CreationalContext<Instance<?>> creationalContext) {
    // Obtain current IP to get the required type and qualifiers
    InjectionPoint ip = InjectionPointProvider.get();
    InstanceImpl<Instance<?>> instance = new InstanceImpl<Instance<?>>((InjectableBean<?>) ip.getBean(), ip.getType(),
            ip.getQualifiers(), (CreationalContextImpl<?>) creationalContext, Collections.EMPTY_SET, ip.getMember(), 0);
    CreationalContextImpl.addDependencyToParent((InjectableBean<Instance<?>>) ip.getBean(), instance, creationalContext);
    return instance;
}
 
Example 8
Source File: SubscriptionPublisherProducer.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Produces
@io.joynr.jeeintegration.api.SubscriptionPublisher
public SubscriptionPublisher getSubscriptionPublisher(InjectionPoint injectionPoint) {
    logger.info("Looking for subscription publisher for: {}", injectionPoint);
    logger.trace("Type {}, Member {}, Annotated {} ",
                 injectionPoint.getType(),
                 injectionPoint.getMember(),
                 injectionPoint.getAnnotated());
    Class beanClass = injectionPoint.getBean() == null ? injectionPoint.getMember().getDeclaringClass()
            : injectionPoint.getBean().getBeanClass();
    logger.info("Bean class is: {}", beanClass);
    if (!subscriptionPublishers.containsKey(beanClass)) {
        Class subscriptionPublisherClass = (Class) injectionPoint.getAnnotated().getBaseType();
        SubscriptionPublisher newSubscriptionPublisher = (SubscriptionPublisher) Proxy.newProxyInstance(subscriptionPublisherClass.getClassLoader(),
                                                                                                        new Class[]{
                                                                                                                subscriptionPublisherClass },
                                                                                                        new InvocationHandler() {
                                                                                                            @Override
                                                                                                            public Object invoke(Object proxy,
                                                                                                                                 Method method,
                                                                                                                                 Object[] args) throws Throwable {
                                                                                                                throw new IllegalStateException("No subscription publisher set for "
                                                                                                                        + subscriptionPublisherClass
                                                                                                                        + " on "
                                                                                                                        + beanClass);
                                                                                                            }
                                                                                                        });
        subscriptionPublishers.putIfAbsent(beanClass, newSubscriptionPublisher);
    }
    return subscriptionPublishers.get(beanClass);
}
 
Example 9
Source File: DefaultConfigPropertyProducer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private <T> T getPropertyWithException(InjectionPoint ip, Type ipCls)
{
    try
    {
        return getUntypedPropertyValue(ip, ipCls);
    }
    catch (RuntimeException rte)
    {
        ConfigProperty configProperty = getAnnotation(ip, ConfigProperty.class);
        throw new RuntimeException("Error while converting property '" + configProperty.name() +
                "' happening in bean " + ip.getBean(), rte);
    }
}
 
Example 10
Source File: SubscriptionPublisherCdiExtension.java    From joynr with Apache License 2.0 4 votes vote down vote up
public void alterSubscriptionPublishInjectionPoints(@Observes ProcessInjectionPoint processInjectionPoint) {
    final InjectionPoint injectionPoint = processInjectionPoint.getInjectionPoint();
    logger.info("Looking at injection point: {}", injectionPoint);
    if (injectionPoint.getType() instanceof Class
            && SubscriptionPublisher.class.isAssignableFrom((Class) injectionPoint.getType())) {
        logger.info("Re-writing injection point type from {} to {} on bean {}",
                    injectionPoint.getType(),
                    SubscriptionPublisher.class,
                    injectionPoint.getBean());
        final Bean<?> bean = injectionPoint.getBean();
        InjectionPoint newInjectionPoint = new InjectionPoint() {
            @Override
            public Type getType() {
                return SubscriptionPublisher.class;
            }

            @Override
            public Set<Annotation> getQualifiers() {
                return injectionPoint.getQualifiers();
            }

            @Override
            public Bean<?> getBean() {
                return bean;
            }

            @Override
            public Member getMember() {
                return injectionPoint.getMember();
            }

            @Override
            public Annotated getAnnotated() {
                return injectionPoint.getAnnotated();
            }

            @Override
            public boolean isDelegate() {
                return injectionPoint.isDelegate();
            }

            @Override
            public boolean isTransient() {
                return injectionPoint.isTransient();
            }
        };
        processInjectionPoint.setInjectionPoint(newInjectionPoint);
    }
}