Class ClassLoaders
- java.lang.Object
-
- org.apache.commons.discovery.resource.ClassLoaders
-
public class ClassLoaders extends java.lang.Object
There are many different contexts in which loaders can be used. This provides a holder for a set of class loaders, so that they don't have to be build back up everytime...
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.ClassLoader>
classLoaders
-
Constructor Summary
Constructors Constructor Description ClassLoaders()
Construct a new class loader set.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoader
get(int idx)
Returns the class loader positioned at the given index.static ClassLoaders
getAppLoaders(java.lang.Class<?> spi, java.lang.Class<?> factory, boolean prune)
Utility method.static ClassLoaders
getLibLoaders(java.lang.Class<?> spi, java.lang.Class<?> factory, boolean prune)
Utility method.boolean
isAncestor(java.lang.ClassLoader classLoader)
Check to see ifclassLoader
is an ancestor of any contained class loader.void
put(java.lang.ClassLoader classLoader)
Specify a new class loader to be used in searching.void
put(java.lang.ClassLoader classLoader, boolean prune)
Specify a new class loader to be used in searching.int
size()
Returns the size of class loaders set.
-
-
-
Field Detail
-
classLoaders
protected java.util.List<java.lang.ClassLoader> classLoaders
-
-
Constructor Detail
-
ClassLoaders
public ClassLoaders()
Construct a new class loader set.
-
-
Method Detail
-
size
public int size()
Returns the size of class loaders set.- Returns:
- The size of class loaders set
-
get
public java.lang.ClassLoader get(int idx)
Returns the class loader positioned at the given index.- Parameters:
idx
- The index the class loader has to be retrieved from- Returns:
- The class loader positioned at the given index
-
put
public void put(java.lang.ClassLoader classLoader)
Specify a new class loader to be used in searching. The order of loaders determines the order of the result. It is recommended to add the most specific loaders first;null
class loaders are discarded.- Parameters:
classLoader
- The class loader has to added in the set
-
put
public void put(java.lang.ClassLoader classLoader, boolean prune)
Specify a new class loader to be used in searching. The order of loaders determines the order of the result. It is recommended to add the most specific loaders first;null
class loaders are discarded.- Parameters:
classLoader
- The class loader has to added in the setprune
- if true, verify that the class loader is not an Ancestor (@see isAncestor) before adding it to our list.
-
isAncestor
public boolean isAncestor(java.lang.ClassLoader classLoader)
Check to see ifclassLoader
is an ancestor of any contained class loader. This can be used to eliminate redundant class loaders IF all class loaders defer to parent class loaders before resolving a class. It may be that this is not always true. Therefore, this check is not done internally to eliminate redundant class loaders, but left to the discretion of the user.- Parameters:
classLoader
- The class loader under test- Returns:
- true, if the class loader under test is an ancestor of any contained class loader, false otherwise
-
getLibLoaders
public static ClassLoaders getLibLoaders(java.lang.Class<?> spi, java.lang.Class<?> factory, boolean prune)
Utility method. Returns a preloaded ClassLoaders instance containing the following class loaders, in order:- spi.getClassLoader
- seeker.getClassLoader
- System Class Loader
- Parameters:
spi
- WHAT is being looked for (an implementation of this class, a default property file related to this class).factory
- WHO is performing the lookup.prune
- Determines if ancestors are allowed to be loaded or not.- Returns:
- The class loaders holder
-
getAppLoaders
public static ClassLoaders getAppLoaders(java.lang.Class<?> spi, java.lang.Class<?> factory, boolean prune)
Utility method. Returns a preloaded ClassLoaders instance containing the following class loaders, in order:- Thread Context Class Loader
- spi.getClassLoader
- seeker.getClassLoader
- System Class Loader
- Parameters:
spi
- WHAT is being looked for (an implementation of this class, a default property file related to this class).factory
- WHO is performing the lookup (factory).prune
- Determines if ancestors are allowed to be loaded or not.- Returns:
- The class loaders holder
-
-