/** * {@inheritDoc} */ @Override protected String getConfiguredValue(String key) { return CodiUtils.lookupConfigFromEnvironment(key, String.class, ""); } }
RestConversationExpirationEvaluator(BeanManager beanManager, AccessDecisionVoterContext accessDecisionVoterContext) { this.accessDecisionVoterContext = accessDecisionVoterContext; this.restParameters = CodiUtils.getContextualReferenceByClass(beanManager, RestParameters.class); }
private JsfRequestLifecycleBroadcaster resolveBroadcaster() { //cdi has to inject the event return getContextualReferenceByName( this.beanManager, BEAN_NAME, JsfRequestLifecycleBroadcaster.class); }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-class and qualifiers. * Compared to the other util methods it allows optional beans. * @param beanManager current bean-manager * @param targetClass class of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param qualifier optional qualifiers * @param <T> target type * @return created or resolved instance if such a bean exists, null otherwise */ public static <T> T getContextualReferenceByClass(BeanManager beanManager, Class<T> targetClass, boolean optionalBeanAllowed, Annotation... qualifier) { Bean<?> foundBean = getOrCreateBeanByClass(beanManager, targetClass, optionalBeanAllowed, qualifier); if(foundBean != null) { //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, foundBean); } return null; }
/** * Allows to perform dependency injection for instances which aren't managed by CDI * @param instance current instance * @param <T> current type * @return instance with injected fields (if possible) */ public static <T> T injectFields(T instance) { CodiCoreConfig codiCoreConfig = getContextualReferenceByClass(CodiCoreConfig.class); return injectFields(instance, codiCoreConfig.isAdvancedQualifierRequiredForDependencyInjection()); }
List<Method> bindingQualifierMethods = getBindingQualifierMethods(qualifier1AnnotationType); Object value1 = callMethod(qualifier1, method); Object value2 = callMethod(qualifier2, method); if (!checkEquality(value1, value2))
/** * Resolves resources outside of CDI for the given class. * @param targetType target type * @param defaultImplementation default implementation * @param <T> current type * @return configured artifact or null if there is no result */ public static <T extends Serializable> T lookupFromEnvironment(Class<T> targetType, T... defaultImplementation) { return lookupFromEnvironment(targetType, null, defaultImplementation); }
/** * Performs dependency injection manually (if permitted). * {@inheritDoc} */ public Converter createConverter(Class targetClass) { return injectFields(this.wrapped.createConverter(targetClass), this.advancedQualifierRequiredForDependencyInjection); }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-name and class * @param beanManager current bean-manager * @param beanName name of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param targetClass class of the bean * @param <T> target type * @return created or resolved instance */ public static <T> T getContextualReferenceByName( BeanManager beanManager, String beanName, boolean optionalBeanAllowed, Class<T> targetClass) { Set<Bean<?>> foundBeans = beanManager.getBeans(beanName); if(foundBeans.size() >= 1) { Bean<?> bean = beanManager.resolve(foundBeans); //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, bean); } if(!optionalBeanAllowed) { throw new IllegalStateException("No bean found for type: " + targetClass.getName() + " and name " + beanName); } return null; }
protected synchronized void createNewBeanInstance() { if(this.currentBeanInstance != null) { return; } this.currentBeanInstance = createNewInstanceOfBean(this.creationalContext, getBean()); if(this.scopeBeanEventEnable) { //we don't have to check the implementation of Serializable - cdi already checked it this.beanManager.fireEvent(new ScopeBeanEvent((Serializable)this.currentBeanInstance)); } }
T... defaultImplementation) checkDefaultImplementation(defaultImplementation);
/** * Resolves resources outside of CDI for the given class. * @param targetType target type * @param defaultImplementation default implementation * @param <T> current type * @return configured artifact or null if there is no result */ public static <T extends Serializable> T lookupFromEnvironment(Class<T> targetType, T... defaultImplementation) { return lookupFromEnvironment(targetType, null, defaultImplementation); }
/** * {@inheritDoc} */ @SuppressWarnings({"unchecked"}) public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> targetClass) { T validator = this.wrapped.getInstance(targetClass); return injectFields(validator, false); } }
List<Method> bindingQualifierMethods = getBindingQualifierMethods(qualifier1AnnotationType); Object value1 = callMethod(qualifier1, method); Object value2 = callMethod(qualifier2, method); if (!checkEquality(value1, value2))
/** * Allows to perform dependency injection for instances which aren't managed by CDI * @param instance current instance * @param <T> current type * @return instance with injected fields (if possible) */ public static <T> T injectFields(T instance) { CodiCoreConfig codiCoreConfig = getContextualReferenceByClass(CodiCoreConfig.class); return injectFields(instance, codiCoreConfig.isAdvancedQualifierRequiredForDependencyInjection()); }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-class and qualifiers. * Compared to the other util methods it allows optional beans. * @param beanManager current bean-manager * @param targetClass class of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param qualifier optional qualifiers * @param <T> target type * @return created or resolved instance if such a bean exists, null otherwise */ public static <T> T getContextualReferenceByClass(BeanManager beanManager, Class<T> targetClass, boolean optionalBeanAllowed, Annotation... qualifier) { Bean<?> foundBean = getOrCreateBeanByClass(beanManager, targetClass, optionalBeanAllowed, qualifier); if(foundBean != null) { //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, foundBean); } return null; }
/** * Creates a scoped instance (a proxy for normal scoped beans) for the given bean-name and class * @param beanManager current bean-manager * @param beanName name of the bean * @param optionalBeanAllowed flag which indicates if it's an optional bean * @param targetClass class of the bean * @param <T> target type * @return created or resolved instance */ public static <T> T getContextualReferenceByName( BeanManager beanManager, String beanName, boolean optionalBeanAllowed, Class<T> targetClass) { Set<Bean<?>> foundBeans = beanManager.getBeans(beanName); if(foundBeans.size() >= 1) { Bean<?> bean = beanManager.resolve(foundBeans); //noinspection unchecked return (T) getContextualReference(beanManager, targetClass, bean); } if(!optionalBeanAllowed) { throw new IllegalStateException("No bean found for type: " + targetClass.getName() + " and name " + beanName); } return null; }
protected synchronized void createNewBeanInstance() { if(this.currentBeanInstance != null) { return; } this.currentBeanInstance = createNewInstanceOfBean(this.creationalContext, getBean()); if(this.scopeBeanEventEnable) { //we don't have to check the implementation of Serializable - cdi already checked it this.beanManager.fireEvent(new ScopeBeanEvent((Serializable)this.currentBeanInstance)); } }
T... defaultImplementation) checkDefaultImplementation(defaultImplementation);
/** * {@inheritDoc} */ @Override protected String getConfiguredValue(String key) { return CodiUtils.lookupConfigFromEnvironment(key, String.class, ""); } }