org.apache.uima.resource.impl
Class ResourceManager_impl

java.lang.Object
  extended by org.apache.uima.resource.impl.ResourceManager_impl
All Implemented Interfaces:
ResourceManager
Direct Known Subclasses:
ResourceManagerPearWrapper_impl

public class ResourceManager_impl
extends java.lang.Object
implements ResourceManager

Reference implementation of ResourceManager.


Field Summary
protected static java.lang.String LOG_RESOURCE_BUNDLE
          resource bundle for log messages
protected  CasManager mCasManager
          CasManager - manages creation and pooling of CASes.
protected  java.util.Map<java.lang.String,java.lang.Class<?>> mInternalParameterizedResourceImplClassMap
          Internal map from resource names (declared in resource declaration XML) to Class objects.
protected  java.util.Map<java.lang.String,org.apache.uima.resource.impl.ResourceManager_impl.ResourceRegistration> mInternalResourceRegistrationMap
          Internal map from resource names (declared in resource declaration XML) to ResourceRegistration objects.
protected  java.util.Map<java.lang.String,java.lang.Class<?>> mParameterizedResourceImplClassMap
          Map from String keys to Class objects.
protected  java.util.Map<java.util.List<java.lang.Object>,java.lang.Object> mParameterizedResourceInstanceMap
          Map from ArrayList(0:String,1:DataResource) keys to Resource objects.
protected  java.util.Map<java.lang.String,java.lang.Object> mResourceMap
          Map from qualified key names (declared in resource dependency XML) to Resource objects.
 
Constructor Summary
ResourceManager_impl()
          Creates a new ResourceManager_impl.
ResourceManager_impl(java.lang.ClassLoader aClassLoader)
          Creates a new ResourceManager_impl with a custom ClassLoader to use for locating resources.
 
Method Summary
 CasManager getCasManager()
          Gets the CasManager, which manages the creation and pooling of CASes.
 java.lang.String getDataPath()
          Gets the data path used to resolve relative paths.
 java.lang.ClassLoader getExtensionClassLoader()
          Returns the UIMA extension class loader.
 java.util.Map<java.lang.String,XMLizable> getImportCache()
          Gets a cache of imported descriptors, so that the parsed objects can be reused if the same URL is imported more than once.
protected  RelativePathResolver getRelativePathResolver()
           
 java.lang.Object getResource(java.lang.String aName)
          Gets the Resource that has been registered under the specified name.
 java.lang.Object getResource(java.lang.String aName, java.lang.String[] aParams)
          Gets an instance of a parameterized Resource.
 java.io.InputStream getResourceAsStream(java.lang.String aKey)
          Retrieves an InputStream for reading from the named resource.
 java.io.InputStream getResourceAsStream(java.lang.String aKey, java.lang.String[] aParams)
          Retrieves an InputStream for reading from the named resource.
 java.lang.Class<? extends Resource> getResourceClass(java.lang.String aName)
          Gets the Class of the Resource that will be returned by a call to ResourceManager.getResource(String) or ResourceManager.getResource(String,String[]).
 java.net.URL getResourceURL(java.lang.String aKey)
          Retrieves the URL to the named resource.
 java.net.URL getResourceURL(java.lang.String aKey, java.lang.String[] aParams)
          Retrieves the URL to the named resource.
 void initializeExternalResources(ResourceManagerConfiguration aConfiguration, java.lang.String aQualifiedContextName, java.util.Map<java.lang.String,java.lang.Object> aAdditionalParams)
          Initializes all external resources declared in a ResourceCreationSpecifier.
 void resolveAndValidateResourceDependencies(ExternalResourceDependency[] aDependencies, java.lang.String aQualifiedContextName)
          Resolves a component's external resource dependencies using this resource manager.
 java.net.URL resolveRelativePath(java.lang.String aRelativePath)
          Attempts to resolve a relative path to an absolute path using the same mechanism that the ResourceManager uses to find resources -- a lookup in the datapath followed by a lookup in the classpath.
 void setCasManager(CasManager aCasManager)
          Sets the CasManager, which manages the creation and pooling of CASes.
 void setDataPath(java.lang.String aPath)
          Sets the data path used to resolve relative paths.
 void setExtensionClassPath(java.lang.ClassLoader parent, java.lang.String classpath, boolean resolveResource)
          Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources.
 void setExtensionClassPath(java.lang.String classpath, boolean resolveResource)
          Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_RESOURCE_BUNDLE

