Package org.apache.qpid.jms.util
Class FactoryFinder<T>
- java.lang.Object
-
- org.apache.qpid.jms.util.FactoryFinder<T>
-
- Type Parameters:
T- The type of the object Factory to locate.
public class FactoryFinder<T> extends Object
A Factory finding helper class used to locate objects that serve as Factories for other Object types. The search an instantiate mechanism is configurable so that in a non-stand-alone environment such as OSGI the finder and be configured to work.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFactoryFinder.ObjectFactoryThe strategy that the FactoryFinder uses to find load and instantiate Objects can be changed out by calling thesetObjectFactory(org.apache.qpid.jms.util.FactoryFinder.ObjectFactory)method with a custom implementation of ObjectFactory.protected static classFactoryFinder.StandaloneObjectFactoryThe default implementation of Object factory which works well in stand-alone applications.
-
Constructor Summary
Constructors Constructor Description FactoryFinder(Class<T> factoryType, String path)Creates a new instance of the FactoryFinder using the given search path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FactoryFinder.ObjectFactorygetObjectFactory()TnewInstance(String key)Creates a new instance of the given key.voidregisterProviderFactory(String scheme, T factory)Allow registration of a Provider factory without wiring via META-INF classesstatic voidsetObjectFactory(FactoryFinder.ObjectFactory objectFactory)Sets the ObjectFactory instance to use when searching for the Factory class.
-
-
-
Method Detail
-
getObjectFactory
public static FactoryFinder.ObjectFactory getObjectFactory()
- Returns:
- the currently configured ObjectFactory instance used to locate the Factory objects.
-
setObjectFactory
public static void setObjectFactory(FactoryFinder.ObjectFactory objectFactory)
Sets the ObjectFactory instance to use when searching for the Factory class. This allows the default instance to be overridden in an environment where the basic version will not work.- Parameters:
objectFactory- the new object factory to use when searching for a Factory instance.
-
newInstance
public T newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, ClassCastException, ResourceNotFoundException, InvocationTargetException, NoSuchMethodException, SecurityException
Creates a new instance of the given key. The method first checks the cache of previously found factory instances for one that matches the key. If no cached version exists then the factory will be searched for using the configured ObjectFactory instance.- Parameters:
key- is the key to add to the path to find a text file containing the factory name- Returns:
- a newly created instance
- Throws:
IllegalAccessException- if an error occurs while accessing the search path.InstantiationException- if the factory object fails on create.ResourceNotFoundException- if the resource with the given key does not exist.IOException- if the search encounter an IO error.ClassNotFoundException- if the class that is to be loaded cannot be found.ClassCastException- if the found object is not assignable to the request factory type.InvocationTargetException- if the constructor of the found factory throws an exceptionNoSuchMethodException- if the factory class found does not have a suitable constructorSecurityException- if a security error occurs trying to create the factory instance.
-
-