Package org.apache.uima.util
Class SimpleResourceFactory
java.lang.Object
org.apache.uima.util.SimpleResourceFactory
- All Implemented Interfaces:
ResourceFactory
A simple implementation of a
ResourceFactory. This implementation
maintains a Map between the ResourceSpecifier sub-interface name (e.g.
AnalysisEngineDescription) and the class name of the resource to be constructed from
specifiers of that type.
UIMA developers who introduce new types of Resources or ResourceSpecifiers may
create an instance of this class and use the addMapping(Class,Class) method to register
a mapping between the ResourceSpecifier interface and the Class of the Resource that is to be
constructed from it. The SimpleResourceFactory should then be registered with the
framework by calling
UIMAFramework.getResourceFactory().registerFactory(Class,ResourceFactory);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapping(Class<? extends ResourceSpecifier> aSpecifierInterface, Class<? extends Resource> aResourceClass) Configures thisSimpleResourceFactoryby adding a new mapping between aResourceSpecifierclass and aResourceclass.voidaddMapping(String aSpecifierInterfaceName, String aResourceClassName) Configures thisSimpleResourceFactoryby adding a new mapping between aResourceSpecifierclass and aResourceclass.produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) Produces an appropriateResourceinstance from aResourceSpecifier.
-
Field Details
-
mClassMap
Map from ResourceSpecifier Class to List of Resource Classes. Resource initialization is attempted in reverse order through this List, so more recently registered classes are tried first.
-
-
Constructor Details
-
SimpleResourceFactory
public SimpleResourceFactory()
-
-
Method Details
-
produceResource
public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationExceptionProduces an appropriateResourceinstance from aResourceSpecifier.- Specified by:
produceResourcein interfaceResourceFactory- Parameters:
aResourceClass- the interface of the resource to be produced. This is intended to be a standard UIMA interface such asTextAnalysisEngineorASB.aSpecifier- an object that specifies how to acquire an instance of aResource.aAdditionalParams- a Map containing additional parameters to pass to theResource.initialize(ResourceSpecifier,Map)method. May benullif there are no parameters.- Returns:
- a
Resourceinstance. Returnsnullif this factory does not know how to create a Resource from theResourceSpecifierprovided. - Throws:
ResourceInitializationException- if a failure occurred during production of the resource- See Also:
-
addMapping
public void addMapping(Class<? extends ResourceSpecifier> aSpecifierInterface, Class<? extends Resource> aResourceClass) Configures thisSimpleResourceFactoryby adding a new mapping between aResourceSpecifierclass and aResourceclass.- Parameters:
aSpecifierInterface- the subinterface ofResourceSpecifier.aResourceClass- a subclass ofResourcethat is to be instantiated from resource specifiers of the given class.
-
addMapping
public void addMapping(String aSpecifierInterfaceName, String aResourceClassName) throws ClassNotFoundException Configures thisSimpleResourceFactoryby adding a new mapping between aResourceSpecifierclass and aResourceclass.- Parameters:
aSpecifierInterfaceName- name of the subinterface ofResourceSpecifier.aResourceClassName- the name of a subclass ofResourcethat is to be instantiated from resource specifiers of the given class.- Throws:
ClassNotFoundException- -
-