protected void postSpecialize() { // Override qualifiers and the bean name Set<Annotation> qualifiers = new HashSet<Annotation>(); for (Annotation qualifier : attributes().getQualifiers()) { // Don't include implicit javax.enterprise.inject.Default qualifier if (!qualifier.equals(Default.Literal.INSTANCE) || getAnnotated().isAnnotationPresent(Default.class)) { qualifiers.add(qualifier); } } String name = attributes().getName(); for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) { qualifiers.addAll(specializedBean.getQualifiers()); if (specializedBean.getName() != null) { name = specializedBean.getName(); } } setAttributes(new ImmutableBeanAttributes<T>(qualifiers, name, attributes())); }
/** * Initializes specialization. This method is called before {@link ProcessBeanAttributes} is fired and also after the event * if the {@link BeanAttributes} have been altered. */ @Override public void preInitialize() { synchronized (this) { if (isSpecializing() && !preInitialized) { preInitialized = true; preSpecialize(); specialize(); checkSpecialization(); postSpecialize(); } } }
@Override public void initializeAfterBeanDiscovery() { checkType(); }
/** * Initializes the bean and its metadata */ @Override public void internalInitialize(BeanDeployerEnvironment environment) { preInitialize(); BeanLogger.LOG.creatingBean(getType()); if (getScope() != null) { proxyRequired = isNormalScoped(); } else { proxyRequired = false; } BeanLogger.LOG.qualifiersUsed(getQualifiers(), this); BeanLogger.LOG.usingName(getName(), this); BeanLogger.LOG.usingScope(getScope(), this); }
if (isSpecializing()) { boolean isNameDefined = getAnnotated().isAnnotationPresent(Named.class); String previousSpecializedBeanName = null; for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) { String name = specializedBean.getName(); if (previousSpecializedBeanName != null && name != null && !previousSpecializedBeanName.equals(specializedBean.getName())) { throw BeanLogger.LOG.beansWithDifferentBeanNamesCannotBeSpecialized(previousSpecializedBeanName, specializedBean.getName(), this); throw BeanLogger.LOG.nameNotAllowedOnSpecialization(getAnnotated(), specializedBean.getAnnotated()); && specializedBean.getBeanClass().getTypeParameters().length > 0 && !(((AbstractClassBean<?>) this).getBeanClass().getGenericSuperclass() instanceof ParameterizedType)); for (Type specializedType : specializedBean.getTypes()) { if (rawInsteadOfGeneric && specializedType instanceof ParameterizedType) { throw BeanLogger.LOG.specializingBeanMissingSpecializedType(this, specializedType, specializedBean); boolean contains = getTypes().contains(specializedType); if (!contains) { for (Type specializingType : getTypes()) {
public boolean isSpecializing() { return getAnnotated().isAnnotationPresent(Specializes.class); }
protected <T, S> boolean fireProcessBeanAttributes(AbstractBean<T, S> bean) { if (!specializationAndEnablementRegistry.isCandidateForLifecycleEvent(bean)) { return false; } ProcessBeanAttributesImpl<T> event = containerLifecycleEvents.fireProcessBeanAttributes(getManager(), bean, bean.getAnnotated(), bean.getType()); if (event == null) { return false; } if (event.isVeto()) { return true; } if (event.isDirty()) { bean.setAttributes(ExternalBeanAttributesFactory.<T>of(event.getBeanAttributesInternal(), manager)); bean.checkSpecialization(); } return false; } }
public void destroy(T instance, CreationalContext<T> creationalContext) { super.destroy(instance, creationalContext); try { getProducer().dispose(instance); } catch (Exception e) { BeanLogger.LOG.errorDestroying(instance, this); BeanLogger.LOG.catchingDebug(e); } finally { if (getDeclaringBean().isDependent()) { creationalContext.release(); } } }
protected Set<? extends AbstractBean<?, ?>> getSpecializedBeans() { return getBeanManager().getServices().get(SpecializationAndEnablementRegistry.class).resolveSpecializedBeans(this); }
public void addNewBeansFromInjectionPoints(AbstractBean<?, ?> bean) { addNewBeansFromInjectionPoints(bean.getInjectionPoints()); }
protected static <X> void fire(BeanManagerImpl beanManager, AbstractBean<X, ?> bean) { fire(beanManager, bean, bean.getAnnotated()); }
public void vetoBean(AbstractBean<?, ?> bean) { beans.remove(bean); if (bean instanceof AbstractClassBean<?>) { classBeanMap.get(bean.getBeanClass()).remove(bean); if (bean instanceof InterceptorImpl<?>) { interceptors.remove(bean); } if (bean instanceof DecoratorImpl<?>) { decorators.remove(bean); } } if (bean instanceof ProducerMethod<?, ?>) { ProducerMethod<?, ?> producerMethod = cast(bean); producerMethodBeanMap.get(WeldMethodKey.of(producerMethod)).remove(producerMethod); } if (bean instanceof ProducerField<?, ?>) { producerFields.remove(bean); } }
if (isSpecializing()) { boolean isNameDefined = getAnnotated().isAnnotationPresent(Named.class); String previousSpecializedBeanName = null; for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) { String name = specializedBean.getName(); if (previousSpecializedBeanName != null && name != null && !previousSpecializedBeanName.equals(specializedBean.getName())) { throw BeanLogger.LOG.beansWithDifferentBeanNamesCannotBeSpecialized(previousSpecializedBeanName, specializedBean.getName(), this); throw BeanLogger.LOG.nameNotAllowedOnSpecialization(getAnnotated(), specializedBean.getAnnotated()); && specializedBean.getBeanClass().getTypeParameters().length > 0 && !(((AbstractClassBean<?>) this).getBeanClass().getGenericSuperclass() instanceof ParameterizedType)); for (Type specializedType : specializedBean.getTypes()) { if (rawInsteadOfGeneric && specializedType instanceof ParameterizedType) { throw BeanLogger.LOG.specializingBeanMissingSpecializedType(this, specializedType, specializedBean); boolean contains = getTypes().contains(specializedType); if (!contains) { for (Type specializingType : getTypes()) {
public boolean isSpecializing() { return getAnnotated().isAnnotationPresent(Specializes.class); }
/** * Initializes the bean and its metadata */ @Override public void internalInitialize(BeanDeployerEnvironment environment) { preInitialize(); BeanLogger.LOG.creatingBean(getType()); if (getScope() != null) { proxyRequired = isNormalScoped(); } else { proxyRequired = false; } BeanLogger.LOG.qualifiersUsed(getQualifiers(), this); BeanLogger.LOG.usingName(getName(), this); BeanLogger.LOG.usingScope(getScope(), this); }
protected <T, S> boolean fireProcessBeanAttributes(AbstractBean<T, S> bean) { if (!specializationAndEnablementRegistry.isCandidateForLifecycleEvent(bean)) { return false; } ProcessBeanAttributesImpl<T> event = containerLifecycleEvents.fireProcessBeanAttributes(getManager(), bean, bean.getAnnotated(), bean.getType()); if (event == null) { return false; } if (event.isVeto()) { return true; } if (event.isDirty()) { bean.setAttributes(ExternalBeanAttributesFactory.<T>of(event.getBeanAttributesInternal(), manager)); bean.checkSpecialization(); } if (event.isIgnoreFinalMethods()) { bean.setIgnoreFinalMethods(); } return false; } }
public void destroy(T instance, CreationalContext<T> creationalContext) { super.destroy(instance, creationalContext); try { getProducer().dispose(instance); } catch (Exception e) { BeanLogger.LOG.errorDestroying(instance, this); BeanLogger.LOG.catchingDebug(e); } finally { if (getDeclaringBean().isDependent()) { creationalContext.release(); } } }
protected Set<? extends AbstractBean<?, ?>> getSpecializedBeans() { return getBeanManager().getServices().get(SpecializationAndEnablementRegistry.class).resolveSpecializedBeans(this); }
public void addNewBeansFromInjectionPoints(AbstractBean<?, ?> bean) { addNewBeansFromInjectionPoints(bean.getInjectionPoints()); }
protected static <X> void fire(BeanManagerImpl beanManager, AbstractBean<X, ?> bean) { fire(beanManager, bean, bean.getAnnotated()); }