WebBeansContext wbc = beanManager.getWebBeansContext(); AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory();
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void createAnnotatedTypeForExistingBeanClass(BeanManagerImpl beanManager, InjectionTargetBean bean) { WebBeansContext wbc = beanManager.getWebBeansContext(); AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory(); // Clear AnnotatedElementFactory caches annotatedElementFactory.clear(); AnnotatedType annotatedType = annotatedElementFactory.newAnnotatedType(bean.getBeanClass()); ReflectionHelper.set(bean, InjectionTargetBean.class, "annotatedType", annotatedType); // Updated members that were set by bean attributes BeanAttributesImpl attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build(); ReflectionHelper.set(bean, BeanAttributesImpl.class, "types", attributes.getTypes()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "qualifiers", attributes.getQualifiers()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "scope", attributes.getScope()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "name", attributes.getName()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "stereotypes", attributes.getStereotypes()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "alternative", attributes.isAlternative()); InjectionTargetFactory factory = new InjectionTargetFactoryImpl(annotatedType, bean.getWebBeansContext()); InjectionTarget injectionTarget = factory.createInjectionTarget(bean); ReflectionHelper.set(bean, InjectionTargetBean.class, "injectionTarget", injectionTarget); LOGGER.debug("New annotated type created for bean '{}'", bean.getBeanClass()); }
private <T> AnnotatedType<T> getOrCreateAnnotatedType(Class<T> type) { AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().getAnnotatedType(type); if (annotatedType == null) { annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(type); } return annotatedType; }
/** * Creates a new {@link BeanManager} instance. * Called by the system. Do not use outside of the * system. */ public BeanManagerImpl(WebBeansContext webBeansContext) { this.webBeansContext = webBeansContext; injectionResolver = new InjectionResolver(webBeansContext); annotatedElementFactory = webBeansContext.getAnnotatedElementFactory(); }
protected AnnotatedType<? super M> getSuperType() { Class<? super M> superclass = getAnnotated().getDeclaringType().getJavaClass().getSuperclass(); if (superclass == null) { return null; } return webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass); } }
protected AnnotatedType<?> getSuperType() { Class<?> superclass = annotatedMember.getDeclaringType().getJavaClass().getSuperclass(); if (superclass == null) { return null; } return parent.getWebBeansContext().getAnnotatedElementFactory().getAnnotatedType(superclass); }
private <T> AnnotatedTypeConfiguratorImpl<T> getAnnotatedTypeConfigurator(Class<T> clazz) { AnnotatedType<T> initialAnnotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz); return (AnnotatedTypeConfiguratorImpl<T>) new AnnotatedTypeConfiguratorImpl(webBeansContext, initialAnnotatedType); } }
private <T> AnnotatedTypeConfiguratorImpl<T> getAnnotatedTypeConfigurator(Class<T> clazz) { AnnotatedType<T> initialAnnotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz); return (AnnotatedTypeConfiguratorImpl<T>) new AnnotatedTypeConfiguratorImpl(webBeansContext, initialAnnotatedType); } }
private void collectPreDestroyMethods(Class<?> type, List<AnnotatedMethod<?>> preDestroyMethods) { if (type == null) { return; } collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods); for (AnnotatedMethod<?> annotatedMethod: webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType)) { if (annotatedMethod.getJavaMember().getDeclaringClass() == type && annotatedMethod.isAnnotationPresent(PreDestroy.class) && annotatedMethod.getParameters().isEmpty()) { preDestroyMethods.add(annotatedMethod); } } } }
public ExtensionBeanBuilder(WebBeansContext webBeansContext, Class<T> type) { Asserts.assertNotNull(webBeansContext, Asserts.PARAM_NAME_WEBBEANSCONTEXT); Asserts.assertNotNull(type, "type"); this.webBeansContext = webBeansContext; annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(type); }
/** * Creates a new extesion bean. * * @param returnType return type * @param webBeansContext */ public ExtensionBean(WebBeansContext webBeansContext, Class<T> returnType) { super(webBeansContext, WebBeansType.EXTENSION, new BeanAttributesImpl<>( webBeansContext.getAnnotatedElementFactory().getAnnotatedType(returnType).getTypeClosure(), AnnotationUtil.DEFAULT_AND_ANY_ANNOTATION_SET, ApplicationScoped.class), returnType, false, new ExtensionProducerFactory<>(webBeansContext.getAnnotatedElementFactory().getAnnotatedType(returnType), webBeansContext)); }
public void defineCdiInterceptorRules() { checkInterceptorConditions(); defineInterceptorMethods(); defineInterceptorBindings(); validateTarget(); // make sure that CDI interceptors do not have any Producer methods or a method with @Observes validateNoProducerOrObserverMethod(annotatedType); // make sure that CDI interceptors do not have a Disposes method validateNoDisposerWithoutProducer(webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); }
protected void checkInterceptorConditions() { Set<AnnotatedMethod<? super T>> methods = webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType); for(AnnotatedMethod<?> method : methods) { for (AnnotatedParameter<?> parameter : method.getParameters()) { if (parameter.isAnnotationPresent(Produces.class)) { throw new WebBeansConfigurationException("Interceptor class : " + annotatedType.getJavaClass() + " can not have producer methods but it has one with name : " + method.getJavaMember().getName()); } } } }
/** * Returns <code>ProcessInjectionTarget</code> event. * @param <T> bean type * @return event */ public <T> GProcessInjectionTarget fireProcessInjectionTargetEventForJavaEeComponents(Class<T> componentClass) { AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(componentClass); InjectionTargetImpl<T> injectionTarget = InjectionTargetImpl.class.cast(webBeansContext.getBeanManagerImpl().createInjectionTarget(annotatedType)); GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,annotatedType); //Fires ProcessInjectionTarget return fireProcessInjectionTargetEvent(processInjectionTargetEvent); }
@Override public void defineInterceptorStack(final Bean<T> bean, final AnnotatedType<T> annotatedType, final WebBeansContext webBeansContext) { super.defineInterceptorStack(bean, isDynamicBean(bean) ? (AnnotatedType<T>) webBeansContext.getAnnotatedElementFactory() .newAnnotatedType(CdiEjbBean.class.cast(bean).getBeanContext().getManagedClass()) : annotatedType, webBeansContext); }
private ConstructorInjectionBean<Object> createConstructorInjectionBean(final WebBeansContext webBeansContext) { if (constructorInjectionBean != null) { return constructorInjectionBean; } synchronized (this) { // concurrentmodificationexception because of annotatedtype internals otherwise if (constructorInjectionBean == null) { constructorInjectionBean = new ConstructorInjectionBean<Object>( webBeansContext, getManagedClass(), webBeansContext.getAnnotatedElementFactory().newAnnotatedType(getManagedClass())); } } return constructorInjectionBean; }
/** * Performs injection on initializer methods, which are methods that are annotated with @Inject, * but have no parameter and thus no injection point. */ private void injectInitializerMethods(Class<?> declaringType, T instance, CreationalContextImpl<T> context) { for (AnnotatedMethod<? super T> method : webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType)) { if (method.getDeclaringType().getJavaClass().equals(declaringType) && method.isAnnotationPresent(Inject.class) && method.getParameters().isEmpty()) { new InjectableMethod<>(method.getJavaMember(), instance, this, context).doInjection(); } } }
private ConstructorInjectionBean<Object> createConstructorInjectionBean(final WebBeansContext webBeansContext) { if (constructorInjectionBean != null) { return constructorInjectionBean; } synchronized (this) { // concurrentmodificationexception because of annotatedtype internals otherwise if (constructorInjectionBean == null) { constructorInjectionBean = new ConstructorInjectionBean<Object>( webBeansContext, getManagedClass(), webBeansContext.getAnnotatedElementFactory().newAnnotatedType(getManagedClass())); } } return constructorInjectionBean; }
public void validateInterceptorClasses() { for(Class<?> interceptorClass : configuredInterceptorClasses) { AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(interceptorClass); // Validate decorator classes if(!annotatedType.isAnnotationPresent(javax.interceptor.Interceptor.class) && !containsCustomInterceptorClass(interceptorClass)) { throw new WebBeansDeploymentException("Given class : " + interceptorClass + " is not a interceptor class"); } } }
public <T> Bean<T> createNewComponent(Class<T> type) { Asserts.nullCheckForClass(type); OpenWebBeansEjbPlugin ejbPlugin = webBeansContext.getPluginLoader().getEjbPlugin(); if (ejbPlugin != null && ejbPlugin.isNewSessionBean(type)) { return ejbPlugin.defineNewSessionBean(type); } AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(type); BeanAttributesImpl<T> defaultBeanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(annotatedType).build(); BeanAttributesImpl<T> newBeanAttributes = new BeanAttributesImpl<>(defaultBeanAttributes.getTypes(), Collections.<Annotation>singleton(new NewLiteral(type))); // TODO replace this by InjectionPointBuilder ManagedBeanBuilder<T, ManagedBean<T>> beanBuilder = new ManagedBeanBuilder<>(webBeansContext, annotatedType, newBeanAttributes, false); NewManagedBean<T> newBean = new NewManagedBean<>(webBeansContext, WebBeansType.MANAGED, annotatedType, newBeanAttributes, type, beanBuilder.getBean().getInjectionPoints()); return newBean; }