Search in sources :

Example 1 with ClassFileInfo

use of org.jboss.weld.resources.spi.ClassFileInfo 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 2 with ClassFileInfo

use of org.jboss.weld.resources.spi.ClassFileInfo 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)2 ClassFileInfo (org.jboss.weld.resources.spi.ClassFileInfo)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 ClassFileInfoException (org.jboss.weld.resources.spi.ClassFileInfoException)1