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()]);
}
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;
}
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());
}
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;
}
Aggregations