private Collection < ComponentDescriptor < ? > > getComponentsDescriptors ( ClassLoader classLoader , List < ComponentDeclaration > componentDeclarations ) { // For each component class name found, load its class and use introspection to find the necessary // annotations required to create a Component Descriptor. Map < RoleHint < ? > , ComponentDescriptor < ? > > descriptorMap = new HashMap <> ( ) ; Map < RoleHint < ? > , Integer > priorityMap = new HashMap <> ( ) ; for ( ComponentDeclaration componentDeclaration : componentDeclarations ) { Class < ? > componentClass ; try { componentClass = classLoader . loadClass ( componentDeclaration . getImplementationClassName ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( String . format ( "Failed to load component class [%s] for annotation parsing" , componentDeclaration . getImplementationClassName ( ) ) , e ) ; } // Look for ComponentRole annotations and register one component per ComponentRole found for ( Type componentRoleType : findComponentRoleTypes ( componentClass ) ) { for ( ComponentDescriptor < ? > componentDescriptor : this . factory . createComponentDescriptors ( componentClass , componentRoleType ) ) { // If there's already a existing role/hint in the list of descriptors then decide which one // to keep by looking at their priorities. Highest priority wins (i.e. lowest integer value). RoleHint < ? > roleHint = new RoleHint ( componentDescriptor . getRoleType ( ) , componentDescriptor . getRoleHint ( ) ) ; addComponent ( descriptorMap , priorityMap , roleHint , componentDescriptor , componentDeclaration , true ) ; } } } return descriptorMap . values ( ) ; }
Find all component descriptors out of component declarations .