private Set<String> findPersistenceTypeNames(PersistenceUnitMetadata pu) { synchronized (CACHED_TYPENAMES) { Set<String> typeNames = CACHED_TYPENAMES.get(pu); if (typeNames != null) { return typeNames; } } Set<String> persistenceTypeNames = new HashSet<String>(); for (Map.Entry<URL, Index> entry : pu.getAnnotationIndex().entrySet()) { List<AnnotationInstance> instances = entry.getValue().getAnnotations(DotName.createSimple(Entity.class.getName())); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (target instanceof ClassInfo) { ClassInfo classInfo = (ClassInfo) target; persistenceTypeNames.add(classInfo.name().toString()); } } } synchronized (CACHED_TYPENAMES) { CACHED_TYPENAMES.put(pu, persistenceTypeNames); } return persistenceTypeNames; }
return new HashSet<Package>(); Collection<ClassInfo> allClasses = index.getKnownClasses(); for (ClassInfo classInfo : allClasses) { String className = classInfo.name().toString(); try { resultClasses.add(pu.cacheTempClassLoader().loadClass(className));
public Components(DeploymentUnit deploymentUnit, Map<ResourceRoot, Index> indexes) { componentDescriptionProcessors = ServiceLoader.load(ComponentDescriptionProcessor.class, WildFlySecurityManager.getClassLoaderPrivileged(BeanArchiveProcessor.class)); for (ComponentDescription component : deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION).getComponentDescriptions()) { ResourceRoot resourceRoot = null; DotName componentClassName = DotName.createSimple(component.getComponentClassName()); for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) { final Index index = entry.getValue(); if (index != null) { if (index.getClassByName(componentClassName) != null) { resourceRoot = entry.getKey(); break; } } } if (resourceRoot == null) { implicitComponentDescriptions.add(component); } if (resourceRoot == null || isClassesRoot(resourceRoot)) { // special handling resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); } componentDescriptions.put(resourceRoot, component); // Process component descriptions for (ComponentDescriptionProcessor processor : componentDescriptionProcessors) { processor.processComponentDescription(resourceRoot, component); } } }
@SuppressWarnings("unchecked") private Set<Class<? extends Fraction>> uninstalledFractionClasses(Set<Type> installedClasses) throws ModuleLoadException, IOException, ClassNotFoundException { Set<String> installedClassNames = installedClasses.stream().map(Type::getTypeName).collect(Collectors.toSet()); List<String> moduleNames = ApplicationEnvironment.get().bootstrapModules(); ClassLoader cl = Module.getBootModuleLoader().loadModule("swarm.container").getClassLoader(); Set<Class<? extends Fraction>> fractionClasses = new HashSet<>(); for (String moduleName : moduleNames) { Module module = Module.getBootModuleLoader().loadModule(moduleName); InputStream indexStream = module.getClassLoader().getResourceAsStream("META-INF/jandex.idx"); if (indexStream != null) { IndexReader reader = new IndexReader(indexStream); Index index = reader.read(); Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(Fraction.class.getName())); for (ClassInfo impl : impls) { if (!installedClassNames.contains(impl.name().toString())) { Class<? extends Fraction> fractionClass = (Class<? extends Fraction>) cl.loadClass(impl.name().toString()); fractionClasses.add(fractionClass); } } } } return fractionClasses; } }
private static void processHandlerChainAnnotations(final ResourceRoot resourceRoot, final Index index, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException { final List<AnnotationInstance> handlerChainAnnotations = index.getAnnotations(HANDLER_CHAIN_ANNOTATION); for (final AnnotationInstance handlerChainAnnotation : handlerChainAnnotations) { final AnnotationTarget annotationTarget = handlerChainAnnotation.target(); if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; if (isJaxwsEndpoint(classInfo, index)) { final String endpointClass = classInfo.name().toString(); processHandlerChainAnnotation(resourceRoot, handlerChainAnnotation, endpointClass, mapping); } } else { // We ignore fields & methods annotated with @HandlerChain. // These are used always in combination with @WebServiceRef // which are always referencing JAXWS client proxies only. } } }
for ( ClassInfo ci : index.getKnownClasses() ) { DotName name = ci.name(); if ( indexedClassInfoAnnotationsMap.containsKey( name ) ) { if ( ci.annotations() != null && !ci.annotations().isEmpty() ) { Map<DotName, List<AnnotationInstance>> tmp = new HashMap<DotName, List<AnnotationInstance>>( ci.annotations() ); DefaultConfigurationHelper.INSTANCE.applyDefaults( tmp, globalDefaults ); return Index.create( annotations, subclasses, implementors, classes );
clazzes = this.input.getIndex().getAllKnownImplementors(DotName.createSimple(Serializable.class.getName())); for ( ClassInfo cl : this.input.getIndex().getKnownClasses() ) { boolean foundDefaultConstructor = false; for ( MethodInfo methodInfo : cl.methods() ) { if ( !"<init>".equals(methodInfo.name()) ) { //$NON-NLS-1$ continue; if ( this.input.getConfig().isWhitelistedClass(ci.name().toString()) ) { continue;
DotName annotation = DotName.createSimple(annClass.getName()); List<AnnotationInstance> classesWithAnnotation = index.getAnnotations(annotation); Set<Class<?>> classesForAnnotation = new HashSet<Class<?>>(); for (AnnotationInstance annotationInstance : classesWithAnnotation) {
List<DotName> processedEntities, Map<DotName, List<ClassInfo>> classToDirectSubclassMap) { processedEntities.add( classInfo.name() ); rootClassWithAllSubclasses.add( classInfo ); List<ClassInfo> subClasses = bindingContext.getIndex().getKnownDirectSubclasses( classInfo.name() ); bindingContext.resolveAllTypes( classInfo.name().toString() );
/** * * @param i * @param methodReference * @param ci * @return whether any superclass implements the method */ public static boolean implementsMethodRecursive ( Index i, MethodReference methodReference, ClassInfo ci ) { if ( implementsMethod(methodReference, ci) ) { return true; } DotName superName = ci.superName(); if ( superName != null ) { ClassInfo superByName = i.getClassByName(superName); if ( superByName == null || "java.lang.Object".equals(superByName.name().toString()) ) { //$NON-NLS-1$ return false; } return implementsMethodRecursive(i, methodReference, superByName); } return false; }
private static List<Method> __invoke(Class<?> clazz, Index index, Comparator<Method> comparator) throws NoSuchMethodException { ArrayList methods = new ArrayList(); ClassInfo clazzInfo = index.getClassByName(DotName.createSimple(clazz.getName())); for (MethodInfo method : clazzInfo.methods()) { if (method.hasAnnotation(IndexFactory.SUBRESOURCE_META)) { methods.add(clazz.getMethod(method.name())); } } if (clazzInfo.superName() != null && clazz.getSuperclass() != java.lang.Object.class) { index = IndexFactory.createIndex(clazz.getSuperclass()); return __invoke(clazz.getSuperclass(), index, comparator); } Collections.sort(methods, comparator); return methods; }
private void getAllKnownSubClasses(DotName name, Set<ClassInfo> allKnown, Set<DotName> subClassesToProcess, Set<DotName> processedClasses) { final List<ClassInfo> list = getKnownDirectSubclasses(name); if (list != null) { for (final ClassInfo clazz : list) { final DotName className = clazz.name(); if (!processedClasses.contains(className)) { allKnown.add(clazz); subClassesToProcess.add(className); } } } }
private static AnnotationInstance getEndpointInterfaceHandlerChainAnnotationInstance(final ClassInfo classInfo, final Index index) { AnnotationValue av = classInfo.annotations().get(WEB_SERVICE_ANNOTATION).iterator().next().value("endpointInterface"); if (av != null) { String intf = av.asString(); if (intf != null && !intf.isEmpty()) { ClassInfo intfClassInfo = index.getClassByName(DotName.createSimple(intf)); if (intfClassInfo != null && ASHelper.isJaxwsEndpointInterface(intfClassInfo)) { return getHandlerChainAnnotationInstance(intfClassInfo); } } } return null; }
public static boolean isJaxwsService(final ClassInfo current, final Index index) { ClassInfo tmp = current; while (tmp != null) { final DotName superName = tmp.superName(); if (JAXWS_SERVICE_CLASS.equals(superName)) { return true; } tmp = index.getClassByName(superName); } return false; }
private Set<String> getImplicitBeanClasses(Index index, ResourceRoot resourceRoot) { Set<String> implicitBeanClasses = new HashSet<String>(); for (AnnotationType beanDefiningAnnotation : beanDefiningAnnotations) { List<AnnotationInstance> annotationInstances = index.getAnnotations(beanDefiningAnnotation.getName()); for (ClassInfo classInfo : Indices.getAnnotatedClasses(annotationInstances)) { implicitBeanClasses.add(Indices.CLASS_INFO_TO_FQCN.apply(classInfo)); } } // Make all explicit components into implicit beans so they will support injection for(ComponentDescription description : components.componentDescriptions.get(resourceRoot)) { if(!components.implicitComponentDescriptions.contains(description)) { implicitBeanClasses.add(description.getComponentClassName()); } } return implicitBeanClasses; }
public static AddressTemplate of(Class<?> entity) { Index index = IndexFactory.createIndex(entity); ClassInfo clazz = index.getClassByName(DotName.createSimple(entity.getCanonicalName())); AddressTemplate addr = null; for (AnnotationInstance annotation : clazz.classAnnotations()) { if (annotation.name().equals(IndexFactory.ADDRESS_META)) { Address meta = entity.getAnnotation(Address.class); addr = AddressTemplate.of(meta.value()); } else if (annotation.name().equals(IndexFactory.ADDRESSES_META)) { Addresses meta = entity.getAnnotation(Addresses.class); StringBuffer sb = new StringBuffer("\n"); for (String s : meta.value()) { sb.append(s).append("\n"); } throw new RuntimeException("Ambiguous resource reference on class "+entity +": "+ sb.toString()); } } if(null==addr) throw new RuntimeException("Missing resource reference on class "+entity); return addr; } }
private Set<String> getAllKnownClasses(Index index) { Set<String> allKnownClasses = new HashSet<String>(); // index may be null if a war has a beans.xml but no WEB-INF/classes if (index != null) { for (ClassInfo classInfo : index.getKnownClasses()) { allKnownClasses.add(Indices.CLASS_INFO_TO_FQCN.apply(classInfo)); } } return allKnownClasses; }
final List<AnnotationInstance> webServletAnnotations = index.getAnnotations(webServlet); if (webServletAnnotations != null && webServletAnnotations.size() > 0) { ServletsMetaData servlets = new ServletsMetaData(); final List<AnnotationInstance> webFilterAnnotations = index.getAnnotations(webFilter); if (webFilterAnnotations != null && webFilterAnnotations.size() > 0) { FiltersMetaData filters = new FiltersMetaData(); final List<AnnotationInstance> webListenerAnnotations = index.getAnnotations(webListener); if (webListenerAnnotations != null && webListenerAnnotations.size() > 0) { List<ListenerMetaData> listeners = new ArrayList<ListenerMetaData>(); final List<AnnotationInstance> runAsAnnotations = index.getAnnotations(runAs); if (runAsAnnotations != null && runAsAnnotations.size() > 0) { AnnotationsMetaData annotations = metaData.getAnnotations(); final List<AnnotationInstance> declareRolesAnnotations = index.getAnnotations(declareRoles); if (declareRolesAnnotations != null && declareRolesAnnotations.size() > 0) { SecurityRolesMetaData securityRoles = metaData.getSecurityRoles(); final List<AnnotationInstance> multipartConfigAnnotations = index.getAnnotations(multipartConfig); if (multipartConfigAnnotations != null && multipartConfigAnnotations.size() > 0) { AnnotationsMetaData annotations = metaData.getAnnotations(); final List<AnnotationInstance> servletSecurityAnnotations = index.getAnnotations(servletSecurity); if (servletSecurityAnnotations != null && servletSecurityAnnotations.size() > 0) { AnnotationsMetaData annotations = metaData.getAnnotations();
public Map<DotName, List<AnnotationInstance>> getIndexedAnnotations(DotName name) { Map<DotName, List<AnnotationInstance>> map = indexedClassInfoAnnotationsMap.get( name ); if ( map == null ) { ClassInfo ci = index.getClassByName( name ); if ( ci == null || ci.annotations() == null ) { map = Collections.emptyMap(); } else { map = new HashMap<DotName, List<AnnotationInstance>>( ci.annotations() ); //here we ignore global annotations for ( DotName globalAnnotationName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS ) { if ( map.containsKey( globalAnnotationName ) ) { map.put( globalAnnotationName, Collections.<AnnotationInstance>emptyList() ); } } } indexedClassInfoAnnotationsMap.put( name, map ); } return map; }
/** * @see {@link Index#getClassByName(org.jboss.jandex.DotName)} */ public ClassInfo getClassByName(final DotName className) { for (Index index : indexes) { final ClassInfo info = index.getClassByName(className); if (info != null) { return info; } } return null; }