protected static final java.lang.String LOG_RESOURCE_BUNDLE
resource bundle for log messages

See Also:
Constant Field Values

mResourceMap

protected java.util.Map<java.lang.String,java.lang.Object> mResourceMap
Map from qualified key names (declared in resource dependency XML) to Resource objects.


mInternalResourceRegistrationMap

protected java.util.Map<java.lang.String,org.apache.uima.resource.impl.ResourceManager_impl.ResourceRegistration> mInternalResourceRegistrationMap
Internal map from resource names (declared in resource declaration XML) to ResourceRegistration objects. Used during initialization only.


mParameterizedResourceImplClassMap

protected java.util.Map<java.lang.String,java.lang.Class<?>> mParameterizedResourceImplClassMap
Map from String keys to Class objects. For ParameterizedResources only, stores the implementation class corresponding to each resource name.


mInternalParameterizedResourceImplClassMap

protected java.util.Map<java.lang.String,java.lang.Class<?>> mInternalParameterizedResourceImplClassMap
Internal map from resource names (declared in resource declaration XML) to Class objects. Used internally during resource initialization.


mParameterizedResourceInstanceMap

protected java.util.Map<java.util.List<java.lang.Object>,java.lang.Object> mParameterizedResourceInstanceMap
Map from ArrayList(0:String,1:DataResource) keys to Resource objects. For ParameterizedResources only, stores the DataResources that have already been encountered, and the Resources that have been instantiated therefrom.


mCasManager

protected CasManager mCasManager
CasManager - manages creation and pooling of CASes.

Constructor Detail

ResourceManager_impl

public ResourceManager_impl()
Creates a new ResourceManager_impl.


ResourceManager_impl

public ResourceManager_impl(java.lang.ClassLoader aClassLoader)
Creates a new ResourceManager_impl with a custom ClassLoader to use for locating resources.

Method Detail

setExtensionClassPath

public void setExtensionClassPath(java.lang.String classpath,
                                  boolean resolveResource)
                           throws java.net.MalformedURLException
Description copied from interface: ResourceManager
Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources.

Specified by:
setExtensionClassPath in interface ResourceManager
Parameters:
classpath - extension ClassLoader classpath
resolveResource - if true ClassLoad resolves resources
Throws:
java.net.MalformedURLException - if a malformed URL has occurred in the classpath string.
See Also:
ResourceManager.setExtensionClassPath(java.lang.String, boolean)

setExtensionClassPath

public void setExtensionClassPath(java.lang.ClassLoader parent,
                                  java.lang.String classpath,
                                  boolean resolveResource)
                           throws java.net.MalformedURLException
Description copied from interface: ResourceManager
Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources. Also allows a parent ClassLoader to be specified.

Specified by:
setExtensionClassPath in interface ResourceManager
Parameters:
parent - parent ClassLoader for the extension ClassLoader
classpath - extension ClassLoader classpath
resolveResource - if true ClassLoad resolves resources
Throws:
java.net.MalformedURLException - if a malformed URL has occurred in the classpath string.
See Also:
ResourceManager.setExtensionClassPath(ClassLoader,java.lang.String, boolean)

getExtensionClassLoader

public java.lang.ClassLoader getExtensionClassLoader()
Description copied from interface: ResourceManager
Returns the UIMA extension class loader.

Specified by:
getExtensionClassLoader in interface ResourceManager
Returns:
ClassLoader - returns the UIMA extension class loader of null if it is not available.
See Also:
ResourceManager.getExtensionClassLoader()

getDataPath

public java.lang.String getDataPath()
Description copied from interface: ResourceManager
Gets the data path used to resolve relative paths. More than one directory may be specified by separating them with the System path.separator character (; on windows, : on UNIX).

