net.sf.mmm.util.reflect.base
Class ReflectionUtilImpl

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.reflect.base.ReflectionUtilImpl
All Implemented Interfaces:
GenericTypeFactory, ReflectionUtil

@Singleton
@Named
public class ReflectionUtilImpl
extends AbstractLoggableComponent
implements ReflectionUtil

This class is a collection of utility functions for dealing with reflection.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
getInstance()

Field Summary
private static CharFilter CHAR_FILTER
           
private static ReflectionUtil instance
           
private static String WEB_INF_CLASSES
          The prefix of resources in WAR-files.
 
Fields inherited from interface net.sf.mmm.util.reflect.api.ReflectionUtil
NO_ARGUMENTS, NO_PARAMETERS, NO_TYPES
 
Constructor Summary
ReflectionUtilImpl()
          The constructor.
 
Method Summary
 int compare(Class<?> class1, Class<?> class2)
          This method compares the given classes.
<T> GenericType<T>
createGenericType(Class<T> type)
          This method creates the GenericType representing the given type.
 GenericType<?> createGenericType(Type type)
          This method creates the GenericType representing the given type.
 GenericType<?> createGenericType(Type type, Class<?> definingType)
          This method creates the GenericType representing the given type in the context of the given definingType.
 GenericType<?> createGenericType(Type type, GenericType<?> definingType)
          This method creates the GenericType representing the given type in the context of the given definingType.
 Set<String> findClassNames(String packageName, boolean includeSubPackages)
          This method finds all classes that are located in the package identified by the given packageName.
 Set<String> findClassNames(String packageName, boolean includeSubPackages, Filter<String> filter)
          This method finds all classes that are located in the package identified by the given packageName.
 Set<String> findClassNames(String packageName, boolean includeSubPackages, Filter<String> filter, ClassLoader classLoader)
          This method finds all classes that are located in the package identified by the given packageName.
 void findClassNames(String packageName, boolean includeSubPackages, Set<String> classSet)
          This method finds all classes that are located in the package identified by the given packageName.
protected  void findClassNames(String packageName, boolean includeSubPackages, Set<String> classSet, Filter<String> filter, ClassLoader classLoader)
           
 Set<String> findResourceNames(String packageName, boolean includeSubPackages, Filter<String> filter)
          This method finds all resources that are located in the package identified by the given packageName.
 Set<String> findResourceNames(String packageName, boolean includeSubPackages, Filter<String> filter, ClassLoader classLoader)
          This method finds all resources that are located in the package identified by the given packageName.
 Set<DataResource> findResources(String absoluteClasspath)
          This method finds all resources that match to the given absoluteClasspath.
 Set<DataResource> findResources(String packageName, boolean includeSubPackages, Filter<String> filter)
          This method finds all resources that are located in the package identified by the given packageName.
 Set<DataResource> findResources(String packageName, boolean includeSubPackages, Filter<String> filter, ClassLoader classLoader)
          This method finds all resources that are located in the package identified by the given packageName.
 Class<?> getArrayClass(Class<?> componentType)
          This method creates the Class reflecting an array of the given componentType.
 Class<?>[] getClasses(Object[] objects)
          This method gets the classes of the given objects.
protected  ClassLoader getDefaultClassLoader()
          This method gets the default ClassLoader to use.
protected  ClassLoader getDefaultClassLoader(Class<?> fallbackClass)
          This method gets the default ClassLoader to use.
protected  Type getGenericDeclaration(Class<?> ancestor, Class<?> descendant)
          This method walks up the Class-hierarchy from descendant up to ancestor and returns the sub-class or sub-interface of ancestor on that hierarchy-path.
static ReflectionUtil getInstance()
          This method gets the singleton instance of this ReflectionUtil.
 Class<?> getNonPrimitiveType(Class<?> type)
          This method gets the according non-primitive type for the class given by type.
 Method getParentMethod(Class<?> inheritingClass, String methodName, Class<?>[] parameterTypes)
          This method gets the method identified by methodName and parameterTypes that is NOT declared but inherited by the given declaringClass.
 Method getParentMethod(Method method)
          This method gets the parent method of the given method.
<T> T
getStaticField(Class<?> type, String fieldName, Class<T> fieldType, boolean exactTypeMatch, boolean mustBeFinal, boolean inherit)
          This method gets the value of a static field .
<T> T
getStaticFieldOrNull(Class<?> type, String fieldName, Class<T> fieldType, boolean exactTypeMatch, boolean mustBeFinal, boolean inherit)
          
