org.apache.uima.fit.util

## 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);

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.uima.resource.impl.ResourceManager_impl

      `ResourceManager_impl.ResourceRegistration`

  - ### Field Summary

    - ### Fields inherited from class org.apache.uima.resource.impl.ResourceManager_impl

      `EMPTY_RESOURCE_CLASS, LOG_RESOURCE_BUNDLE, mCasManager, mInternalParameterizedResourceImplClassMap, mInternalResourceRegistrationMap, mParameterizedResourceImplClassMap, mParameterizedResourceInstanceMap, mResourceMap`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleNamedResourceManager()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `initializeExternalResources(ResourceManagerConfiguration aConfiguration, String aQualifiedContextName, Map<String,Object> aAdditionalParams)`
    `boolean` | `isAutoWireEnabled()`
    `void` | `setAutoWireEnabled(boolean aAutoWireEnabled)`
    `void` | `setExternalContext(Map<String,Object> aExternalContext)`

    - ### Methods inherited from class org.apache.uima.resource.impl.ResourceManager_impl

      `copy, destroy, getCasManager, getDataPath, getExtensionClassLoader, getExternalResources, getImportCache, getImportUrlsCache, getRelativePathResolver, getResource, getResource, getResourceAsStream, getResourceAsStream, getResourceClass, getResourceURL, getResourceURL, loadUserClass, loadUserClass, loadUserClassOrThrow, resolveAndValidateResourceDependencies, resolveRelativePath, setCasManager, setDataPath, setExtensionClassLoaderImpl, setExtensionClassPath, setExtensionClassPath, setExtensionClassPath`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.uima.resource.ResourceManager

      `setExtensionClassLoader`

- - ### Constructor Detail

    - #### SimpleNamedResourceManager

          public SimpleNamedResourceManager()

  - ### Method Detail

    - #### initializeExternalResources

          public void initializeExternalResources(ResourceManagerConfiguration aConfiguration,
                                                  String aQualifiedContextName,
                                                  Map<String,Object> aAdditionalParams)
                                           throws ResourceInitializationException

      Specified by:
        `initializeExternalResources` in interface `ResourceManager`
      Overrides:
        `initializeExternalResources` in class `ResourceManager_impl`
      Throws:
        `ResourceInitializationException`

    - #### setExternalContext

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

    - #### setAutoWireEnabled

          public void setAutoWireEnabled(boolean aAutoWireEnabled)

    - #### isAutoWireEnabled

          public boolean isAutoWireEnabled()

Copyright © 2012–2021 The Apache Software Foundation. All rights reserved.