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.
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 ClassesModifier and TypeClassDescriptionstatic interfaceThe 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 classThe default implementation of Object factory which works well in stand-alone applications. -
Constructor Summary
ConstructorsConstructorDescriptionFactoryFinder(Class<T> factoryType, String path) Creates a new instance of the FactoryFinder using the given search path. -
Method Summary
Modifier and TypeMethodDescriptionstatic FactoryFinder.ObjectFactorynewInstance(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.
-
Constructor Details
-
FactoryFinder
Creates a new instance of the FactoryFinder using the given search path.- Parameters:
factoryType- The Class that defines what this finder is searching for.path- The path to use when searching for the factory definitions.
-
-
Method Details
-
getObjectFactory
- Returns:
- the currently configured ObjectFactory instance used to locate the Factory objects.
-
setObjectFactory
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.
-
registerProviderFactory
Allow registration of a Provider factory without wiring via META-INF classes- Parameters:
scheme- The URI scheme value that names the target Provider instance.factory- The factory to register in this finder.
-