Specified by:
getDataPath in interface ResourceManager
Returns:
the data path
See Also:
ResourceManager.getDataPath()

setDataPath

public void setDataPath(java.lang.String aPath)
                 throws java.net.MalformedURLException
Description copied from interface: ResourceManager
Sets the data path used to resolve relative paths. More than one directory may be specified by separating them with the System path.separator character (; on windows, : on UNIX). The elements of this path may be URLs or File paths.

Specified by:
setDataPath in interface ResourceManager
Parameters:
aPath - the data path
Throws:
java.net.MalformedURLException - if an element of the path is neither a valid URL or a valid file path
See Also:
ResourceManager.setDataPath(String)

resolveRelativePath

public java.net.URL resolveRelativePath(java.lang.String aRelativePath)
                                 throws java.net.MalformedURLException
Description copied from interface: ResourceManager
Attempts to resolve a relative path to an absolute path using the same mechanism that the ResourceManager uses to find resources -- a lookup in the datapath followed by a lookup in the classpath.

Specified by:
resolveRelativePath in interface ResourceManager
Parameters:
aRelativePath - a relative URL or file path
Returns:
the absolute URL of an actual file in the datapath or classpath, null if no file matching aRelativePath is found.
Throws:
java.net.MalformedURLException

getResource

public java.lang.Object getResource(java.lang.String aName)
                             throws ResourceAccessException
Description copied from interface: ResourceManager
Gets the Resource that has been registered under the specified name.

Specified by:
getResource in interface ResourceManager
Parameters:
aName - the name of the resource to retrieve
Returns:
the Resource registered under aName, null if none exists.
Throws:
ResourceAccessException
See Also:
ResourceManager.getResource(String)

getResource

public java.lang.Object getResource(java.lang.String aName,
                                    java.lang.String[] aParams)
                             throws ResourceAccessException
Description copied from interface: ResourceManager
Gets an instance of a parameterized Resource. An example of a parameterized Resource is a dictionary whose data depends on a specified language identifier.

Specified by:
getResource in interface ResourceManager
Parameters:
aName - the name of the resource to retrieve
aParams - the parameters determining which particular instance is returned
Returns:
the requested Resource, null if there is no resource registered under the name aName.
Throws:
ResourceAccessException
See Also:
ResourceManager.getResource(java.lang.String, java.lang.String[])

getResourceClass

public java.lang.Class<? extends Resource> getResourceClass(java.lang.String aName)
Description copied from interface: ResourceManager
Gets the Class of the Resource that will be returned by a call to ResourceManager.getResource(String) or ResourceManager.getResource(String,String[]).

Specified by:
getResourceClass in interface ResourceManager
Parameters:
aName - the name of a resource
Returns:
the Class for the resource named aName, null if there is no resource registered under that name.
See Also:
ResourceManager.getResourceClass(java.lang.String)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String aKey,
                                               java.lang.String[] aParams)
                                        throws ResourceAccessException
Description copied from interface: ResourceManager
Retrieves an InputStream for reading from the named resource. This can be used, for example, to read configuration or authority files. This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed.

Specified by:
getResourceAsStream in interface ResourceManager
Parameters:
aKey - the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in the data path or in the class path using ClassLoader.getResource(String).
aParams - parameters used to further identify the resource
Returns:
an InputStream for reading from the named resource, null if the named resource could not be found. It is the caller's responsibility to close this stream once it is no longer needed.
Throws:
ResourceAccessException - if a failure occurs in accessing the resource

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String aKey)
                                        throws ResourceAccessException
Description copied from interface: ResourceManager
Retrieves an InputStream for reading from the named resource. This can be used, for example, to read configuration or authority files.

Specified by:
getResourceAsStream in interface ResourceManager
Parameters:
aKey - the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in the data path or in the class path using ClassLoader.getResource(String).
Returns:
an InputStream for reading from the named resource, null if the named resource could not be found. It is the caller's responsibility to close this stream once it is no longer needed.
Throws:
ResourceAccessException - if a failure occurs in accessing the resource

