Class SimpleNamedResourceManager

java.lang.Object
org.apache.uima.resource.impl.ResourceManager_impl
org.apache.uima.fit.util.SimpleNamedResourceManager
All Implemented Interfaces:
ResourceManager

public class SimpleNamedResourceManager extends ResourceManager_impl
EXPERIMENTAL CODE

Simple ResourceManager allowing for direct injection of Java objects into UIMA components as external resources.

This implementation uses a simple map to look up an Java object by key. If any component using this resource manager declares an external resource by the given key, the Java object will be bound to that external resource.

Example:

 class MyComponent extends JCasAnnotator_ImplBase {
   static final String RES_INJECTED_POJO = "InjectedPojo";
   @ExternalResource(key = RES_INJECTED_POJO)
   private String injectedString;
 
   public void process(JCas aJCas) throws AnalysisEngineProcessException {
     ...
   }
 }
 
Per default it is necessary to explicitly bind a objects from the external context to external resource keys used by the UIMA component:
 Map<String, Object> context = new HashMap<String, Object>();
 context("myString", "Just an injected POJO");
 
 SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
 resMgr.setExternalContext(externalContext);
 
 AnalysisEngineDescription desc = createPrimitiveDescription(MyComponent.class);
 bindExternalResource(desc, MyComponent.RES_INJECTED_POJO, "myString");
 AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
 
With autowireing enabled, an explicit binding is not necessary:
 Map<String, Object> context = new HashMap<String, Object>();
 context(MyComponent.RES_INJECTED_POJO, "Just an injected POJO");
 
 SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
 resMgr.setAutoWireEnabled(true);
 resMgr.setExternalContext(externalContext);
 
 AnalysisEngineDescription desc = createPrimitiveDescription(MyComponent.class);
 AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
 
  • Constructor Details

    • SimpleNamedResourceManager

      public SimpleNamedResourceManager()
  • Method Details

    • initializeExternalResources

      public void initializeExternalResources(ResourceManagerConfiguration aConfiguration, String aQualifiedContextName, Map<String,Object> aAdditionalParams) throws ResourceInitializationException
      Description copied from interface: ResourceManager
      Initializes all external resources declared in a ResourceCreationSpecifier. Multi-threading: may be called on multiple threads. Initialization should be done once, on the first call External resources have a Container class representing the resource, which are instances of Resource. This may act as the implementation class, or they may also have a separately specified implementation class, which may or may not implement Resource. As part of the initialization of the Container class, by default, External Resource Bindings are processed to hook them up with defined External Resources, using the default implementation of resolveAndValidateResourceDependencies.
      Specified by:
      initializeExternalResources in interface ResourceManager
      Overrides:
      initializeExternalResources in class ResourceManager_impl
      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
    • setExternalContext

      public void setExternalContext(Map<String,Object> aExternalContext)
    • setAutoWireEnabled

      public void setAutoWireEnabled(boolean aAutoWireEnabled)
    • isAutoWireEnabled

      public boolean isAutoWireEnabled()