/** * Replace the general producer method BeanAttributes with one bound to the collected injection site * types to properly reflect all of the type locations the producer method applies to. * * @param pba the ProcessBeanAttributes * @see ClaimProviderBeanAttributes */ public void addTypeToClaimProducer(@Observes ProcessBeanAttributes pba) { if (pba.getAnnotated().isAnnotationPresent(Claim.class)) { Claim claim = pba.getAnnotated().getAnnotation(Claim.class); if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) { log.debugf("addTypeToClaimProducer: %s\n", pba.getAnnotated()); BeanAttributes delegate = pba.getBeanAttributes(); String name = delegate.getName(); if (delegate.getTypes().contains(Optional.class)) { if (providerOptionalTypes.size() == 0) { providerOptionalTypes.add(Optional.class); } pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, providerOptionalTypes, providerQualifiers)); } else if (name != null && name.startsWith("RawClaimTypeProducer#")) { if (rawTypes.size() == 0) { rawTypes.add(Object.class); } pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, rawTypes, rawTypeQualifiers)); log.debugf("Setup RawClaimTypeProducer BeanAttributes"); } } } }
/** * Decorate the ConfigPropertyProducer BeanAttributes to set the types the producer applies to. This set is collected * from all injection points annotated with @ConfigProperty. * * @param delegate - the original producer method BeanAttributes * @param types - the full set of @ConfigProperty injection point types */ public ClaimProviderBeanAttributes(BeanAttributes<Object> delegate, Set<Type> types, Set<Annotation> qualifiers) { this.delegate = delegate; this.types = types; this.qualifiers = qualifiers; if (types.size() == 0) { Thread.dumpStack(); } }
/** * Generates a unique signature for {@link BeanAttributes}. */ static String createBeanAttributesId(BeanAttributes<?> attributes) { return Stream.of(attributes.getName(), attributes.getScope().getName(), createAnnotationCollectionId(attributes.getQualifiers()), createTypeCollectionId(attributes.getTypes())) .filter(Objects::nonNull) .collect(joining(",")); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void doDefineNewManagedBean(BeanManagerImpl beanManager, String bdaId, Class<?> beanClass) { try { ClassTransformer classTransformer = getClassTransformer(); SlimAnnotatedType<?> annotatedType = classTransformer.getBackedAnnotatedType(beanClass, bdaId); boolean managedBeanOrDecorator = Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType); if (managedBeanOrDecorator) { EnhancedAnnotatedType eat = EnhancedAnnotatedTypeImpl.of(annotatedType, classTransformer); BeanAttributes attributes = BeanAttributesFactory.forBean(eat, beanManager); ManagedBean<?> bean = ManagedBean.of(attributes, eat, beanManager); Field field = beanManager.getClass().getDeclaredField("beanSet"); field.setAccessible(true); field.set(beanManager, Collections.synchronizedSet(new HashSet<Bean<?>>())); // TODO: beanManager.addBean(bean); beanManager.getBeanResolver().clear(); bean.initializeAfterBeanDiscovery(); // define managed bean // beanManager.cleanupAfterBoot(); LOGGER.debug("Bean defined '{}'", beanClass.getName()); } else { // TODO : define session bean LOGGER.warning("Bean NOT? defined '{}', session bean?", beanClass.getName()); } } catch (Exception e) { LOGGER.debug("Bean definition failed.", e); } }
public CdiEjbBean(final BeanContext bc, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType<T> at, final InjectionTargetFactoryImpl<T> factory, final BeanAttributes<T> attributes) { super(webBeansContext, toSessionType(bc.getComponentType()), at, new EJBBeanAttributesImpl<T>(bc, attributes), beanClass, factory); this.beanContext = bc; bc.set(Bean.class, this); passivatingId = bc.getDeploymentID() + getReturnType().getName(); final boolean stateful = BeanType.STATEFUL.equals(bc.getComponentType()); final boolean isDependent = getScope().equals(Dependent.class); isDependentAndStateful = isDependent && stateful; if (webBeansContext.getBeanManagerImpl().isPassivatingScope(getScope()) && stateful) { if (!getBeanContext().isPassivable()) { throw new DefinitionException( getBeanContext().getBeanClass() + " is a not apssivation-capable @Stateful with a scope " + getScope().getSimpleName() + " which need passivation"); } passivable = true; } else { passivable = false; } if (!isDependent) { for (final Type type : attributes.getTypes()) { if (ParameterizedType.class.isInstance(type)) { throw new DefinitionException("Parameterized session bean should be @Dependent: " + beanClass); } } } if (getAnnotatedType().isAnnotationPresent(Interceptor.class) || getAnnotatedType().isAnnotationPresent(Decorator.class)) { throw new DefinitionException("An EJB can't be an interceptor or a decorator: " + beanClass); } }
DriverBeanAttributes(BeanAttributes<T> beanAttributes, String profile) { delegate = beanAttributes; this.profile = profile; }
OrientBeanAttributes(BeanAttributes<T> delegate, String profile) { this.delegate = delegate; this.profile = profile; }
private <T> Bean<T> getBean(BeanManager beanManager, Class<T> beanClass, String profile) { BeanAttributes<T> beanAttributes = beanManager.createBeanAttributes(beanManager.createAnnotatedType(beanClass)); return beanManager.createBean(new OrientBeanAttributes<>(beanAttributes, profile), beanClass, new OrientProducerFactory<>(beanClass, profile)); }
ClusterBeanAttributes(BeanAttributes<T> beanAttributes, String profile) { delegate = beanAttributes; this.profile = profile; }
SessionBeanAttributes(BeanAttributes<T> beanAttributes, String profile) { delegate = beanAttributes; this.profile = profile; }
MongoClientBeanAttributes(BeanAttributes<T> beanAttributes, String profile) { delegate = beanAttributes; this.profile = profile; }
MongoDatabaseBeanAttributes(BeanAttributes<T> beanAttributes, String profile) { delegate = beanAttributes; this.profile = profile; }
@SuppressWarnings("unused") <T> void processBeanAttributes(@Observes ProcessBeanAttributes<T> pba, BeanManager beanManager) throws Exception { final BeanAttributes<T> beanAttributes = pba.getBeanAttributes(); if (beanAttributes.getTypes().contains(Archive.class)) { if (!DeploymentScoped.class.isAssignableFrom(beanAttributes.getScope())) { pba.setBeanAttributes(new BeanAttributes<T>() { @Override public Set<Type> getTypes() { return beanAttributes.getTypes(); } @Override public Set<Annotation> getQualifiers() { Set<Annotation> qualifiers = new HashSet<>(); qualifiers.addAll(beanAttributes.getQualifiers()); qualifiers.add(ImplicitDeployment.Literal.INSTANCE); qualifiers.removeIf(e -> Default.class.isAssignableFrom(e.getClass())); return qualifiers; } @Override public Class<? extends Annotation> getScope() { return beanAttributes.getScope(); } @Override public String getName() { return beanAttributes.getName(); } @Override public Set<Class<? extends Annotation>> getStereotypes() { return beanAttributes.getStereotypes(); } @Override public boolean isAlternative() { return beanAttributes.isAlternative(); } }); } } }
@Override public <T> BeanAttributes<T> createBeanAttributes(AnnotatedType<T> type) { // TODO Auto-generated method stub return null; }
@Override public BeanAttributes<?> createBeanAttributes(AnnotatedMember<?> type) { // TODO Auto-generated method stub return null; }
@Override public <T> Bean<T> createBean(BeanAttributes<T> attributes, Class<T> beanClass, InjectionTargetFactory<T> injectionTargetFactory) { // TODO Auto-generated method stub return null; }
@Override public <T, X> Bean<T> createBean(BeanAttributes<T> attributes, Class<X> beanClass, ProducerFactory<X> producerFactory) { // TODO Auto-generated method stub return null; }
MongoClientBeanAttributes(BeanAttributes<MongoClient> beanAttributes) { delegate = beanAttributes; }
BeanAlternative(BeanAttributes<T> attributes, Set<? extends Annotation> qualifiers) { this.attributes = attributes; Set<Annotation> annotations = new HashSet<>(attributes.getQualifiers()); annotations.addAll(qualifiers); this.qualifiers = unmodifiableSet(annotations); }
@Override public <T> Bean<T> createBean(final BeanAttributes<T> arg0, final Class<T> arg1, final InjectionTargetFactory<T> arg2) { return this.beanManager.createBean(arg0, arg1, arg2); }
@Override public <T, X> Bean<T> createBean(final BeanAttributes<T> arg0, final Class<X> arg1, final ProducerFactory<X> arg2) { return this.beanManager.createBean(arg0, arg1, arg2); }
@Override public <T> BeanAttributes<T> createBeanAttributes( final AnnotatedType<T> arg0) { return this.beanManager.createBeanAttributes(arg0); }
@Override public BeanAttributes<?> createBeanAttributes(final AnnotatedMember<?> arg0) { return this.beanManager.createBeanAttributes(arg0); }
public <T> BeanAttributes<T> createBeanAttributes(final AnnotatedType<T> type) { return new CdiEjbBean.EJBBeanAttributesImpl( findBeanContext(webBeansContext, type.getJavaClass()), BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(type).build()); }
public CdiEjbBean(final BeanContext beanContext, final WebBeansContext webBeansContext, final AnnotatedType<T> at, final BeanAttributes<T> attributes) { this(beanContext, webBeansContext, beanContext.getManagedClass(), at, new EjbInjectionTargetFactory<T>(beanContext, at, webBeansContext), attributes); EjbInjectionTargetImpl.class.cast(getInjectionTarget()).setCdiEjbBean(this); }
public EJBBeanAttributesImpl(final BeanContext bc, final BeanAttributes<T> beanAttributes) { super(beanAttributes, false); this.beanContext = bc; this.ejbTypes = new HashSet<Type>(); initTypes(); }
public OpenEJBBeanBuilder(final BeanContext bc, final WebBeansContext webBeansContext, final AnnotatedType<A> annotatedType, final BeanAttributes<A> attributes) { super(webBeansContext, annotatedType, attributes); this.beanContext = bc; }