Search in sources :

Example 1 with ContainerLifecycleEventObserverMethod

use of org.jboss.weld.event.ContainerLifecycleEventObserverMethod in project core by weld.

the class JsonObjects method isUnrestrictedProcessAnnotatedTypeObserver.

private static boolean isUnrestrictedProcessAnnotatedTypeObserver(ObserverMethod<?> observerMethod) {
    if (observerMethod instanceof ContainerLifecycleEventObserverMethod) {
        ContainerLifecycleEventObserverMethod<?> containerLifecycleObserverMethod = (ContainerLifecycleEventObserverMethod<?>) observerMethod;
        Class<?> rawObserverType = Reflections.getRawType(containerLifecycleObserverMethod.getObservedType());
        if ((rawObserverType.equals(ProcessAnnotatedType.class) || rawObserverType.equals(ProcessSyntheticAnnotatedType.class)) && containerLifecycleObserverMethod.getRequiredAnnotations().isEmpty()) {
            Type eventType = containerLifecycleObserverMethod.getObservedType();
            Type[] typeArguments;
            if (eventType instanceof ParameterizedType) {
                typeArguments = ((ParameterizedType) eventType).getActualTypeArguments();
            } else {
                typeArguments = Arrays2.EMPTY_TYPE_ARRAY;
            }
            if (typeArguments.length == 0 || Reflections.isUnboundedWildcard(typeArguments[0]) || Reflections.isUnboundedTypeVariable(typeArguments[0])) {
                return true;
            }
        }
    }
    return false;
}
Also used : ContainerLifecycleEventObserverMethod(org.jboss.weld.event.ContainerLifecycleEventObserverMethod) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) EventType(org.jboss.weld.probe.BootstrapStats.EventType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) Type(java.lang.reflect.Type) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)

Example 2 with ContainerLifecycleEventObserverMethod

use of org.jboss.weld.event.ContainerLifecycleEventObserverMethod in project core by weld.

the class FastProcessAnnotatedTypeResolver method resolveProcessAnnotatedTypeObservers.

/**
 * Resolves a set of {@code ProcessAnnotatedType} observer methods for the specified class. If no observer methods are resolved, an
 * empty set is returned.
 *
 * @param className the specified class name
 * @return the set of resolved ProcessAnnotatedType observer methods
 */
public Set<ContainerLifecycleEventObserverMethod<?>> resolveProcessAnnotatedTypeObservers(ClassFileServices classFileServices, String className) {
    Set<ContainerLifecycleEventObserverMethod<?>> result = new HashSet<ContainerLifecycleEventObserverMethod<?>>();
    result.addAll(catchAllObservers);
    ClassFileInfo classInfo = classFileServices.getClassFileInfo(className);
    for (Map.Entry<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>> entry : observers.entrySet()) {
        ContainerLifecycleEventObserverMethod<?> observer = entry.getKey();
        if (containsRequiredAnnotation(classInfo, observer) && entry.getValue().test(classInfo)) {
            result.add(observer);
        }
    }
    return result;
}
Also used : ContainerLifecycleEventObserverMethod(org.jboss.weld.event.ContainerLifecycleEventObserverMethod) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) ClassFileInfo(org.jboss.weld.resources.spi.ClassFileInfo) Predicate(java.util.function.Predicate)

Example 3 with ContainerLifecycleEventObserverMethod

use of org.jboss.weld.event.ContainerLifecycleEventObserverMethod in project core by weld.

the class FastAnnotatedTypeLoader method loadAnnotatedType.

@Override
public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, String bdaId) {
    try {
        final ClassFileInfo classFileInfo = classFileServices.getClassFileInfo(className);
        // firstly, check if this class is an annotation
        if ((classFileInfo.getModifiers() & BytecodeUtils.ANNOTATION) != 0) {
            // This is an annotation - an annotation may not end up as a managed bean nor be observer by PAT observer. Skip it.
            return null;
        }
        if (classFileInfo.isVetoed()) {
            return null;
        }
        // secondly, let's resolve PAT observers for this class
        Set<ContainerLifecycleEventObserverMethod<?>> observerMethods = Collections.emptySet();
        if (containerLifecycleEvents.isProcessAnnotatedTypeObserved()) {
            observerMethods = resolver.resolveProcessAnnotatedTypeObservers(classFileServices, className);
            if (!observerMethods.isEmpty()) {
                // there are PAT observers for this class, register the class now
                return createContext(className, classFileInfo, observerMethods, bdaId);
            }
        }
        if (Beans.isDecoratorDeclaringInAppropriateConstructor(classFileInfo)) {
            BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName());
        }
        // lastly, check if this class fulfills CDI managed bean requirements - if it does, add the class
        if (Beans.isTypeManagedBeanOrDecoratorOrInterceptor(classFileInfo, checkTypeModifiers)) {
            return createContext(className, classFileInfo, observerMethods, bdaId);
        }
        return null;
    } catch (ClassFileInfoException e) {
        BootstrapLogger.LOG.exceptionLoadingAnnotatedType(e.getMessage());
        return fallback.loadAnnotatedType(className, bdaId);
    }
}
Also used : ContainerLifecycleEventObserverMethod(org.jboss.weld.event.ContainerLifecycleEventObserverMethod) ClassFileInfoException(org.jboss.weld.resources.spi.ClassFileInfoException) ClassFileInfo(org.jboss.weld.resources.spi.ClassFileInfo)

Aggregations

ContainerLifecycleEventObserverMethod (org.jboss.weld.event.ContainerLifecycleEventObserverMethod)3 ClassFileInfo (org.jboss.weld.resources.spi.ClassFileInfo)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1 ProcessSyntheticAnnotatedType (javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)1 EventType (org.jboss.weld.probe.BootstrapStats.EventType)1 ClassFileInfoException (org.jboss.weld.resources.spi.ClassFileInfoException)1