Search in sources :

Example 1 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.

the class EjbSupportImpl method createNewSessionBeans.

@Override
public void createNewSessionBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) {
    final SlimAnnotatedTypeStore store = manager.getServices().get(SlimAnnotatedTypeStore.class);
    final ClassTransformer classTransformer = manager.getServices().get(ClassTransformer.class);
    for (Type type : environment.getNewBeanTypes()) {
        Class<?> clazz = Reflections.getRawType(type);
        if (isEjb(clazz)) {
            EnhancedAnnotatedType<?> enhancedType = classTransformer.getEnhancedAnnotatedType(clazz, type, manager.getId());
            InternalEjbDescriptor<?> descriptor = ejbDescriptors.getUnique(clazz);
            environment.addSessionBean(createNewSessionBean(enhancedType, descriptor, manager, store));
        }
    }
}
Also used : EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) Type(java.lang.reflect.Type) SlimAnnotatedType(org.jboss.weld.annotated.slim.SlimAnnotatedType) SlimAnnotatedTypeStore(org.jboss.weld.annotated.slim.SlimAnnotatedTypeStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer)

Example 2 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.

the class Decorators method checkAbstractMethods.

/**
 * Check all abstract methods are declared by the decorated types.
 *
 * @param type
 * @param beanManager
 * @param delegateType
 * @throws DefinitionException If any of the abstract methods is not declared by the decorated types
 */
public static <T> void checkAbstractMethods(Set<Type> decoratedTypes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) {
    if (decoratedTypes == null) {
        decoratedTypes = new HashSet<Type>(type.getInterfaceClosure());
        decoratedTypes.remove(Serializable.class);
    }
    Set<MethodSignature> signatures = new HashSet<MethodSignature>();
    for (Type decoratedType : decoratedTypes) {
        for (EnhancedAnnotatedMethod<?, ?> method : ClassTransformer.instance(beanManager).getEnhancedAnnotatedType(Reflections.getRawType(decoratedType), beanManager.getId()).getEnhancedMethods()) {
            signatures.add(method.getSignature());
        }
    }
    for (EnhancedAnnotatedMethod<?, ?> method : type.getEnhancedMethods()) {
        if (Reflections.isAbstract(((AnnotatedMethod<?>) method).getJavaMember())) {
            MethodSignature methodSignature = method.getSignature();
            if (!signatures.contains(methodSignature)) {
                throw BeanLogger.LOG.abstractMethodMustMatchDecoratedType(method, Formats.formatAsStackTraceElement(method.getJavaMember()));
            }
        }
    }
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) MethodSignature(org.jboss.weld.annotated.enhanced.MethodSignature) HashSet(java.util.HashSet)

Example 3 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.

the class Validator method validateDecorator.

protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) {
    if (decorator.getDecoratedTypes().isEmpty()) {
        throw ValidatorLogger.LOG.noDecoratedTypes(decorator);
    }
    if (!decorator.getScope().equals(Dependent.class)) {
        throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator);
    }
    Decorators.checkDelegateType(decorator);
    /*
         * Validate decorators of facade built-in beans
         */
    Type delegateType = decorator.getDelegateType();
    if (delegateType instanceof ParameterizedType) {
        ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType;
        if (!Decorators.isPassivationCapable(decorator)) {
            if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) {
                throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName());
            }
            if (Event.class.equals(parameterizedDelegateType.getRawType())) {
                throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Event.class.getName());
            }
        }
    }
    if (decorator instanceof WeldDecorator<?>) {
        EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated();
        if (decorator instanceof DecoratorImpl<?>) {
            // Discovered decorator bean - abstract methods and delegate injection point are validated during bean initialization
            validateRIBean((CommonBean<?>) decorator, manager, specializedBeans);
            // Following checks are not legal for custom decorator beans as we cannot rely on decorator bean class methods
            if (!BeanMethods.getObserverMethods(annotated).isEmpty() || !BeanMethods.getAsyncObserverMethods(annotated).isEmpty()) {
                throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator);
            }
            while (annotated != null && annotated.getJavaClass() != Object.class) {
                if (!annotated.getDeclaredEnhancedMethods(Produces.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveProducerMethods(decorator);
                }
                if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator);
                }
                if (!annotated.getDeclaredEnhancedMethodsWithAnnotatedParameters(Disposes.class).isEmpty()) {
                    throw ValidatorLogger.LOG.decoratorsCannotHaveDisposerMethods(decorator);
                }
                annotated = annotated.getEnhancedSuperclass();
            }
        } else {
            // Custom decorator bean
            validateGeneralBean(decorator, manager);
            Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) WeldDecorator(org.jboss.weld.bean.WeldDecorator) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) Instance(javax.enterprise.inject.Instance) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) Event(javax.enterprise.event.Event) Dependent(javax.enterprise.context.Dependent) Provider(javax.inject.Provider)

Example 4 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.

the class SubclassedComponentInstantiator method createEnhancedSubclass.

protected Class<T> createEnhancedSubclass(EnhancedAnnotatedType<T> type, Bean<?> bean, BeanManagerImpl manager) {
    Set<InterceptionModel> models = getInterceptionModelsForType(type, manager, bean);
    Set<MethodSignature> enhancedMethodSignatures = new HashSet<MethodSignature>();
    Set<MethodSignature> interceptedMethodSignatures = (models == null) ? enhancedMethodSignatures : new HashSet<MethodSignature>();
    for (AnnotatedMethod<?> method : Beans.getInterceptableMethods(type)) {
        enhancedMethodSignatures.add(MethodSignatureImpl.of(method));
        if (models != null) {
            for (InterceptionModel model : models) {
                if (!model.getInterceptors(InterceptionType.AROUND_INVOKE, method.getJavaMember()).isEmpty()) {
                    interceptedMethodSignatures.add(MethodSignatureImpl.of(method));
                    break;
                }
            }
        }
    }
    Set<Type> types = null;
    if (bean == null) {
        types = Collections.<Type>singleton(type.getJavaClass());
    } else {
        types = bean.getTypes();
    }
    return new InterceptedSubclassFactory<T>(manager.getContextId(), type.getJavaClass(), types, bean, enhancedMethodSignatures, interceptedMethodSignatures).getProxyClass();
}
Also used : InterceptionType(org.jboss.weld.interceptor.spi.model.InterceptionType) Type(java.lang.reflect.Type) SlimAnnotatedType(org.jboss.weld.annotated.slim.SlimAnnotatedType) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) MethodSignature(org.jboss.weld.annotated.enhanced.MethodSignature) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) HashSet(java.util.HashSet)

Example 5 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project HotswapAgent by HotswapProjects.

the class BeanReloadExecutor method doDefineNewManagedBean.

@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);
            ReflectionHelper.set(beanManager, beanManager.getClass(), "beanSet", Collections.synchronizedSet(new HashSet<Bean<?>>()));
            beanManager.addBean(bean);
            beanManager.getBeanResolver().clear();
            bean.initializeAfterBeanDiscovery();
            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);
    }
}
Also used : EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) ClassTransformer(org.jboss.weld.resources.ClassTransformer) ContextNotActiveException(org.jboss.weld.context.ContextNotActiveException) HashSet(java.util.HashSet)

Aggregations

EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)6 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 MethodSignature (org.jboss.weld.annotated.enhanced.MethodSignature)2 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 WildcardType (java.lang.reflect.WildcardType)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Any (javax.enterprise.inject.Any)1 Instance (javax.enterprise.inject.Instance)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanAttributes (javax.enterprise.inject.spi.BeanAttributes)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 Provider (javax.inject.Provider)1 SlimAnnotatedTypeStore (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStore)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1