Package org.xwiki.component.annotation
Class ComponentAnnotationLoader
- java.lang.Object
-
- org.xwiki.component.annotation.ComponentAnnotationLoader
-
public class ComponentAnnotationLoader extends Object
Dynamically loads all components defined using Annotations and declared in META-INF/components.txt files.- Since:
- 1.8.1
- Version:
- $Id: 8adb8e34e44456f37f11035184b78bc828a10743 $
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_LIST
Location in the classloader of the file defining the list of component implementation class to parser for annotations.static String
COMPONENT_OVERRIDE_LIST
Deprecated.starting with 3.3M1 use the notion of priorities instead (seeComponentDeclaration
).
-
Constructor Summary
Constructors Constructor Description ComponentAnnotationLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Set<Class<?>>
findComponentRoleClasses(Class<?> componentClass)
Deprecated.since 4.0M1 usefindComponentRoleTypes(Class)
insteadSet<Type>
findComponentRoleTypes(Class<?> componentClass)
Set<Type>
findComponentRoleTypes(Class<?> componentClass, Type[] parameters)
List<ComponentDescriptor<?>>
getComponentsDescriptors(Class<?> componentClass)
List<ComponentDeclaration>
getDeclaredComponents(InputStream componentListStream)
Get all components listed in the passed resource stream.List<ComponentDeclaration>
getDeclaredComponents(ClassLoader classLoader, String location)
Get all components listed in the passed resource file.List<ComponentDeclaration>
getDeclaredComponentsFromJAR(InputStream jarFile)
Get all components listed in a JAR file.protected org.slf4j.Logger
getLogger()
Useful for unit tests that need to capture logs; they can return a mock logger instead of the real logger and thus assert what's been logged.void
initialize(ComponentManager manager, ClassLoader classLoader)
Loads all components defined using annotations.void
initialize(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
void
register(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
void
register(ComponentManager manager, Collection<ComponentDescriptor<?>> componentDescriptors)
void
unregister(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
-
-
-
Field Detail
-
COMPONENT_LIST
public static final String COMPONENT_LIST
Location in the classloader of the file defining the list of component implementation class to parser for annotations.- See Also:
- Constant Field Values
-
COMPONENT_OVERRIDE_LIST
@Deprecated public static final String COMPONENT_OVERRIDE_LIST
Deprecated.starting with 3.3M1 use the notion of priorities instead (seeComponentDeclaration
).Location in the classloader of the file specifying which component implementation to use when several components with the same role/hint are found.- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
public void initialize(ComponentManager manager, ClassLoader classLoader)
Loads all components defined using annotations.- Parameters:
manager
- the component manager to use to dynamically register componentsclassLoader
- the classloader to use to look for the Component list declaration file (META-INF/components.txt
)
-
initialize
public void initialize(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
- Parameters:
manager
- the component manager to use to dynamically register componentsclassLoader
- the classloader to use to look for the Component list declaration file (META-INF/components.txt
)componentDeclarations
- the declarations of components to register- Since:
- 3.3M1
-
register
public void register(ComponentManager manager, Collection<ComponentDescriptor<?>> componentDescriptors)
- Parameters:
manager
- the component manager to use to dynamically register componentscomponentDescriptors
- the descriptors of components to register- Since:
- 11.1
-
register
public void register(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
- Parameters:
manager
- the component manager to use to dynamically register componentsclassLoader
- the classloader to use to look for the Component list declaration file (META-INF/components.txt
)componentDeclarations
- the declarations of components to register- Since:
- 4.0M1
-
unregister
public void unregister(ComponentManager manager, ClassLoader classLoader, List<ComponentDeclaration> componentDeclarations)
- Parameters:
manager
- the component manager to use to dynamically register componentsclassLoader
- the classloader to use to look for the Component list declaration file (META-INF/components.txt
)componentDeclarations
- the declarations of components to register- Since:
- 4.0M1
-
getComponentsDescriptors
public List<ComponentDescriptor<?>> getComponentsDescriptors(Class<?> componentClass)
-
findComponentRoleTypes
public Set<Type> findComponentRoleTypes(Class<?> componentClass, Type[] parameters)
-
findComponentRoleClasses
@Deprecated public Set<Class<?>> findComponentRoleClasses(Class<?> componentClass)
Deprecated.since 4.0M1 usefindComponentRoleTypes(Class)
insteadFinds the interfaces that implement component roles by looking recursively in all interfaces of the passed component implementation class. If the roles annotation value is specified then use the specified list instead of doing auto-discovery. Also note that we support component classes implementing JSR 330'sProvider
(and thus without a component role annotation).- Parameters:
componentClass
- the component implementation class for which to find the component roles it implements- Returns:
- the list of component role classes implemented
-
getDeclaredComponents
public List<ComponentDeclaration> getDeclaredComponents(ClassLoader classLoader, String location) throws IOException
Get all components listed in the passed resource file.- Parameters:
classLoader
- the classloader to use to find the resourceslocation
- the name of the resources to look for- Returns:
- the list of component implementation class names
- Throws:
IOException
- in case of an error loading the component list resource- Since:
- 12.1RC1
-
getDeclaredComponents
public List<ComponentDeclaration> getDeclaredComponents(InputStream componentListStream) throws IOException
Get all components listed in the passed resource stream. The format is:(priority level):(fully qualified component implementation name)
.- Parameters:
componentListStream
- the stream to parse- Returns:
- the list of component declaration (implementation class names and priorities)
- Throws:
IOException
- in case of an error loading the component list resource- Since:
- 3.3M1
-
getDeclaredComponentsFromJAR
public List<ComponentDeclaration> getDeclaredComponentsFromJAR(InputStream jarFile) throws IOException
Get all components listed in a JAR file.- Parameters:
jarFile
- the JAR file to parse- Returns:
- the list of component declaration (implementation class names and priorities)
- Throws:
IOException
- in case of an error loading the component list resource
-
getLogger
protected org.slf4j.Logger getLogger()
Useful for unit tests that need to capture logs; they can return a mock logger instead of the real logger and thus assert what's been logged.- Returns:
- the Logger instance to use to log
-
-