getResourceURL

public java.net.URL getResourceURL(java.lang.String aKey,
                                   java.lang.String[] aParams)
                            throws ResourceAccessException
Description copied from interface: ResourceManager
Retrieves the URL to the named resource. This can be used, for example, to locate configuration or authority files. This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed.

Specified by:
getResourceURL in interface ResourceManager
Parameters:
aKey - the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in the data path or in the class path using ClassLoader.getResource(String).
aParams - parameters used to further identify the resource
Returns:
the URL at which the named resource is located, null if the named resource could not be found.
Throws:
ResourceAccessException - if a failure occurs in accessing the resource

getResourceURL

public java.net.URL getResourceURL(java.lang.String aKey)
                            throws ResourceAccessException
Description copied from interface: ResourceManager
Retrieves the URL to the named resource. This can be used, for example, to locate configuration or authority files.

Specified by:
getResourceURL in interface ResourceManager
Parameters:
aKey - the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in the data path or in the class path using ClassLoader.getResource(String).
Returns:
the URL at which the named resource is located, null if the named resource could not be found.
Throws:
ResourceAccessException - if a failure occurs in accessing the resource

initializeExternalResources

public void initializeExternalResources(ResourceManagerConfiguration aConfiguration,
                                        java.lang.String aQualifiedContextName,
                                        java.util.Map<java.lang.String,java.lang.Object> aAdditionalParams)
                                 throws ResourceInitializationException
Description copied from interface: ResourceManager
Initializes all external resources declared in a ResourceCreationSpecifier.

Specified by:
initializeExternalResources in interface ResourceManager
Parameters:
aConfiguration - the ResourceManagerConfiguration containing resource declarations and bindings
aQualifiedContextName - qualified name of UimaContext for the component (e.g. analysis engine) that is declaring these external resources
aAdditionalParams - additional parameters to be passed to resource initialize methods
Throws:
ResourceInitializationException - if an initialization failure occurs

resolveAndValidateResourceDependencies

public void resolveAndValidateResourceDependencies(ExternalResourceDependency[] aDependencies,
                                                   java.lang.String aQualifiedContextName)
                                            throws ResourceInitializationException
Description copied from interface: ResourceManager
Resolves a component's external resource dependencies using this resource manager. Throws an exception if any required dependencies are not satisfied.

Specified by:
resolveAndValidateResourceDependencies in interface ResourceManager
Parameters:
aDependencies - declarations of a component's dependencies on external resources
aQualifiedContextName - qualified name of UimaContext for the component (e.g. analysis engine) that is declaring these dependencies
Throws:
ResourceInitializationException - if a required dependency is not satisfied

getCasManager

public CasManager getCasManager()
Description copied from interface: ResourceManager
Gets the CasManager, which manages the creation and pooling of CASes.

Specified by:
getCasManager in interface ResourceManager

setCasManager

public void setCasManager(CasManager aCasManager)
Description copied from interface: ResourceManager
Sets the CasManager, which manages the creation and pooling of CASes. This method does not normally need to be called by an application. It allows a custom CAS Manager implementation to be substituted for the default one, which may be useful when embedding UIMA in other middleware where a different CAS Manager implementation may be desired.

This method can only be called once, and must be called before creating any AnalysisEngines that use this ResourceManager. An Exception will be thrown if this method is called twice or is called after ResourceManager.getCasManager() has already been called (which happens during AE initialization).

Specified by:
setCasManager in interface ResourceManager
Parameters:
aCasManager - CAS Manager instance to plug in

getRelativePathResolver

protected RelativePathResolver getRelativePathResolver()

getImportCache

public java.util.Map<java.lang.String,XMLizable> getImportCache()
Description copied from interface: ResourceManager
Gets a cache of imported descriptors, so that the parsed objects can be reused if the same URL is imported more than once.

Specified by:
getImportCache in interface ResourceManager
Returns:
A map from absolute URL to the XMLizable object that was parsed from thar URL


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.