public interface ResourceManager
ResourceManager
holds a collection of Resource
objects, each registered under a specified key.Modifier and Type | Method and Description |
---|---|
void |
destroy()
Frees all resources held by this ResourceManager, and marks the ResourceManager as having been destroyed.
|
CasManager |
getCasManager()
Gets the CasManager, which manages the creation and pooling of CASes.
|
String |
getDataPath()
Gets the data path used to resolve relative paths.
|
ClassLoader |
getExtensionClassLoader()
Returns the UIMA extension class loader.
|
List<Object> |
getExternalResources() |
Map<String,XMLizable> |
getImportCache()
Deprecated.
Intended just for internal use.
|
Object |
getResource(String aName)
Gets the instance of the implementation object for a resource that has been registered under the specified name.
|
Object |
getResource(String aName,
String[] aParams)
Returns one of two kinds of objects (or null):
- an instance of the implementation object for a resource, that has
been loaded with a DataResource resource produced by the resource given the aParms
- (if there is no implementation defined for this resource)
returns an instance of the DataResource, itself, produced by the resource given the aParms
An example of a parameterized Resource is a
dictionary whose data depend on a specified language identifier.
|
InputStream |
getResourceAsStream(String aKey)
Retrieves an InputStream for reading from the named resource.
|
InputStream |
getResourceAsStream(String aKey,
String[] aParams)
Retrieves an InputStream for reading from the named resource.
|
<N> Class<N> |
getResourceClass(String aName)
Gets the Class of the Resource that will be returned by a call to
getResource(String)
or getResource(String,String[]) . |
URL |
getResourceURL(String aKey)
Retrieves the URL to the named resource.
|
URL |
getResourceURL(String aKey,
String[] aParams)
Retrieves the URL to the named resource.
|
void |
initializeExternalResources(ResourceManagerConfiguration aConfiguration,
String aQualifiedContextName,
Map<String,Object> aAdditionalParams)
Initializes all external resources declared in a ResourceCreationSpecifier.
|
<N> Class<N> |
loadUserClass(String name)
Loads a user class using either the UIMA extension class loader (if specified) or
the loader the UIMA framework is running in.
|
void |
resolveAndValidateResourceDependencies(ExternalResourceDependency[] aDependencies,
String aQualifiedContextName)
Resolves a component's external resource dependencies (bindings) using this resource manager.
|
URL |
resolveRelativePath(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(String aPath)
Sets the data path used to resolve relative paths.
|
void |
setExtensionClassPath(ClassLoader parent,
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(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.
|
String getDataPath()
path.separator
character (; on windows, : on
UNIX).void setDataPath(String aPath) throws MalformedURLException
path.separator
character (; on windows, : on
UNIX). The elements of this path may be URLs or File paths.aPath
- the data pathMalformedURLException
- if an element of the path is neither a valid URL or a valid file pathURL resolveRelativePath(String aRelativePath) throws MalformedURLException
aRelativePath
- a relative URL or file pathaRelativePath
is found.MalformedURLException
- if the path cannot be converted to a URLObject getResource(String aName) throws ResourceAccessException
aName
- the name of the resource to retrieveaName
,
null
if none exists.ResourceAccessException
- if the requested resource could not be initialized. A common cause is that it
requires parameters and the getResource(String,String[])
method should have
been called instead of this method.ResourceAccessException
- tbdObject getResource(String aName, String[] aParams) throws ResourceAccessException
aName
- the name of the parameterized resource to retrieveaParams
- the parameters determining which particular instance is returned
and specifying a particular DataResource instance to use in initializing
the implementation of the resource (if there is an implementation).
If there is no implementation, the DataResource instance
produced from the named Resource given these
parameters is returned instead.null
.ResourceAccessException
- if there is a resource registered under aName
but it could not be
instantiated for the specified parameters.<N> Class<N> getResourceClass(String aName)
getResource(String)
or getResource(String,String[])
.
For those resource specifications which include an implementation class, this call returns that class.N
- The generic type for the returned classaName
- the name of a resourceaName
, null
if there is
no resource registered under that name.URL getResourceURL(String aKey) throws ResourceAccessException
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)
.URL
at which the named resource is located, null
if
the named resource could not be found.ResourceAccessException
- if a failure occurs in accessing the resourceInputStream getResourceAsStream(String aKey) throws ResourceAccessException
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)
.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.ResourceAccessException
- if a failure occurs in accessing the resourceURL getResourceURL(String aKey, String[] aParams) throws ResourceAccessException
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 resourceURL
at which the named resource is located, null
if
the named resource could not be found.ResourceAccessException
- if a failure occurs in accessing the resourceInputStream getResourceAsStream(String aKey, String[] aParams) throws ResourceAccessException
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 resourceInputStream
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.ResourceAccessException
- if a failure occurs in accessing the resourcevoid initializeExternalResources(ResourceManagerConfiguration aConfiguration, String aQualifiedContextName, Map<String,Object> aAdditionalParams) throws ResourceInitializationException
aConfiguration
- the ResourceManagerConfiguration containing resource declarations and bindingsaQualifiedContextName
- qualified name of UimaContext for the component (e.g. analysis engine) that is
declaring these external resourcesaAdditionalParams
- additional parameters to be passed to resource initialize methodsResourceInitializationException
- if an initialization failure occursvoid resolveAndValidateResourceDependencies(ExternalResourceDependency[] aDependencies, String aQualifiedContextName) throws ResourceInitializationException
aDependencies
- declarations of a component's dependencies on external resourcesaQualifiedContextName
- qualified name of UimaContext for the component (e.g. analysis engine) that is
declaring these dependenciesResourceInitializationException
- if a required dependency is not satisfiedvoid setExtensionClassPath(String classpath, boolean resolveResource) throws MalformedURLException
classpath
- extension ClassLoader classpathresolveResource
- if true ClassLoad resolves resourcesMalformedURLException
- if a malformed URL has occurred in the classpath string.void setExtensionClassPath(ClassLoader parent, String classpath, boolean resolveResource) throws MalformedURLException
parent
- parent ClassLoader for the extension ClassLoaderclasspath
- extension ClassLoader classpathresolveResource
- if true ClassLoad resolves resourcesMalformedURLException
- if a malformed URL has occurred in the classpath string.ClassLoader getExtensionClassLoader()
CasManager getCasManager()
void setCasManager(CasManager aCasManager)
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 getCasManager()
has already been called
(which happens during AE initialization).
aCasManager
- CAS Manager instance to plug in@Deprecated Map<String,XMLizable> getImportCache()
<N> Class<N> loadUserClass(String name) throws ClassNotFoundException
N
- the generic type for the returned classname
- the class to loadClassNotFoundException
- -void destroy()
Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.