public ResourceManager newResourceManager()

in uimafit-core/src/main/java/org/apache/uima/fit/internal/ResourceManagerFactory.java [71:112]


    public ResourceManager newResourceManager() throws ResourceInitializationException {
      UimaContext activeContext = UimaContextHolder.getContext();
      if (activeContext != null) {
        // If we are already in a UIMA context, then we re-use it. Mind that the JCas cannot
        // handle switching across more than one classloader.
        // This can be done since UIMA 2.9.0 and starts being handled in uimaFIT 2.3.0
        // See https://issues.apache.org/jira/browse/UIMA-5056
        LOG.trace("Using resource manager from active UIMA context");
        return ((UimaContextAdmin) activeContext).getResourceManager();
      }

      // If there is no UIMA context, then we create a new resource manager
      // UIMA core still does not fall back to the context classloader in all cases.
      // This was the default behavior until uimaFIT 2.2.0.
      ResourceManager resMgr;
      if (Thread.currentThread().getContextClassLoader() != null) {
        // If the context classloader is set, then we want the resource manager to fallb
        // back to it. However, it may not reliably do that that unless we explictly pass
        // null here. See. UIMA-6239.
        LOG.trace("Detected thread context classloader: preparing resource manager to use it");
        resMgr = new ResourceManager_impl(null);
      } else {
        resMgr = UIMAFramework.newDefaultResourceManager();
      }

      // Since UIMA Core version 2.10.3 and 3.0.1 the thread context classloader is taken
      // into account by the core framework. Thus, we no longer have to explicitly set a
      // classloader these or more recent versions. (cf. UIMA-5802)
      short maj = UimaVersion.getMajorVersion();
      short min = UimaVersion.getMinorVersion();
      short rev = UimaVersion.getBuildRevision();
      boolean uimaCoreIgnoresContextClassloader = (maj == 2 && (min < 10 || (min == 10 && rev < 3)))
              || // version < 2.10.3
              (maj == 3 && ((min == 0 && rev < 1))); // version < 3.0.1
      if (uimaCoreIgnoresContextClassloader) {
        LOG.trace("Detected UIMA version " + maj + "." + min + "." + rev
                + " which ignores the thread context classloader, setting it explicitly");
        resMgr.setExtensionClassLoader(ClassLoaderUtils.findClassloader(), true);
      }

      return resMgr;
    }