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 2007/01/17 19:47:50 UTC

svn commit: r497124 - in /incubator/uima/uimaj/trunk/uimaj-tools/src/main: java/org/apache/uima/tools/jcasgen/Jg.java resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties

Author: schor
Date: Wed Jan 17 10:47:49 2007
New Revision: 497124

URL: http://svn.apache.org/viewvc?view=rev&rev=497124
Log:
UIMA-177

Modified:
    incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
    incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties

Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java?view=diff&rev=497124&r1=497123&r2=497124
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java Wed Jan 17 10:47:49 2007
@@ -42,6 +42,7 @@
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 import javax.swing.UIManager;
@@ -264,6 +265,8 @@
   private Type casStringType;
 
   private Type tcasAnnotationType;
+  
+  private Map mergedTypesAddingFeatures = new TreeMap();  // a Map of types and the xml files that were merged to create them 
 
   public Jg() { // default constructor
   }
@@ -413,11 +416,12 @@
           XMLInputSource in = new XMLInputSource(file);
           XMLizable specifier = UIMAFramework.getXMLParser().parse(in);
 
+          mergedTypesAddingFeatures.clear();
           if (specifier instanceof AnalysisEngineDescription) {
             AnalysisEngineDescription aeSpecifier = (AnalysisEngineDescription) specifier;
             if (!aeSpecifier.isPrimitive())
               typeSystemDescription = CasCreationUtils.mergeDelegateAnalysisEngineTypeSystems(
-                      aeSpecifier, createResourceManager());
+                      aeSpecifier, createResourceManager(), mergedTypesAddingFeatures);
             else
               typeSystemDescription = mergeTypeSystemImports(aeSpecifier
                       .getAnalysisEngineMetaData().getTypeSystem());
@@ -428,6 +432,14 @@
             error.newError(IError.ERROR, getString("fileDoesntParse", new Object[] { inputFile }),
                     null);
           }
+          if (mergedTypesAddingFeatures.size() > 0) {
+            error.newError(
+                    IError.WARN, 
+                    getString("typesHaveFeaturesAdded",
+                            new Object[] {makeMergeMessage(mergedTypesAddingFeatures)}),
+                    null
+                    );
+          }
           TypePriorities typePriorities = null;
           FsIndexDescription[] fsIndexDescription = null;
           try {
@@ -465,6 +477,29 @@
     }
   }
 
+  // message: TypeName = ".....", URLs defining this type = "xxxx", "xxxx", ....
+  private String makeMergeMessage(Map m) {
+    StringBuffer sb = new StringBuffer();  
+    for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
+      Map.Entry entry = (Map.Entry)it.next();
+      String typeName =(String)entry.getKey();
+      sb.append("\n  ");
+      sb.append("TypeName having merged features = ").append(typeName).append("\n    URLs defining this type =");
+      Set urls = (Set)entry.getValue();
+      boolean afterFirst = false;
+      for (Iterator itUrls = urls.iterator(); itUrls.hasNext();) {
+        if (afterFirst)
+          sb.append(",\n        ");
+        else
+          sb.append("\n        ");
+        afterFirst = true;
+        String url = (String) itUrls.next();
+        sb.append('"').append(url).append('"');
+      }
+    }
+    return sb.toString();
+  }
+  
   // This is also the interface for CDE
   void generateAllTypes(String outputDirectory, TypeDescription[] tds, CASImpl aCas)
           throws IOException {
@@ -523,7 +558,7 @@
     }
     */
   }
-
+  /* This code was only called by above commented out section 
   private TypeDescription createTdFromType(String typeName) {
     TypeDescription td = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
     Type type = builtInTypeSystem.getType(typeName);
@@ -546,7 +581,8 @@
             .toArray(new FeatureDescription[featuresOfType.size()]));
     return td;
   }
-
+  */
+  
   private void generateClasses(TypeDescription td, String outputDirectory) throws IOException {
     simpleClassName = removePkg(getJavaName(td));
     generateClass(progressMonitor, outputDirectory, td, (new JCasTypeTemplate())
@@ -895,12 +931,13 @@
     return resourceManager;
   }
 
-  public TypeSystemDescription mergeTypeSystemImports(TypeSystemDescription tsd)
+  private TypeSystemDescription mergeTypeSystemImports(TypeSystemDescription tsd)
           throws ResourceInitializationException {
     Collection tsdc = new ArrayList(1);
     tsdc.add(tsd.clone());
+    mergedTypesAddingFeatures.clear();
     TypeSystemDescription mergedTsd = CasCreationUtils.mergeTypeSystems(tsdc,
-            createResourceManager());
+            createResourceManager(), mergedTypesAddingFeatures);
     return mergedTsd;
   }
 

Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties?view=diff&rev=497124&r1=497123&r2=497124
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties Wed Jan 17 10:47:49 2007
@@ -28,6 +28,7 @@
 creatingTarget = Creating: ''{0}''.
 missingArguments = Argument(s) missing - Requires at least 1 argument - the xml source.
 fileDoesntParse = File ''{0}'' doesn''t have an AnalysisEngine Descriptor or a TypeSystem Descriptor, which are the required kinds of input.
+typesHaveFeaturesAdded = Warning: the following types were generated by merging different type descriptors, where the resulting number of features is larger than that of the components. Although the resulting generated JCas classes are correct, doing this kind of merging makes reuse of this component more difficult.{0}
 reservedNameUsed = The feature name ''{0}'', specified in Type ''{1}'' is reserved. Please choose another name.
 invalidXML = Invalid XML found in input file ''{0}''.
 resourceInitializationException = ****** Resource Initialization Error occurred while instantiating the CAS type system. Continuing, but may generate incorrectly.  Caused by {0}.******