Search in sources :

Example 1 with AnnotationType

use of org.glassfish.hk2.classmodel.reflect.AnnotationType in project Payara by payara.

the class WeldUtils method getCDIEnablingAnnotations.

/**
 * Get the names of any annotation types that are applied to beans, which should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return An array of annotation type names; The array could be empty if none are found.
 */
public static String[] getCDIEnablingAnnotations(DeploymentContext context) {
    List<String> result = new ArrayList<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return result.toArray(new String[result.size()]);
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 2 with AnnotationType

use of org.glassfish.hk2.classmodel.reflect.AnnotationType in project Payara by payara.

the class ConfigModularityUtils method getAnnotatedConfigBeans.

public List<Class> getAnnotatedConfigBeans(Class annotationType) {
    List<Class> prox = new ArrayList<Class>();
    List<ActiveDescriptor<?>> descriptor = serviceLocator.getDescriptors(BuilderHelper.createContractFilter(ConfigInjector.class.getName()));
    Class<?> clz = null;
    for (ActiveDescriptor desc : descriptor) {
        if (desc.getName() == null) {
            continue;
        }
        ConfigInjector injector = serviceLocator.getService(ConfigInjector.class, desc.getName());
        if (injector != null) {
            String clzName = injector.getClass().getName().substring(0, injector.getClass().getName().length() - 8);
            if (clzName == null) {
                continue;
            }
            try {
                clz = injector.getClass().getClassLoader().loadClass(clzName);
                if (clz == null) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.log(Level.FINE, "Cannot find the class mapping to:  " + clzName);
                    }
                    continue;
                }
            } catch (Throwable e) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "Cannot load the class", e);
                }
                continue;
            }
        }
        if (clz != null) {
            if (clz.isAnnotationPresent(annotationType)) {
                prox.add(clz);
            }
        }
    }
    return prox;
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ArrayList(java.util.ArrayList) ConfigInjector(org.jvnet.hk2.config.ConfigInjector)

Example 3 with AnnotationType

use of org.glassfish.hk2.classmodel.reflect.AnnotationType in project Payara by payara.

the class WeldUtils method hasCDIEnablingAnnotations.

/**
 * Determine whether there are any beans annotated with annotations that should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 * @param paths   The paths to check for annotated beans
 *
 * @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
 */
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
    List<String> result = new ArrayList<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at) && type.wasDefinedIn(paths)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return !(result.isEmpty());
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 4 with AnnotationType

use of org.glassfish.hk2.classmodel.reflect.AnnotationType in project Payara by payara.

the class WeldUtils method getCDIAnnotatedClassNames.

/**
 * Get the names of any classes that are annotated with bean-defining annotations, which should
 * enable CDI processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return A collection of class names; The collection could be empty if none are found.
 */
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
    Set<String> result = new HashSet<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at)) {
                        if (!result.contains(at.getName())) {
                            result.add(type.getName());
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)3 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)3 AnnotationType (org.glassfish.hk2.classmodel.reflect.AnnotationType)3 Type (org.glassfish.hk2.classmodel.reflect.Type)3 Types (org.glassfish.hk2.classmodel.reflect.Types)3 HashSet (java.util.HashSet)1 ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)1 ConfigInjector (org.jvnet.hk2.config.ConfigInjector)1