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()
Deprecated.
Use
getDataPathElements() instead. |
List<String> |
getDataPathElements()
Gets the data path elements 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
ThreadLocal Context Class Loader (if available) 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)
Deprecated.
Use
setDataPathElements(java.lang.String...) instead. |
void |
setDataPathElements(File... aElements)
Sets the data path elements used to resolve relative paths.
|
void |
setDataPathElements(String... aElements)
Sets the data path elements used to resolve relative paths.
|
default void |
setExtensionClassLoader(ClassLoader classLoader,
boolean resolveResources)
Set an extension class loader into the Resource Manager
|
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.
|
@Deprecated String getDataPath()
getDataPathElements()
instead.path.separator
character (; on windows, : on
UNIX).List<String> getDataPathElements()
@Deprecated void setDataPath(String aPath) throws MalformedURLException
setDataPathElements(java.lang.String...)
instead.path.separator
character (; on windows, : on
UNIX). Elements of this path may be absolute or relative file paths.aPath
- the data pathMalformedURLException
- if an element of the path is neither a valid URL or a valid file pathvoid setDataPathElements(String... aElements) throws MalformedURLException
aElements
- the data pathMalformedURLException
- if an element of the path is neither a valid URL or a valid file pathvoid setDataPathElements(File... aElements) throws MalformedURLException
aElements
- 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.default void setExtensionClassLoader(ClassLoader classLoader, boolean resolveResources)
classLoader
- the loader to use. If this is an instance of UIMAClassLoader, it is used directly;
otherwise, a new UIMAClassLoader with no classpath, having the classLoader as a parent
is created and used.resolveResources
- true to also use this to resolve resourcesClassLoader 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
- generic class of classname
- the class to loadClassNotFoundException
- -void destroy()
Copyright © 2006–2022 The Apache Software Foundation. All rights reserved.