Class ExternalResourceFactory

java.lang.Object
org.apache.uima.fit.factory.ExternalResourceFactory

public final class ExternalResourceFactory extends Object
Helper methods for external resources.
  • Field Details

  • Method Details

    • isExternalResourceField

      public static boolean isExternalResourceField(Field field)
      This method determines if the field is annotated with ExternalResource.
      Parameters:
      field - the field to analyze
      Returns:
      whether the field is marked as an external resource
    • createResourceDescription

      public static ExternalResourceDescription createResourceDescription(Class<? extends Resource> aInterface, Object... aParams)
      Create an external resource description for a custom resource.
      Parameters:
      aInterface - the interface the resource should implement.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createNamedResourceDescription

      public static ExternalResourceDescription createNamedResourceDescription(String aName, Class<? extends Resource> aInterface, Object... aParams)
      Create an external resource description for a custom resource.
      Parameters:
      aName - the name of the resource (the key).
      aInterface - the interface the resource should implement.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createSharedResourceDescription

      public static ExternalResourceDescription createSharedResourceDescription(String aUrl, Class<? extends SharedResourceObject> aInterface, Object... aParams)
      Create an external resource description for a SharedResourceObject.
      Parameters:
      aUrl - the URL from which the resource is initialized.
      aInterface - the interface the resource should implement.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createSharedResourceDescription

      public static ExternalResourceDescription createSharedResourceDescription(URL aUrl, Class<? extends SharedResourceObject> aInterface, Object... aParams)
      Create an external resource description for a SharedResourceObject.
      Parameters:
      aUrl - the URL from which the resource is initialized.
      aInterface - the interface the resource should implement.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createSharedResourceDescription

      public static ExternalResourceDescription createSharedResourceDescription(File aFile, Class<? extends SharedResourceObject> aInterface, Object... aParams)
      Create an external resource description for a SharedResourceObject.
      Parameters:
      aFile - the file from which the resource is initialized.
      aInterface - the interface the resource should implement.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createNamedResourceDescriptionUsingUrl

      public static ExternalResourceDescription createNamedResourceDescriptionUsingUrl(String aName, Class<? extends SharedResourceObject> aInterface, String aUrl, Object... aParams)
      Create an external resource description for a SharedResourceObject.
      Parameters:
      aName - the name of the resource (the key).
      aInterface - the interface the resource should implement.
      aUrl - the URL from which the resource is initialized.
      aParams - parameters passed to the resource when it is created.
      Returns:
      the description.
      See Also:
    • createNamedFileResourceDescription

      public static ExternalResourceDescription createNamedFileResourceDescription(String aName, String aUrl)
      Create an external resource description for a file addressable via an URL.
      Parameters:
      aName - the name of the resource (the key).
      aUrl - a URL.
      Returns:
      the description.
      See Also:
    • createResourceBinding

      public static ExternalResourceBinding createResourceBinding(String aKey, ExternalResourceDescription aResource)
      Create an external resource binding.
      Parameters:
      aKey - the key to bind to.
      aResource - the resource to bind.
      Returns:
      the description.
    • createResourceBinding

      public static ExternalResourceBinding createResourceBinding(String aKey, String aResourceKey)
      Create an external resource binding. This is a more convenient method of creating an ExternalResourceBinding than calling ResourceSpecifierFactory.createExternalResourceBinding() and setting the resource name and key manually.
      Parameters:
      aKey - the key to bind to.
      aResourceKey - the resource key to bind.
      Returns:
      the description.
    • createResourceDependency

      public static ExternalResourceDependency createResourceDependency(Field field)
      Creates an ExternalResourceDependency for a field annotated with ExternalResource.
      Parameters:
      field - the field to analyze
      Returns:
      a external resource dependency
    • createResourceDependency

      public static ExternalResourceDependency createResourceDependency(String aKey, Class<?> aInterface, boolean aOptional, String aDescription)
      Creates an ExternalResourceDependency for a given key and interface. This is a more convenient method of creating an ExternalResourceDependency than calling ResourceSpecifierFactory.createExternalResourceDependency() and setting the fields manually.
      Parameters:
      aKey - the resource key
      aInterface - the resource interface
      aOptional - determines whether the dependency is optional
      aDescription - a description of the resource
      Returns:
      the external resource dependency
    • createResourceDependencies

      public static ExternalResourceDependency[] createResourceDependencies(Class<?> cls) throws ResourceInitializationException
      Parameters:
      cls - the class to analyze
      Returns:
      the external resource dependencies
      Throws:
      ResourceInitializationException - if the external resource dependencies could not be created
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, String aKey, URL aUrl) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency is encounter that has the specified key, the resource will be bound.

      Caveat: If you use this method, you may expect that DataResource.getUrl() or DataResource.getUri() will return the same URL that you have specified here. This may NOT be the case. UIMA will internally try to resolve the URL via a ResourceManager. If it cannot resolve a remove URL, this mechanism will think it may be a local file and will return some local path - or it may redirect it to some location as though fit by the ResourceManager.

      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aUrl - a URL.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, String aKey, File aFile) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency is encounter that has the specified key, the resource will be bound.

      Caveat: If you use this method, you may expect that DataResource.getUrl() or DataResource.getUri() will return the URL of the file that you have specified here. This may NOT be the case. UIMA will internally try to resolve the URL via a ResourceManager. If it cannot resolve a remove URL, this mechanism will think it may be a local file and will return some local path - or it may redirect it to some location as though fit by the ResourceManager.

      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aFile - a file.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResource

      @Deprecated public static void bindResource(ResourceSpecifier aDesc, String aKey, String aUrl) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency is encountered that has the specified key, the resource will be bound.

      Caveat: If you use this method, you may expect that DataResource.getUrl() or DataResource.getUri() will return the same URL that you have specified here. This is may NOT be the case. UIMA will internally try to resolve the URL via a ResourceManager. If it cannot resolve a remove URL, this mechanism will think it may be a local file and will return some local path - or it may redirect it to some location as though fit by the ResourceManager.

      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aUrl - a URL.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResourceUsingUrl

      public static void bindResourceUsingUrl(ResourceSpecifier aDesc, String aKey, String aUrl) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency is encountered that has the specified key, the resource will be bound.

      Caveat: If you use this method, you may expect that DataResource.getUrl() or DataResource.getUri() will return the same URL that you have specified here. This is may NOT be the case. UIMA will internally try to resolve the URL via a ResourceManager. If it cannot resolve a remove URL, this mechanism will think it may be a local file and will return some local path - or it may redirect it to some location as though fit by the ResourceManager.

      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aUrl - a URL.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, Class<? extends Resource> aRes, String... aParams) throws InvalidXMLException, ClassNotFoundException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with a compatible type is found, the resource will be bound.
      Parameters:
      aDesc - a description.
      aRes - the resource to bind.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      ClassNotFoundException - if the resource implementation class or interface class could not be accessed
      See Also:
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, Class<?> aApi, Class<? extends Resource> aRes, String... aParams) throws InvalidXMLException, ClassNotFoundException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with a compatible type is found, the resource will be bound.
      Parameters:
      aDesc - a description.
      aApi - the resource interface.
      aRes - the resource to bind.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      ClassNotFoundException - if the resource implementation class or interface class could not be accessed
      See Also:
    • bindResourceUsingUrl

      public static void bindResourceUsingUrl(ResourceSpecifier aDesc, Class<? extends SharedResourceObject> aRes, String aUrl, Object... aParams) throws InvalidXMLException, ClassNotFoundException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with a compatible type is found, the resource will be bound.
      Parameters:
      aDesc - a description.
      aRes - the resource to bind.
      aUrl - the URL from which the resource is initialized.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      ClassNotFoundException - if the resource implementation class or interface class could not be accessed
      See Also:
    • bindResourceUsingUrl

      public static void bindResourceUsingUrl(ResourceSpecifier aDesc, Class<?> aApi, Class<? extends SharedResourceObject> aRes, String aUrl, Object... aParams) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency is encountered that has a key equal to the API class name, the resource will be bound.
      Parameters:
      aDesc - a description.
      aApi - the resource interface.
      aRes - the resource to bind.
      aUrl - the URL from which the resource is initialized.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResourceUsingUrl

      public static void bindResourceUsingUrl(ResourceSpecifier aDesc, String aKey, Class<? extends SharedResourceObject> aRes, String aUrl, Object... aParams) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with the given key is encountered the resource will be bound.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aRes - the resource to bind.
      aUrl - the URL from which the resource is initialized.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, String aKey, Class<? extends Resource> aRes, String... aParams) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with the given key is encountered, the given resource is bound to it.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aRes - the resource to bind.
      aParams - parameters passed to the resource when it is created.
      Throws:
      InvalidXMLException - if import resolution failed
      See Also:
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, ExternalResourceDescription aResDesc) throws InvalidXMLException, ClassNotFoundException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with a compatible type is found, the given resource is bound to it.
      Parameters:
      aDesc - a description.
      aResDesc - the resource description.
      Throws:
      InvalidXMLException - if import resolution failed
      ClassNotFoundException - if the resource implementation class or interface class could not be accessed
    • bindResource

      public static void bindResource(ResourceSpecifier aDesc, String aKey, ExternalResourceDescription aResDesc) throws InvalidXMLException
      Scan the given resource specifier for external resource dependencies and whenever a dependency with the given key is encountered, the given resource is bound to it.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aResDesc - the resource description.
      Throws:
      InvalidXMLException - if import resolution failed
    • createDependencyAndBind

      public static void createDependencyAndBind(ResourceSpecifier aDesc, String aKey, Class<? extends Resource> aImpl, String... aParams) throws InvalidXMLException
      Create a new dependency for the specified resource and bind it. This method is helpful for UIMA components that do not use the uimaFIT ExternalResource annotation, because no external resource dependencies can be automatically generated by uimaFIT for such components.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aImpl - the resource implementation.
      aParams - additional parameters supported by the resource.
      Throws:
      InvalidXMLException - if import resolution failed
    • createDependencyAndBind

      public static void createDependencyAndBind(ResourceSpecifier aDesc, String aKey, Class<? extends Resource> aImpl, Class<?> aApi, String... aParams) throws InvalidXMLException
      Create a new dependency for the specified resource and bind it. This method is helpful for UIMA components that do not use the uimaFIT ExternalResource annotation, because no external resource dependencies can be automatically generated by uimaFIT for such components.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aImpl - the resource implementation.
      aApi - the resource interface
      aParams - additional parameters supported by the resource.
      Throws:
      InvalidXMLException - if import resolution failed
    • createDependency

      public static void createDependency(ResourceSpecifier aDesc, String aKey, Class<?> aApi)
      Create a new dependency for the specified resource and bind it. This method is helpful for UIMA components that do not use the uimaFIT ExternalResource annotation, because no external resource dependencies can be automatically generated by uimaFIT for such components.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aApi - the resource API.
    • createDependencyAndBindUsingUrl

      public static void createDependencyAndBindUsingUrl(AnalysisEngineDescription aDesc, String aKey, Class<? extends SharedResourceObject> aImpl, String aUrl, Object... aParams) throws InvalidXMLException
      Create a new dependency for the specified resource and bind it. This method is helpful for UIMA components that do not use the uimaFIT ExternalResource annotation, because no external resource dependencies can be automatically generated by uimaFIT for such components.
      Parameters:
      aDesc - a description.
      aKey - the key to bind to.
      aImpl - the resource implementation.
      aUrl - the resource URL.
      aParams - additional parameters supported by the resource.
      Throws:
      InvalidXMLException - if import resolution failed
    • bindResource

      @Deprecated public static void bindResource(ResourceManagerConfiguration aResMgrCfg, String aBindTo, ExternalResourceDescription aRes)
      Create a binding for the given external resource in the given resource manager. This method also scans the given external resource for any nested external resources and creates bindings for them as well.
      Parameters:
      aResMgrCfg - the resource manager to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • bindResourceOnce

      public static void bindResourceOnce(ResourceManagerConfiguration aResMgrCfg, String aBindTo, ExternalResourceDescription aRes)
      Create a binding for the given external resource in the given resource manager. This method also scans the given external resource for any nested external resources and creates bindings for them as well.

      NOTE:If you use this method on resource manager configurations of aggregate analysis engine descriptions because it will not have any effects on the delegate analysis engines of the aggregate. If you want to recursively bind an external resource to the delegates in an aggregate engine, use e.g. bindResource(ResourceSpecifier, String, ExternalResourceDescription).

      Parameters:
      aResMgrCfg - the resource manager to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • bindResource

      @Deprecated public static void bindResource(ExternalResourceDescription aRes, String aBindTo, ExternalResourceDescription aNestedRes)
      Create a new external resource binding.
      Parameters:
      aRes - the resource to bind to
      aBindTo - what key to bind to.
      aNestedRes - the resource that should be bound.
    • bindResourceOnce

      public static void bindResourceOnce(ExternalResourceDescription aRes, String aBindTo, ExternalResourceDescription aNestedRes)
      Create a binding for the given external resource in the given resource. This method also scans the given external resource for any nested external resources and creates bindings for them as well.

      NOTE: This method only works on ExtendedExternalResourceDescription_impl instances. Any ExternalResourceDescription instances created with uimaFIT use this implementation. For reasons of convenience, the method signature uses ExternalResourceDescription but will thrown an IllegalArgumentException if the wrong implementations are provided.

      Parameters:
      aRes - the resource to bind to
      aBindTo - what key to bind to.
      aNestedRes - the resource that should be bound.
      Throws:
      IllegalArgumentException - if the given resource description is not an instance of ExtendedExternalResourceDescription_impl.
    • bindResourceOnce

      public static void bindResourceOnce(ResourceCreationSpecifier aDesc, String aBindTo, ExternalResourceDescription aRes)
      Create a binding for the given external resource in the resource manager configuration of the given resource. If no resource manager configuration exists yet, it will be created. This method also scans the given external resource for any nested external resources and creates bindings for them as well.

      NOTE:IF you use this method with aggregate analysis engine descriptions because it will not have any effects on the delegate analysis engines of the aggregate. If you want to recursively bind an external resource to the delegates in an aggregate engine, use e.g. bindResource(ResourceSpecifier, String, ExternalResourceDescription).

      Parameters:
      aDesc - the specifier to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • bindResource

      @Deprecated public static void bindResource(ResourceManagerConfiguration aResMgrCfg, String aBindTo, String aRes)
      Create a binding for the given external resource in the given resource manager configuration. This method does not scan the given external resource for any nested external resources and does not create bindings for them. Use bindResourceOnce(ResourceCreationSpecifier, String, ExternalResourceDescription) if you wish to bind nested resources as well.

      NOTE:If you use this method on resource manager configurations of aggregate analysis engine descriptions because it will not have any effects on the delegate analysis engines of the aggregate. If you want to recursively bind an external resource to the delegates in an aggregate engine, use e.g. bindResource(ResourceSpecifier, String, ExternalResourceDescription).

      Parameters:
      aResMgrCfg - the resource manager to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • bindResourceOnceWithoutNested

      public static void bindResourceOnceWithoutNested(ResourceManagerConfiguration aResMgrCfg, String aBindTo, String aRes)
      Create a binding for the given external resource in the given resource manager configuration. This method does not scan the given external resource for any nested external resources and does not create bindings for them. Use bindResourceOnce(ResourceCreationSpecifier, String, ExternalResourceDescription) if you wish to bind nested resources as well.

      NOTE:If you use this method on resource manager configurations of aggregate analysis engine descriptions because it will not have any effects on the delegate analysis engines of the aggregate. If you want to recursively bind an external resource to the delegates in an aggregate engine, use e.g. bindResource(ResourceSpecifier, String, ExternalResourceDescription).

      Parameters:
      aResMgrCfg - the resource manager to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • bindResourceOnceWithoutNested

      public static void bindResourceOnceWithoutNested(ResourceCreationSpecifier aDesc, String aBindTo, String aRes)
      Create a binding for the given external resource in resource manager configuration of the given resource creation specified. If no resource manager configuration exists yet, it is created. This method does not scan the given external resource for any nested external resources and does not create bindings for them. Use bindResourceOnce(ResourceCreationSpecifier, String, ExternalResourceDescription) if you wish to bind nested resources as well.

      NOTE:If you use this method on an aggregate analysis engine description, it will not have any effects on the delegate analysis engines of the aggregate. If you want to recursively bind an external resource to the delegates in an aggregate engine, use e.g. bindResource(ResourceSpecifier, String, ExternalResourceDescription).

      Parameters:
      aDesc - the specifier to create the binding in.
      aBindTo - what key to bind to.
      aRes - the resource that should be bound.
    • getImplementationName

      protected static String getImplementationName(ExternalResourceDescription aDesc)
      Find the name of the class implementing this resource. The location where this name is stored varies, depending if the resource extends SharedResourceObject or implements Resource.
      Parameters:
      aDesc - the external resource description.
      Returns:
      the implementation name.
    • extractResourceParameters

      protected static Map<String,ExternalResourceDescription> extractResourceParameters(Object[] configurationData)
      Extracts the external resource from the configuration parameters and nulls out these parameters. Mind that the array passed to this method is modified by the method.
      Parameters:
      configurationData - the configuration parameters.
      Returns:
      extRes the external resource parameters.
    • createResource

      public static <R extends Resource> R createResource(Class<R> resourceClass, Object... params) throws ResourceInitializationException
      Create an instance of a UIMA shared/external resource class.
      Type Parameters:
      R - the resource type.
      Parameters:
      resourceClass - the class implementing the resource.
      params - parameters passed to the resource when it is created. Each parameter consists of two arguments, the first being the name and the second being the parameter value
      Returns:
      the resource instance.
      Throws:
      ResourceInitializationException - if there was a problem instantiating the resource.
    • createResource

      public static <R extends Resource> R createResource(Class<R> resourceClass, ResourceManager resMgr, Object... params) throws ResourceInitializationException
      Create an instance of a UIMA shared/external resource class.
      Type Parameters:
      R - the resource type.
      Parameters:
      resourceClass - the class implementing the resource.
      resMgr - a resource manager (optional).
      params - parameters passed to the resource when it is created. Each parameter consists of two arguments, the first being the name and the second being the parameter value
      Returns:
      the resource instance.
      Throws:
      ResourceInitializationException - if there was a problem instantiating the resource.