protected  Class<?> getSubClass(Class<?> ancestor, Class<?> descendant)
          This method walks up the Class-hierarchy from descendant up to ancestor and returns the sub-class or sub-interface of ancestor on that hierarchy-path.
 boolean isMarkerInterface(Class<?> interfaceClass)
          This method determines if the given interfaceClass is a marker-interface (e.g.
 Set<Class<?>> loadClasses(Collection<String> qualifiedClassNames)
          This method loads the classes given as Collection of fully qualified names by qualifiedClassNames and returns them as Set.
 Set<Class<?>> loadClasses(Collection<String> classNames, ClassResolver classResolver, Filter<? super Class<?>> filter)
          This method loads the classes given as Collection of names by classNames using the given classResolver.
 Set<Class<?>> loadClasses(Collection<String> qualifiedClassNames, Filter<? super Class<?>> filter)
          This method loads the classes given as Collection of fully qualified names by qualifiedClassNames.
 String toString(Type type)
          This method gets the string representation of a Type.
 void toString(Type type, Appendable appendable, Visitor<Class<?>> classFormatter)
          This method gets the string representation of a Type.
private  Type toType(CharSequenceScanner parser, ClassResolver resolver, Type owner)
          This method parses the given type as generic Type.
 Type toType(String type)
          This method is the analogy to Class.forName(String) for creating a Type instance from String.
 Type toType(String type, ClassResolver resolver)
          This method is the analogy to Class.forName(String) for creating a Type instance from String.
 void visitResourceNames(String packageName, boolean includeSubPackages, ClassLoader classLoader, ResourceVisitor visitor)
          This method does the actual magic to locate resources on the classpath.
private static void visitResources(File packageDirectory, StringBuilder qualifiedNameBuilder, int qualifiedNamePrefixLength, ResourceVisitor visitor)
          This method scans the given packageDirectory recursively for resources.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_INF_CLASSES

private static final String WEB_INF_CLASSES
The prefix of resources in WAR-files.

See Also:
Constant Field Values

instance

private static ReflectionUtil instance
See Also:
getInstance()

CHAR_FILTER

private static final CharFilter CHAR_FILTER
See Also:
toType(CharSequenceScanner, ClassResolver, Type)
Constructor Detail

ReflectionUtilImpl

public ReflectionUtilImpl()
The constructor.

Method Detail

getInstance

public static ReflectionUtil getInstance()
This method gets the singleton instance of this ReflectionUtil.
This design is the best compromise between easy access (via this indirection you have direct, static access to all offered functionality) and IoC-style design which allows extension and customization.
For IoC usage, simply ignore all static getInstance() methods and construct new instances via the container-framework of your choice (like plexus, pico, springframework, etc.). To wire up the dependent components everything is properly annotated using common-annotations (JSR-250). If your container does NOT support this, you should consider using a better one.

Returns:
the singleton instance.

getClasses

public Class<?>[] getClasses(Object[] objects)
This method gets the classes of the given objects.

Specified by:
getClasses in interface ReflectionUtil
Parameters:
objects - is an array containing the objects for that the classes are requested.
Returns:
an array of the same length as the given array. At each position the returned array contains the class of the object from the given array at the same position or null, if that object is null.

createGenericType

public <T> GenericType<T> createGenericType(Class<T> type)
This method creates the GenericType representing the given type.
The type, lower bound and upper bound of the returned GenericType will all be identical to the given type.
ATTENTION:
If you know the Type where the given type was defined you should use GenericTypeFactory.createGenericType(Type, GenericType) instead to get a more precise result.

Specified by:
createGenericType in interface GenericTypeFactory
Type Parameters:
T - is the generic type of the Class to convert.
Parameters:
type - is the Type to represent.
Returns:
the according GenericType.

createGenericType

public GenericType<?> createGenericType(Type type)
This method creates the GenericType representing the given type.
If the given type is a Class, the methods behaves like GenericTypeFactory.createGenericType(Class).
ATTENTION:
If you know the Type where the given type was defined (e.g. the Class where you retrieved the given type from as parameter, return-type or field-type) you should use GenericTypeFactory.createGenericType(Type, GenericType) instead to get a more precise result.

Specified by:
createGenericType in interface GenericTypeFactory
Parameters:
type - is the Type to represent.
Returns:
the according GenericType.

createGenericType

public GenericType<?> createGenericType(Type type,
                                        GenericType<?> definingType)
This method creates the GenericType representing the given type in the context of the given definingType.
Here is some typical example of how to use this:
 ReflectionUtil util = getInstance();
 Class<?> myClass = getSomeClass();
 GenericType definingType = util.createGenericType(myClass);
 Method myMethod = findSomeMethod(myClass);
 Type returnType = myMethod.getGenericReturnType();
 GenericType type = util.createGenericType(returnType, definingType);
 Class<?> returnClass = type.GenericType.getRetrievalClass();
 
Now if you ask your self why all this instead of just using myMethod.getReturnType() ? Read the javadoc of GenericType to get the answer.
NOTE:
Please look at mmm-util-pojo which allows to use this features at a higher level and therefore much easier.

Specified by:
createGenericType in interface GenericTypeFactory
Parameters:
type - is the Type to represent.
definingType - is the GenericType where the given type is defined in. It is needed to resolve TypeVariables.
Returns:
the according GenericType.
See Also:
GenericTypeFactory.createGenericType(Type, Class)

createGenericType

public GenericType<?> createGenericType(Type type,
                                        Class<?> definingType)
This method creates the GenericType representing the given type in the context of the given definingType.
It is a convenience method for createGenericType(type, createGenericType(definingType))

Specified by:
createGenericType in interface GenericTypeFactory
Parameters:
type - is the Type to represent.
definingType - is the Class where the given type is defined in. It is needed to resolve TypeVariables.
Returns:
the according GenericType.

getSubClass

protected Class<?> getSubClass(Class<?> ancestor,
                               Class<?> descendant)
This method walks up the Class-hierarchy from descendant up to ancestor and returns the sub-class or sub-interface of ancestor on that hierarchy-path.
Please note that if ancestor is an interface, the hierarchy may NOT be unique. In such case it will be unspecified which of the possible paths is used.

Parameters:
ancestor - is the super-class or super-interface of descendant.
descendant - is the sub-class or sub-interface of ancestor.
Returns:
the sub-class or sub-interface on the hierarchy-path from descendant up to ancestor.

getGenericDeclaration

protected Type getGenericDeclaration(Class<?> ancestor,
                                     Class<?> descendant)
This method walks up the Class-hierarchy from descendant up to ancestor and returns the sub-class or sub-interface of ancestor on that hierarchy-path.
Please note that if ancestor is an interface, the hierarchy may NOT be unique. In such case it will be unspecified which of the possible paths is used.

Parameters:
ancestor - is the super-class or super-interface of descendant.
descendant - is the sub-class or sub-interface of ancestor.
Returns:
the sub-class or sub-interface on the hierarchy-path from descendant up to ancestor.

getArrayClass

public Class<?> getArrayClass(Class<?> componentType)
This method creates the Class reflecting an array of the given componentType.

Specified by:
getArrayClass in interface ReflectionUtil
Parameters:
componentType - is the component type .
Returns:
the according array-class.

toType

public Type toType(String type)
This method is the analogy to Class.forName(String) for creating a Type instance from String.

Specified by:
toType in interface ReflectionUtil
Parameters:
type - is the string representation of the requested type.
Returns:
the requested type.
See Also:
ReflectionUtil.toType(String, ClassResolver)

toType

public Type toType(String type,
                   ClassResolver resolver)
This method is the analogy to Class.forName(String) for creating a Type instance from String.

Specified by:
toType in interface ReflectionUtil
Parameters:
type - is the string representation of the requested type.
resolver - is used to resolve classes.
Returns:
the requested type.

toType

private Type toType(CharSequenceScanner parser,
                    ClassResolver resolver,
                    Type owner)
This method parses the given type as generic Type.
This would be easier when using StringParser but we want to avoid the dependency on util-misc.

Parameters:
parser - is the string-parser on the type string to parse.
resolver - is used to resolve classes.
owner - is the owner-type or null.
Returns:
the parsed type.

toString

public String toString(Type type)
This method gets the string representation of a Type. Instead of Type.toString() it returns Class.getName() if the type is a Class.

Specified by:
toString in interface ReflectionUtil
Parameters:
type - is the type to get as string.
Returns:
the string representation of the given type.

toString

public void toString(Type type,
                     Appendable appendable,
                     Visitor<Class<?>> classFormatter)
This method gets the string representation of a Type. Instead of Type.toString() it returns Class.getName() if the type is a Class.

Specified by:
toString in interface ReflectionUtil
Parameters:
type - is the type to get as string.
appendable - is where to append the string representation to.
classFormatter - is a Visitor that gets called for each Class and has to append as string-representation of the visited Class to the appendable.

compare

public int compare(Class<?> class1,
                   Class<?> class2)
This method compares the given classes.

Specified by:
compare in interface ReflectionUtil
Parameters:
class1 - is the first class.
class2 - is the second class.
Returns:
  • 0 if both classes are equal to each other.
  • 1 if class1 inherits from class2.
  • -1 if class2 inherits from class1.
  • Integer.MIN_VALUE otherwise.

getNonPrimitiveType

public Class<?> getNonPrimitiveType(Class<?> type)
This method gets the according non-primitive type for the class given by type.
E.g. getNonPrimitiveType(int.class) will return Integer.class.

Specified by:
getNonPrimitiveType in interface ReflectionUtil
Parameters:
type - is the (potentially) primitive type.
Returns:
the according object-type for the given type. This will be the given type itself if it is NOT primitive.
See Also:
Class.isPrimitive()

isMarkerInterface

public boolean isMarkerInterface(Class<?> interfaceClass)
This method determines if the given interfaceClass is a marker-interface (e.g. Serializable or Cloneable). A marker-interface is also called a tagging-interface.

Specified by:
isMarkerInterface in interface ReflectionUtil
Parameters:
interfaceClass - is the Class reflecting the interface to check.
Returns:
true if the given interfaceClass is a marker-interface, false otherwise (if regular interface or no interface at all).

getStaticField

public <T> T getStaticField(Class<?> type,
                            String fieldName,
                            Class<T> fieldType,
                            boolean exactTypeMatch,
                            boolean mustBeFinal,
                            boolean inherit)
                 throws NoSuchFieldException,
                        IllegalAccessException,
                        IllegalArgumentException
This method gets the value of a static field .

Specified by:
getStaticField in interface ReflectionUtil
Type Parameters:
T - the templated type the requested field is assigned to.
Parameters:
type - is the class or interface containing the requested field.
fieldName - is the name of the requested field.
fieldType - is the type the requested field is assigned to. Therefore the field declaration (!) must be assignable to this type.
exactTypeMatch - - if true, the fieldType must match exactly the type of the static field, else if false the type of the field may be a sub-type of fieldType or one of the types may be primitive while the other is the according object-type.
mustBeFinal - - if true, an IllegalArgumentException is thrown if the specified static field exists but is NOT final, false otherwise.
inherit - if true the field may be inherited from a super-class or super-interface of type, else if false the field is only accepted if it is declared in type.
Returns:
the value of the field with the given type.
Throws:
NoSuchFieldException - if the given type has no field with the given fieldName.
IllegalAccessException - if you do not have permission to read the field (e.g. field is private).
IllegalArgumentException - if the field is NOT static (or final) or has the wrong type.

getStaticFieldOrNull

public <T> T getStaticFieldOrNull(Class<?> type,
                                  String fieldName,
                                  Class<T> fieldType,
                                  boolean exactTypeMatch,
                                  boolean mustBeFinal,
                                  boolean inherit)
                       throws IllegalArgumentException

Specified by:
getStaticFieldOrNull in interface ReflectionUtil
Type Parameters:
T - the templated type the requested field is assigned to.
Parameters:
type - is the class or interface containing the requested field.
fieldName - is the name of the requested field.
fieldType - is the type the requested field is assigned to. Therefore the field declaration (!) must be assignable to this type.
exactTypeMatch - - if true, the fieldType must match exactly the type of the static field, else if false the type of the field may be a sub-type of fieldType or one of the types may be primitive while the other is the according object-type.
mustBeFinal - - if true, an IllegalArgumentException is thrown if the specified static field exists but is NOT final, false otherwise.
inherit - if true the field may be inherited from a super-class or super-interface of type, else if false the field is only accepted if it is declared in type.
Returns:
the value of the field with the given type or null if the field does NOT exist or is NOT accessible.
Throws:
IllegalArgumentException - if the field is NOT static (or final) or has the wrong type.

getParentMethod

public Method getParentMethod(Method method)
                       throws SecurityException
This method gets the parent method of the given method. The parent method is the method overridden (is the sense of Override) by the given method or directly inherited from an interface.

Specified by:
getParentMethod in interface ReflectionUtil
Parameters:
method - is the method.
Returns:
the parent method or null if no such method exists.
Throws:
SecurityException - if access has been denied by the SecurityManager.

getParentMethod

public Method getParentMethod(Class<?> inheritingClass,
                              String methodName,
                              Class<?>[] parameterTypes)
                       throws SecurityException
This method gets the method identified by methodName and parameterTypes that is NOT declared but inherited by the given declaringClass.

Specified by:
getParentMethod in interface ReflectionUtil
Parameters:
inheritingClass - is the class inheriting the requested method.
methodName - is the name of the requested method.
parameterTypes - is the signature of the requested method.
Returns:
the inherited method or null if no such method exists.
Throws:
SecurityException - if access has been denied by the SecurityManager.
See Also:
ReflectionUtil.getParentMethod(Class, String, Class[])

visitResources

private static void visitResources(File packageDirectory,
                                   StringBuilder qualifiedNameBuilder,
                                   int qualifiedNamePrefixLength,
                                   ResourceVisitor visitor)
This method scans the given packageDirectory recursively for resources.

Parameters:
packageDirectory - is the directory representing the Package.
qualifiedNameBuilder - is a StringBuilder containing the qualified prefix (the Package with a trailing dot).
qualifiedNamePrefixLength - the length of the prefix used to rest the string-builder after reuse.
visitor - is the ResourceVisitor.

findClassNames

public Set<String> findClassNames(String packageName,
                                  boolean includeSubPackages)
This method finds all classes that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findClassNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan.
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
Returns:
a Set with the fully qualified names of all requested classes.

findClassNames

public void findClassNames(String packageName,
                           boolean includeSubPackages,
                           Set<String> classSet)
This method finds all classes that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findClassNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan.
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
classSet - is where to add the classes.

findClassNames

public Set<String> findClassNames(String packageName,
                                  boolean includeSubPackages,
                                  Filter<String> filter)
This method finds all classes that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findClassNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan.
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the Class-names to be added to the resulting Set. The Filter will receive fully qualified class-names as argument (e.g. "net.sf.mmm.reflect.api.ReflectionUtil").
Returns:
a Set with the fully qualified names of all requested classes.

findClassNames

public Set<String> findClassNames(String packageName,
                                  boolean includeSubPackages,
                                  Filter<String> filter,
                                  ClassLoader classLoader)
This method finds all classes that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findClassNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan.
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the Class-names to be added to the resulting Set. The Filter will receive fully qualified class-names as argument (e.g. "net.sf.mmm.reflect.api.ReflectionUtil").
classLoader - is the explicit ClassLoader to use.
Returns:
a Set with the fully qualified names of all requested classes.

findClassNames

protected void findClassNames(String packageName,
                              boolean includeSubPackages,
                              Set<String> classSet,
                              Filter<String> filter,
                              ClassLoader classLoader)
                       throws RuntimeIoException
Parameters:
packageName - is the name of the Package to scan.
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
classSet - is where to add the classes.
filter - is used to filter the Class-names to be added to the resulting Set. The Filter will receive fully qualified class-names as argument (e.g. "net.sf.mmm.reflect.api.ReflectionUtil").
classLoader - is the explicit ClassLoader to use.
Throws:
RuntimeIoException - if the operation failed with an I/O error.
See Also:
findClassNames(String, boolean, Filter, ClassLoader)

findResourceNames

public Set<String> findResourceNames(String packageName,
                                     boolean includeSubPackages,
                                     Filter<String> filter)
This method finds all resources that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findResourceNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan. Both "." and "/" are accepted as separator (e.g. "net.sf.mmm.util.reflect).
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the resources. The Filter will receive fully qualified classpath entries as argument (e.g. "net/sf/mmm/util/reflect/beans-util-reflect.xml"). Typically you will exclude resources that end with ".class" or only accept resources that end with ".xml".
Returns:
a Set with the fully qualified names of all requested resources (e.g. "net/sf/mmm/util/reflect/beans-util-reflect.xml").

findResourceNames

public Set<String> findResourceNames(String packageName,
                                     boolean includeSubPackages,
                                     Filter<String> filter,
                                     ClassLoader classLoader)
This method finds all resources that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findResourceNames in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan. Both "." and "/" are accepted as separator (e.g. "net.sf.mmm.util.reflect).
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the resources. The Filter will receive fully qualified classpath entries as argument (e.g. "net/sf/mmm/util/reflect/beans-util-reflect.xml"). Typically you will exclude resources that end with ".class" or only accept resources that end with ".xml".
classLoader - is the explicit ClassLoader to use.
Returns:
a Set with the fully qualified names of all requested resources (e.g. "net/sf/mmm/util/reflect/beans-util-reflect.xml").

findResources

public Set<DataResource> findResources(String packageName,
                                       boolean includeSubPackages,
                                       Filter<String> filter)
This method finds all resources that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findResources in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan. Both "." and "/" are accepted as separator (e.g. "net.sf.mmm.util.reflect).
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the resources. Typically you will exclude resources that end with ".class" or only accept resources that end with ".xml".
Returns:
a Set with all requested resources.

findResources

public Set<DataResource> findResources(String absoluteClasspath)
                                throws RuntimeIoException
This method finds all resources that match to the given absoluteClasspath. Unlike ClasspathResource.ClasspathResource(String) this method will return all resources that with the given classpath (e.g. out of multiple JAR-files).

Specified by:
findResources in interface ReflectionUtil
Parameters:
absoluteClasspath - is the absolute path to the resource. E.g. "net/sf/mmm/util/resource/ClasspathResource.txt".
Returns:
a Set with all requested resources.
Throws:
RuntimeIoException - if the operation failed with an I/O error.

findResources

public Set<DataResource> findResources(String packageName,
                                       boolean includeSubPackages,
                                       Filter<String> filter,
                                       ClassLoader classLoader)
This method finds all resources that are located in the package identified by the given packageName.
ATTENTION:
This is a relative expensive operation. Depending on your classpath multiple directories, JAR-, and WAR-files may need to be scanned.

Specified by:
findResources in interface ReflectionUtil
Parameters:
packageName - is the name of the Package to scan. Both "." and "/" are accepted as separator (e.g. "net.sf.mmm.util.reflect).
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
filter - is used to filter the resources. Typically you will exclude resources that end with ".class" or only accept resources that end with ".xml".
classLoader - is the explicit ClassLoader to use.
Returns:
a Set with all requested resources.

visitResourceNames

public void visitResourceNames(String packageName,
                               boolean includeSubPackages,
                               ClassLoader classLoader,
                               ResourceVisitor visitor)
                        throws RuntimeIoException
This method does the actual magic to locate resources on the classpath.

Parameters:
packageName - is the name of the Package to scan. Both "." and "/" are accepted as separator (e.g. "net.sf.mmm.util.reflect).
includeSubPackages - - if true all sub-packages of the specified Package will be included in the search.
classLoader - is the explicit ClassLoader to use.
visitor - is the ResourceVisitor.
Throws:
RuntimeIoException - if the operation failed with an I/O error.

loadClasses

public Set<Class<?>> loadClasses(Collection<String> qualifiedClassNames)
This method loads the classes given as Collection of fully qualified names by qualifiedClassNames and returns them as Set.

Specified by:
loadClasses in interface ReflectionUtil
Parameters:
qualifiedClassNames - is a collection containing the qualified names of the classes to load.
Returns:
a Set with all loaded classes.

loadClasses

public Set<Class<?>> loadClasses(Collection<String> qualifiedClassNames,
                                 Filter<? super Class<?>> filter)
This method loads the classes given as Collection of fully qualified names by qualifiedClassNames. It returns a Set containing only those loaded classes that are accepted by the given filter.

Specified by:
loadClasses in interface ReflectionUtil
Parameters:
qualifiedClassNames - is a collection containing the qualified names of the classes to load.
filter - is used to filter the loaded classes.
Returns:
a Set with all loaded classes that are accepted by the given filter.

loadClasses

public Set<Class<?>> loadClasses(Collection<String> classNames,
                                 ClassResolver classResolver,
                                 Filter<? super Class<?>> filter)
This method loads the classes given as Collection of names by classNames using the given classResolver. It returns a Set containing only those loaded classes that are accepted by the given filter.

Specified by:
loadClasses in interface ReflectionUtil
Parameters:
classNames - is a collection containing the names of the classes to load. The class names should typically be the qualified names of the classes to load. But this may differ depending on the classResolver.
classResolver - is used to load/resolve the classes by their names.
filter - is used to filter the loaded classes.
Returns:
a Set with all loaded classes that are accepted by the given filter.

getDefaultClassLoader

protected ClassLoader getDefaultClassLoader()
This method gets the default ClassLoader to use. This should be the ContextClassLoader but falls back to alternatives if no such ClassLoader is available.

Returns:
the default ClassLoader to use.

getDefaultClassLoader

protected ClassLoader getDefaultClassLoader(Class<?> fallbackClass)
This method gets the default ClassLoader to use. This should be the ContextClassLoader but falls back to alternatives if no such ClassLoader is available.

Parameters:
fallbackClass - is used to retrieve a ClassLoader as fallback if the ContextClassLoader is not available.
Returns:
the default ClassLoader to use.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.