You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2008/11/21 23:18:07 UTC

svn commit: r719734 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/ main/java/org/apache/uima/analysis_engine/impl/ main/java/org/apache/uima/impl/ main/java/org/apache/uima/resource/ main/java/org/apache/uima/resource/impl/...

Author: schor
Date: Fri Nov 21 14:18:06 2008
New Revision: 719734

URL: http://svn.apache.org/viewvc?rev=719734&view=rev
Log:
[UIMA-1170] Changed PearWrapper to pass in to the pear the UIMA Context - this lets things like sofa mappings work.  Changed the UIMA Context to allow it to have overriding ResourceManager - this allows the Pear to run with a different Classpath, Data path.  Changed the ResourceManager to add a subclass of it just to hold the ClassPath and Datapath, while sharing all the other fields with its parent.  This is needed to do even basic things like collect all the type systems in use together so the CAS creation has the right type system to create.  Added test case for passing sofa maps into a pear.  Added a test pear for this that requires a mapping.

Added:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManagerPearWrapper.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManagerPearWrapper_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/pearTests/pearSofaMap.pear   (with props)
Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/ChildUimaContext_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/RootUimaContext_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/impl/factoryConfig.xml
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/PearRuntimeTest.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java Fri Nov 21 14:18:06 2008
@@ -945,6 +945,15 @@
   }
 
   /**
+   * Gets a new instance of the default {@link ResourceManagerPearWrapper} used by this implementation. 
+   * 
+   * @return a new <code>ResourceManagerPearWrapper</code> to be used by the application.
+   */
+  public static ResourceManager newDefaultResourceManagerPearWrapper() {
+    return getInstance()._newDefaultResourceManagerPearWrapper();
+  }
+
+  /**
    * Gets a new instance of the {@link ConfigurationManager} used by this implementation. This will
    * be used by Resources to manage access to their configuration parameters.
    * 
@@ -1125,6 +1134,15 @@
 
   /**
    * To be implemented by subclasses; this should return a new instance of the default
+   * {@link ResourceManagerPearWrapper} used by this implementation.
+   * 
+   * @return a new <code>ResourceManagerPearWrapper</code> to be used by the application.
+   */
+  protected abstract ResourceManager _newDefaultResourceManagerPearWrapper();
+  
+  
+  /**
+   * To be implemented by subclasses; this should return a new instance of the default
    * {@link ConfigurationManager} used by this implementation.
    * 
    * @return a new <code>ConfigurationManager</code> to be used by the application.

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java Fri Nov 21 14:18:06 2008
@@ -37,11 +37,13 @@
 import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.impl.ChildUimaContext_impl;
 import org.apache.uima.pear.tools.PackageBrowser;
 import org.apache.uima.resource.PearSpecifier;
 import org.apache.uima.resource.Resource;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceManagerPearWrapper;
 import org.apache.uima.resource.ResourceProcessException;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
@@ -63,14 +65,25 @@
    // key = resourceManager instance associated with this call
    // value = map <String_Pair, ResourceManager>
    // value = resourceManager instance created by this class
+  
+   // The reason we do this: For cases involving Cas Pools and multiple
+   //  threads, we want to share the resource manager - otherwise
+   //  there could be multiple instances of the classes for this pear
+   //  loaded.
+   // The map is a double map.  The first one maps between the
+   // incoming Resource Manager, and a second map.
+   // The second map (allows for multiple Pears in a pipeline)
+   // maps (for the given incoming Resource Manager), using a key
+   // consisting of the "class path" and "data path", the 
+   // Resource Manager for that combination.
 
-   static private Map cachedResourceManagers = Collections
-         .synchronizedMap(new WeakHashMap(4));
+   static private Map<ResourceManager, Map<StringPair, ResourceManager>> cachedResourceManagers = Collections
+         .synchronizedMap(new WeakHashMap<ResourceManager, Map<StringPair, ResourceManager>>(4));
 
    private AnalysisEngine ae = null;
 
-   private Map createRMmap(StringPair sp, ResourceManager rm) {
-      Map result = new HashMap(4);
+   private Map<StringPair, ResourceManager> createRMmap(StringPair sp, ResourceManager rm) {
+      Map<StringPair, ResourceManager> result = new HashMap<StringPair, ResourceManager>(4);
       result.put(sp, rm);
       UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG,
             this.getClass().getName(), "createRMmap", LOG_RESOURCE_BUNDLE,
@@ -79,12 +92,20 @@
       return result;
    }
 
-   private ResourceManager createRM(StringPair sp, PackageBrowser pkgBrowser)
+   private ResourceManager createRM(StringPair sp, PackageBrowser pkgBrowser, ResourceManager parentResourceManager)
          throws MalformedURLException {
       // create UIMA resource manager and apply pear settings
-      ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager();
-      rsrcMgr.setExtensionClassPath(sp.classPath, true);
-      UIMAFramework.getLogger(this.getClass()).logrb(
+//      ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager();
+     ResourceManager rsrcMgr;
+     if (null == parentResourceManager) {
+       // could be null for top level Pear not in an aggregate
+       rsrcMgr = UIMAFramework.newDefaultResourceManager();
+     } else {
+       rsrcMgr = UIMAFramework.newDefaultResourceManagerPearWrapper();
+       ((ResourceManagerPearWrapper)rsrcMgr).initializeFromParentResourceManager(parentResourceManager);
+     }
+     rsrcMgr.setExtensionClassPath(sp.classPath, true);
+     UIMAFramework.getLogger(this.getClass()).logrb(
             Level.CONFIG,
             this.getClass().getName(),
             "createRM",
@@ -113,6 +134,15 @@
     * 
     * @see org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase#initialize(org.apache.uima.resource.ResourceSpecifier,
     *      java.util.Map)
+    *      
+    * (Nov 2008) initialize is called as a normal part of produceResource.  
+    * There are 2 cases: 
+    *   1) The Pear is the top level component
+    *   2) The Pear is contained in an aggregate.
+    *   
+    *   In Case (1), the aAdditionalParams passed in does *not* contain a UIMA_CONTEXT
+    *   In Case (2), the aAdditionalParams passed in contains a child UIMA_CONTEXT 
+    *     created for this component.
     */
    public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
          throws ResourceInitializationException {
@@ -191,14 +221,14 @@
          StringPair sp = new StringPair(classPath, dataPath);
          ResourceManager innerRM;
 
-         Map c1 = (Map) cachedResourceManagers.get(applicationRM);
+         Map<StringPair, ResourceManager> c1 = cachedResourceManagers.get(applicationRM);
          if (null == c1) {
-            innerRM = createRM(sp, pkgBrowser);
+            innerRM = createRM(sp, pkgBrowser, applicationRM);
             cachedResourceManagers.put(applicationRM, createRMmap(sp, innerRM));
          } else {
             innerRM = (ResourceManager) c1.get(sp);
             if (null == innerRM) {
-               innerRM = createRM(sp, pkgBrowser);
+               innerRM = createRM(sp, pkgBrowser, applicationRM);
                c1.put(sp, innerRM);
                UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG,
                      this.getClass().getName(), "initialize",
@@ -215,9 +245,18 @@
          ResourceSpecifier specifier = UIMAFramework.getXMLParser()
                .parseResourceSpecifier(in);
 
+         UimaContextAdmin uimaContext = (UimaContextAdmin) aAdditionalParams.get(Resource.PARAM_UIMA_CONTEXT);
+         if (null != uimaContext) {
+           ((ChildUimaContext_impl)uimaContext).setPearResourceManager(innerRM);
+         }
          // create analysis engine
+         // Cloning is needed because the aAdditionalParameters, if 
+         //  passed without cloning to produceAnalysisEngine, gets
+         //  modified, and the aAdditionalParameters original object
+         //  is re-used by the ASB_impl - a caller of this method,
+         //  for other delegates.
          Map clonedAdditionalParameters = new HashMap(aAdditionalParams);
-         clonedAdditionalParameters.remove(Resource.PARAM_UIMA_CONTEXT);
+//         clonedAdditionalParameters.remove(Resource.PARAM_UIMA_CONTEXT);
          clonedAdditionalParameters.remove(Resource.PARAM_RESOURCE_MANAGER);
          this.ae = UIMAFramework
                .produceAnalysisEngine(specifier, innerRM, clonedAdditionalParameters);

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/ChildUimaContext_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/ChildUimaContext_impl.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/ChildUimaContext_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/ChildUimaContext_impl.java Fri Nov 21 14:18:06 2008
@@ -53,6 +53,21 @@
    */
   private SessionNamespaceView_impl mSessionNamespaceView;
 
+  /**
+   * ResourceManager used to locate and access external resources
+   * Set non-null only for Pear resources contained in an aggregate
+   */
+  
+  private ResourceManager mPearResourceManager = null;
+
+  /**
+   * ref to the parent.  
+   * This is only used to find containing resource managers
+   * that may exist due to Pear Wrappers
+   *
+   */
+  private final UimaContextAdmin parentContext;
+
   /*
    * (non-Javadoc) Creates a child context.
    */
@@ -64,6 +79,7 @@
     mSessionNamespaceView = new SessionNamespaceView_impl(mRootContext.getSession(),
             mQualifiedContextName);
     mSofaMappings = aSofaMappings;
+    parentContext = aParentContext;
   }
 
   /*
@@ -102,9 +118,21 @@
    * @return the ResourceManager
    */
   public ResourceManager getResourceManager() {
-    return getRootContext().getResourceManager();
+    if (null == mPearResourceManager) {
+      return parentContext.getResourceManager();
+    }
+    return mPearResourceManager;
   }
 
+  /**
+   * Set the Pear resource manager, to be used instead of any
+   * containing Resource Manager.
+   * @param resourceManager
+   */
+  public void setPearResourceManager(ResourceManager resourceManager) {
+    mPearResourceManager = resourceManager;
+  }
+  
   /*
    * (non-Javadoc)
    * 

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/RootUimaContext_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/RootUimaContext_impl.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/RootUimaContext_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/RootUimaContext_impl.java Fri Nov 21 14:18:06 2008
@@ -35,7 +35,7 @@
 /**
  * Implementation of the root {@link UimaContext}. UIMA Contexts are arranged in a tree structure
  * corresponding to the nested structure of the components in a CPE or Aggregate AE. The root
- * UimaContext has direct references to shared compoennts such as the ResourceManager and
+ * UimaContext has direct references to shared components such as the ResourceManager and
  * ConfigurationManager. The children UimaContexts reference these through the root.
  */
 public class RootUimaContext_impl extends UimaContext_ImplBase {

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java Fri Nov 21 14:18:06 2008
@@ -122,6 +122,12 @@
   private String mResourceManagerImplClassName;
 
   /**
+   * ResourceManagerPearWrapper implementation class, an instance of which will be returned by
+   * {@link #newDefaultResourceManagerPearWrapper()}.
+   */
+  private String mResourceManagerPearWrapperImplClassName;
+
+  /**
    * ConfigurationManager implementation class, an instance of which will be returned by
    * {@link #newConfigurationManager()}.
    */
@@ -334,6 +340,24 @@
   }
 
   /**
+   * To be implemented by subclasses; this should return a new instance of the default
+   * {@link ResourceManager) used by this implementation.
+   * 
+   * @return a new <code>ResourceManager</code> to be used by the application.
+   */
+  protected ResourceManager _newDefaultResourceManagerPearWrapper() {
+    try {
+      return (ResourceManager) Class.forName(mResourceManagerPearWrapperImplClassName).newInstance();
+    } catch (InstantiationException e) {
+      throw new UIMARuntimeException(e);
+    } catch (IllegalAccessException e) {
+      throw new UIMARuntimeException(e);
+    } catch (ClassNotFoundException e) {
+      throw new UIMARuntimeException(e);
+    }
+  }
+
+  /**
    * To be implemented by subclasses; this should return a new instance of the
    * {@link ConfigurationManager) used by this implementation.
    * 
@@ -509,6 +533,13 @@
                   new Object[] { "<resourceManager>" }));
         }
         mResourceManagerImplClassName = attributes.getValue("class");
+      } else if ("resourceManagerPearWrapper".equals(qName)) {
+        if (context != CONTEXT_FACTORY_CONFIG) {
+          throw new SAXException(I18nUtil.localizeMessage(UIMAException.STANDARD_MESSAGE_CATALOG,
+                  Locale.getDefault(), "element_unexpected_in_context",
+                  new Object[] { "<resourceManagerPearWrapper>" }));
+        }
+        mResourceManagerPearWrapperImplClassName = attributes.getValue("class");      
       } else if ("configurationManager".equals(qName)) {
         if (context != CONTEXT_FACTORY_CONFIG) {
           throw new SAXException(I18nUtil.localizeMessage(UIMAException.STANDARD_MESSAGE_CATALOG,

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManagerPearWrapper.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManagerPearWrapper.java?rev=719734&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManagerPearWrapper.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManagerPearWrapper.java Fri Nov 21 14:18:06 2008
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.resource;
+
+
+/**
+ * A <code>ResourceManagerPearWrapper</code> is a 
+ * special Resource Manager, sharing all its fields with its parent,
+ * except for the class path and data path fields.
+ * 
+ * 
+ */
+public interface ResourceManagerPearWrapper extends ResourceManager {
+  /**
+   * Pear Wrapper Resource Managers share all their values with their parent,
+   * except for the 2 values used to store the Classpath and Datapath.
+   * 
+   * This method is called immediately after the factory creates the 
+   * object (using the 0-argument constructor), and it initializes all
+   * the fields in this wrapper to share the values with their parent.
+   * @param resourceManager
+   */
+  void initializeFromParentResourceManager(ResourceManager resourceManager);
+}

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManagerPearWrapper_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManagerPearWrapper_impl.java?rev=719734&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManagerPearWrapper_impl.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManagerPearWrapper_impl.java Fri Nov 21 14:18:06 2008
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.resource.impl;
+
+import java.net.MalformedURLException;
+
+import org.apache.uima.internal.util.UIMAClassLoader;
+import org.apache.uima.resource.RelativePathResolver;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceManagerPearWrapper;
+
+/**
+ * Reference implementation of {@link org.apache.uima.resource.ResourceManager},
+ * used for PearAnalysisEngineWrapper.
+ * 
+ * It is a subclass of ResourceManager_impl, with a different classpath/datapath
+ * but everything else referring to the same objects as the parent.
+ * 
+ * 
+ */
+public class ResourceManagerPearWrapper_impl extends ResourceManager_impl implements ResourceManagerPearWrapper {
+
+  /**
+   * UIMA extension ClassLoader. ClassLoader is created if an extension classpath is specified at
+   * the ResourceManager
+   */
+  private UIMAClassLoader uimaCL = null;
+
+  /**
+   * Object used for resolving relative paths. This is built by parsing the data path.
+   */
+  private RelativePathResolver mRelativePathResolver;
+
+  /**
+   * Initializes from the parent, a new <code>ResourceManagerForPearWrapper_impl</code>.
+   */
+  public void initializeFromParentResourceManager(ResourceManager resourceManager) {
+    ResourceManager_impl r = (ResourceManager_impl) resourceManager;
+    mRelativePathResolver = new RelativePathResolver_impl();
+    mResourceMap = r.mResourceMap;
+    mInternalResourceRegistrationMap = r.mInternalResourceRegistrationMap;
+    mParameterizedResourceImplClassMap = r.mParameterizedResourceImplClassMap;
+    mInternalParameterizedResourceImplClassMap = r.mInternalParameterizedResourceImplClassMap;
+    mParameterizedResourceInstanceMap = r.mParameterizedResourceInstanceMap;
+    mCasManager = r.mCasManager;
+  }
+ 
+  /**
+   * @see org.apache.uima.resource.ResourceManager#setExtensionClassPath(java.lang.String, boolean)
+   */
+  public void setExtensionClassPath(String classpath, boolean resolveResource)
+          throws MalformedURLException {
+    // create UIMA extension ClassLoader with the given classpath
+    uimaCL = new UIMAClassLoader(classpath, this.getClass().getClassLoader());
+
+    if (resolveResource) {
+      // set UIMA extension ClassLoader also to resolve resources
+      getRelativePathResolver().setPathResolverClassLoader(uimaCL);
+    }
+  }
+
+  /**
+   * @see org.apache.uima.resource.ResourceManager#setExtensionClassPath(ClassLoader,java.lang.String,
+   *      boolean)
+   */
+  public void setExtensionClassPath(ClassLoader parent, String classpath, boolean resolveResource)
+          throws MalformedURLException {
+    // create UIMA extension ClassLoader with the given classpath
+    uimaCL = new UIMAClassLoader(classpath, parent);
+
+    if (resolveResource) {
+      // set UIMA extension ClassLoader also to resolve resources
+      getRelativePathResolver().setPathResolverClassLoader(uimaCL);
+    }
+  }
+
+  /**
+   * @see org.apache.uima.resource.ResourceManager#getExtensionClassLoader()
+   */
+  public ClassLoader getExtensionClassLoader() {
+    return uimaCL;
+  }
+
+  @Override
+  protected RelativePathResolver getRelativePathResolver() {
+    return mRelativePathResolver;
+  }
+
+}

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java Fri Nov 21 14:18:06 2008
@@ -57,35 +57,35 @@
   /**
    * resource bundle for log messages
    */
-  private static final String LOG_RESOURCE_BUNDLE = "org.apache.uima.impl.log_messages";
+  protected static final String LOG_RESOURCE_BUNDLE = "org.apache.uima.impl.log_messages";
 
   /**
    * Object used for resolving relative paths. This is built by parsing the data path.
    */
-  private RelativePathResolver mRelativePathResolver;
+  private final RelativePathResolver mRelativePathResolver;
 
   /**
    * Map from qualified key names (declared in resource dependency XML) to Resource objects.
    */
-  private Map mResourceMap = Collections.synchronizedMap(new HashMap());
+  protected Map mResourceMap = Collections.synchronizedMap(new HashMap());
 
   /**
    * Internal map from resource names (declared in resource declaration XML) to ResourceRegistration
    * objects. Used during initialization only.
    */
-  private Map mInternalResourceRegistrationMap = Collections.synchronizedMap(new HashMap());
+  protected Map mInternalResourceRegistrationMap = Collections.synchronizedMap(new HashMap());
 
   /**
    * Map from String keys to Class objects. For ParameterizedResources only, stores the
    * implementation class corresponding to each resource name.
    */
-  private Map mParameterizedResourceImplClassMap = Collections.synchronizedMap(new HashMap());
+  protected Map mParameterizedResourceImplClassMap = Collections.synchronizedMap(new HashMap());
 
   /**
    * Internal map from resource names (declared in resource declaration XML) to Class objects. Used
    * internally during resource initialization.
    */
-  private Map mInternalParameterizedResourceImplClassMap = Collections
+  protected Map mInternalParameterizedResourceImplClassMap = Collections
           .synchronizedMap(new HashMap());
 
   /**
@@ -93,7 +93,7 @@
    * ParameterizedResources only, stores the DataResources that have already been encountered, and
    * the Resources that have been instantiated therefrom.
    */
-  private Map mParameterizedResourceInstanceMap = Collections.synchronizedMap(new HashMap());
+  protected Map mParameterizedResourceInstanceMap = Collections.synchronizedMap(new HashMap());
 
   /**
    * UIMA extension ClassLoader. ClassLoader is created if an extension classpath is specified at
@@ -102,7 +102,7 @@
   private UIMAClassLoader uimaCL = null;
 
   /** CasManager - manages creation and pooling of CASes. */
-  private CasManager mCasManager = null;
+  protected CasManager mCasManager = null;
 
   /**
    * Cache of imported descriptors, so that parsed objects can be reused if the
@@ -127,7 +127,7 @@
 
     if (resolveResource) {
       // set UIMA extension ClassLoader also to resolve resources
-      mRelativePathResolver.setPathResolverClassLoader(uimaCL);
+      getRelativePathResolver().setPathResolverClassLoader(uimaCL);
     }
   }
 
@@ -142,7 +142,7 @@
 
     if (resolveResource) {
       // set UIMA extension ClassLoader also to resolve resources
-      mRelativePathResolver.setPathResolverClassLoader(uimaCL);
+      getRelativePathResolver().setPathResolverClassLoader(uimaCL);
     }
   }
 
@@ -165,14 +165,14 @@
    * @see org.apache.uima.resource.ResourceManager#getDataPath()
    */
   public String getDataPath() {
-    return mRelativePathResolver.getDataPath();
+    return getRelativePathResolver().getDataPath();
   }
 
   /**
    * @see org.apache.uima.resource.ResourceManager#setDataPath(String)
    */
   public void setDataPath(String aPath) throws MalformedURLException {
-    mRelativePathResolver.setDataPath(aPath);
+    getRelativePathResolver().setDataPath(aPath);
   }
 
   /*
@@ -187,7 +187,7 @@
     } catch (MalformedURLException e) {
       relativeUrl = new URL("file", "", aRelativePath);
     }
-    return mRelativePathResolver.resolveRelativePath(relativeUrl);
+    return getRelativePathResolver().resolveRelativePath(relativeUrl);
   }
 
   /**
@@ -354,7 +354,7 @@
       // {
       // relativeUrl = new URL("file","",aKey);
       // }
-      // return mRelativePathResolver.resolveRelativePath(relativeUrl);
+      // return getRelativePathResolver().resolveRelativePath(relativeUrl);
     }
     // }
     // catch(MalformedURLException e)
@@ -390,7 +390,7 @@
       // {
       // relativeUrl = new URL("file","",aKey);//keyNoContext);
       // }
-      // return mRelativePathResolver.resolveRelativePath(relativeUrl);
+      // return getRelativePathResolver().resolveRelativePath(relativeUrl);
     }
     // }
     // catch(MalformedURLException e)
@@ -476,7 +476,7 @@
         } catch (MalformedURLException e) {
           throw new ResourceInitializationException(e);
         }
-        URL absUrl = mRelativePathResolver.resolveRelativePath(relativeUrl);
+        URL absUrl = getRelativePathResolver().resolveRelativePath(relativeUrl);
         if (absUrl != null) {
           // found - create a DataResource object and store it in the mResourceMap
           FileResourceSpecifier spec = new FileResourceSpecifier_impl();
@@ -534,7 +534,7 @@
     // add the relative path resolver to the resource init. params
     Map initParams = (aResourceInitParams == null) ? new HashMap() : new HashMap(
             aResourceInitParams);
-    initParams.put(DataResource.PARAM_RELATIVE_PATH_RESOLVER, mRelativePathResolver);
+    initParams.put(DataResource.PARAM_RELATIVE_PATH_RESOLVER, getRelativePathResolver());
     
     // determine if verification mode is on.  If so, we don't want to load the resource data
     boolean verificationMode = initParams.containsKey(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE);
@@ -645,6 +645,11 @@
       }
     }
   }
+ 
+  // This method overridden by subclass for pear wrapper
+  protected RelativePathResolver getRelativePathResolver() {
+    return mRelativePathResolver;
+  }
 
   static class ResourceRegistration {
     Object resource;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/impl/factoryConfig.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/impl/factoryConfig.xml?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/impl/factoryConfig.xml (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/impl/factoryConfig.xml Fri Nov 21 14:18:06 2008
@@ -26,6 +26,7 @@
 	<cpm class="org.apache.uima.collection.impl.cpm.CPMImpl"/>
     <logger class="org.apache.uima.util.impl.JSR47Logger_impl"/>
 	<resourceManager class="org.apache.uima.resource.impl.ResourceManager_impl"/>
+  <resourceManagerPearWrapper class="org.apache.uima.resource.impl.ResourceManagerPearWrapper_impl"/>
 	<configurationManager class="org.apache.uima.resource.impl.ConfigurationManager_impl"/>
 	<uimaContext class="org.apache.uima.impl.RootUimaContext_impl"/>
 	<cpe class="org.apache.uima.collection.impl.CollectionProcessingEngine_impl"/>

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/PearRuntimeTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/PearRuntimeTest.java?rev=719734&r1=719733&r2=719734&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/PearRuntimeTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/PearRuntimeTest.java Fri Nov 21 14:18:06 2008
@@ -21,6 +21,9 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import junit.framework.Assert;
@@ -31,9 +34,11 @@
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
 import org.apache.uima.analysis_engine.metadata.FixedFlow;
+import org.apache.uima.analysis_engine.metadata.SofaMapping;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.pear.tools.PackageBrowser;
 import org.apache.uima.pear.tools.PackageInstaller;
+import org.apache.uima.resource.metadata.Capability;
 import org.apache.uima.resource.metadata.Import;
 import org.apache.uima.test.junit_extension.JUnitExtension;
 
@@ -69,12 +74,34 @@
     }
   }
 
+  public void testPearSofaMapping() throws Exception {
+    AnalysisEngineDescription desc = createAeDescriptionFromPears(new String[]{"pearTests/pearSofaMap.pear"});
+    Capability[] capabilities = new Capability[]{UIMAFramework.getResourceSpecifierFactory().createCapability()};
+    capabilities[0].setInputSofas(new String[] {"_InitialView"});
+    capabilities[0].setOutputSofas(new String[] {"GermanDocument"});
+    desc.getAnalysisEngineMetaData().setCapabilities(capabilities);
+    SofaMapping[] sofaMappings = new SofaMapping[] 
+      {UIMAFramework.getResourceSpecifierFactory().createSofaMapping(),
+       UIMAFramework.getResourceSpecifierFactory().createSofaMapping()};
+//    <componentKey>ProjectForPear_pear</componentKey>
+//    <componentSofaName>EnglishDocument</componentSofaName>
+//    <aggregateSofaName>_InitialView</aggregateSofaName>
+  
+    sofaMappings[0].setComponentKey("Pear0");
+    sofaMappings[1].setComponentKey("Pear0");
+    sofaMappings[0].setComponentSofaName("EnglishDocument");
+    sofaMappings[1].setComponentSofaName("GermanDocument");
+    sofaMappings[0].setAggregateSofaName("_InitialView");
+    sofaMappings[1].setAggregateSofaName("GermanDocument");
+    desc.setSofaMappings(sofaMappings);
+    CAS cas = runDesc(desc);
+  }
   /**
    * @throws Exception
    */
   public void testPearRuntime() throws Exception {
 
-    CAS cas = this.runPearRuntimeTestcase("pearTests/DateTime.pear", "pearTests/RoomNumber.pear");
+    CAS cas = this.runPearRuntimeTestcase(new String[]{"pearTests/DateTime.pear", "pearTests/RoomNumber.pear"});
     
     //check if 3 annotations are available in the CAS index
     // The 3 annotations are the doc annotation, plus 2 room numbers
@@ -93,71 +120,69 @@
 
   public void testPearRuntimeDocAnnot() throws Exception {
 
-    CAS cas = this.runPearRuntimeTestcase("pearTests/analysisEngine.pear", "pearTests/analysisEngine2.pear");
+    CAS cas = this.runPearRuntimeTestcase(new String[]{"pearTests/analysisEngine.pear", "pearTests/analysisEngine2.pear"});
 
     //check if 3 annotations are available in the CAS index
     Assert.assertEquals(cas.getAnnotationIndex().size(), 3);
    }
 
+  private Import [] installPears(String [] pears) throws IOException {
+    List<Import> result = new ArrayList<Import>();
+    for (String s : pears) {
+      result.add(installPear(s));
+    }
+    return result.toArray(new Import[result.size()]);
+  }
   
-  /**
-   * @throws Exception
-   */
-  private CAS runPearRuntimeTestcase(String pear1, String pear2) throws Exception {
-
+  private Import installPear(String pear) throws IOException {
     // check temporary working directory
     if (this.tempInstallDir == null)
       throw new FileNotFoundException("temp directory not found");
     // check sample PEAR files
 
     // get pear files to install
-    File pearFile1 = JUnitExtension.getFile(pear1);
-    Assert.assertNotNull(pearFile1);
-
-    File pearFile2 = JUnitExtension.getFile(pear2);
-    Assert.assertNotNull(pearFile2);
+    File pearFile = JUnitExtension.getFile(pear);
+    Assert.assertNotNull(pearFile);
 
     // Install PEAR packages
-    PackageBrowser instPear1 = PackageInstaller
-            .installPackage(this.tempInstallDir, pearFile1, true);
+    PackageBrowser instPear = PackageInstaller
+            .installPackage(this.tempInstallDir, pearFile, true);
 
     // check pear PackageBrowser object
-    Assert.assertNotNull(instPear1);
-
-    PackageBrowser instPear2 = PackageInstaller
-            .installPackage(this.tempInstallDir, pearFile2, true);
+    Assert.assertNotNull(instPear); 
+ 
+    // import pear specifiers
+    Import impPear = UIMAFramework.getResourceSpecifierFactory().createImport();
+    File import1 = new File(instPear.getComponentPearDescPath());
+    impPear.setLocation(import1.toURI().getPath());
 
-    // check pear PackageBrowser object
-    Assert.assertNotNull(instPear2);
+    return impPear;
+  }
+  
+  private AnalysisEngineDescription createAeDescriptionFromPears(String[] pears) throws Exception {
+    Import[] impPears = installPears(pears);
 
     // create aggregate analysis engine descriptor
     AnalysisEngineDescription desc = UIMAFramework.getResourceSpecifierFactory()
             .createAnalysisEngineDescription();
     desc.setPrimitive(false);
 
-    // import pear specifiers
-    Import impPear1 = UIMAFramework.getResourceSpecifierFactory().createImport();
-    File import1 = new File(instPear1.getComponentPearDescPath());
-    impPear1.setLocation(import1.toURI().getPath());
-
-    // import main pear descriptor
-    Import impPear2 = UIMAFramework.getResourceSpecifierFactory().createImport();
-    File import2 = new File(instPear2.getComponentPearDescPath());
-    impPear2.setLocation(import2.toURI().getPath());
-
     // add delegates as imports
     Map delegates = desc.getDelegateAnalysisEngineSpecifiersWithImports();
-    delegates.put("Pear1", impPear1);
-    delegates.put("Pear2", impPear2);
+    String [] keys = new String[impPears.length];
+    for (int i = 0; i < impPears.length; i++) {
+      keys[i] = "Pear" + i;
+      delegates.put(keys[i], impPears[i]);
+    }
 
     // add sequence - fixed flow
     FixedFlow fixedFlow = UIMAFramework.getResourceSpecifierFactory().createFixedFlow();
-    fixedFlow.setFixedFlow(new String[] { "Pear1", "Pear2" });
+    fixedFlow.setFixedFlow(keys);
 
     // add analysis engine meta data
     AnalysisEngineMetaData md = desc.getAnalysisEngineMetaData();
     md.setName("PEAR aggregate");
-    md.setDescription("combines tow PEARs");
+    md.setDescription("combines one or more PEARs");
     md.setVersion("1.0");
     md.setFlowConstraints(fixedFlow);
 
@@ -168,8 +193,11 @@
 //    OutputStreamWriter(outStream, OutputFormat.Defaults.Encoding); XMLSerializer xmlSerializer =
 //    new XMLSerializer(); xmlSerializer.setWriter(writer);
 //    desc.toXML(xmlSerializer.getContentHandler(), true); writer.close();
-    
+    return desc;
 
+  }
+  
+  private CAS runDesc(AnalysisEngineDescription desc) throws Exception {
     // Create analysis engine from aggregate ae description
     AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, null, null);
     Assert.assertNotNull(ae);
@@ -182,4 +210,13 @@
     
     return cas;
   }
+  
+  /**
+   * @throws Exception
+   */
+  private CAS runPearRuntimeTestcase(String[] pears) throws Exception {
+    
+    AnalysisEngineDescription desc = createAeDescriptionFromPears(pears);    
+    return runDesc(desc);
+  }
 }

Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/pearTests/pearSofaMap.pear
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/pearTests/pearSofaMap.pear?rev=719734&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/pearTests/pearSofaMap.pear
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream