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 2014/08/12 23:27:15 UTC

svn commit: r1617593 [1/3] - in /uima/uimaj/trunk/uimaj-core: ./ src/main/java/ src/main/java/org/apache/uima/cas/impl/ src/main/java/org/apache/uima/resource/metadata/impl/ src/main/java/org/apache/uima/util/ src/test/java/org/apache/uima/analysis_eng...

Author: schor
Date: Tue Aug 12 21:27:14 2014
New Revision: 1617593

URL: http://svn.apache.org/r1617593
Log:
[UIMA-3969] merge from branch/2.6.0-json back into trunk

Added:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/JsonContentHandlerJacksonWrapper.java
      - copied unchanged from r1617592, uima/uimaj/branches/2.6.0-json/uimaj-core/src/main/java/org/apache/uima/util/JsonContentHandlerJacksonWrapper.java
Modified:
    uima/uimaj/trunk/uimaj-core/   (props changed)
    uima/uimaj/trunk/uimaj-core/pom.xml
    uima/uimaj/trunk/uimaj-core/src/main/java/   (props changed)
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ListUtils.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLizable.java
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngineDescription_implTest.java
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java

Propchange: uima/uimaj/trunk/uimaj-core/
------------------------------------------------------------------------------
  Merged /uima/uimaj/branches/2.6.0-json/uimaj-core:r1616936-1617592

Modified: uima/uimaj/trunk/uimaj-core/pom.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/pom.xml?rev=1617593&r1=1617592&r2=1617593&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/pom.xml (original)
+++ uima/uimaj/trunk/uimaj-core/pom.xml Tue Aug 12 21:27:14 2014
@@ -73,6 +73,12 @@
 			<scope>test</scope>
 		</dependency>
 		
+		<dependency>
+			<groupId>com.fasterxml.jackson.core</groupId>
+	    <artifactId>jackson-core</artifactId>
+	    <version>2.4.1.1</version>
+		</dependency>
+		
 		<!-- This next dependency is used to enable findbug rule suppression annotations
 		     Currently commented out - till more thought given to this. 
 		     For instance, we don't want to accidentally distribute this dependency in builds

Propchange: uima/uimaj/trunk/uimaj-core/src/main/java/
------------------------------------------------------------------------------
  Merged /uima/uimaj/branches/2.6.0-json/uimaj-core/src/main/java:r1616936-1617592

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ListUtils.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ListUtils.java?rev=1617593&r1=1617592&r2=1617593&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ListUtils.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ListUtils.java Tue Aug 12 21:27:14 2014
@@ -86,6 +86,8 @@ public class ListUtils {
 
   private ErrorHandler eh;
 
+  private boolean foundCycle;
+
   /**
    * Creates a new ListUtils object.
    * 
@@ -145,23 +147,27 @@ public class ListUtils {
   }
 
   public int getLength(int type, int addr) {
-	int neListType = -1;
-	int tailFeat = -1;
-	if (isIntListType(type)) {
-	  neListType = neIntListType;
-	  tailFeat = intTailFeat;
-	} else if ( isFloatListType(type)) {
-	  neListType = neFloatListType;
-	  tailFeat = floatTailFeat;
-	} else if (isStringListType(type)) {
-      neListType = neStringListType;
-	  tailFeat = stringTailFeat;
-	} else if (isFsListType(type)) {
-	  neListType = neFsListType;
-	  tailFeat = fsTailFeat;
-	}
+    int neListType = -1;
+    int tailFeat = -1;
+    if (isIntListType(type)) {
+      neListType = neIntListType;
+      tailFeat = intTailFeat;
+    } else if ( isFloatListType(type)) {
+      neListType = neFloatListType;
+      tailFeat = floatTailFeat;
+    } else if (isStringListType(type)) {
+        neListType = neStringListType;
+      tailFeat = stringTailFeat;
+    } else if (isFsListType(type)) {
+      neListType = neFsListType;
+      tailFeat = fsTailFeat;
+    }
+    return getLength(type, addr, neListType, tailFeat);    
+  }
+  
+  public int getLength(int type, int addr, int neListType, int tailFeat) {
 	IntRedBlackTree visited = new IntRedBlackTree();
-	boolean foundCycle = false;
+	foundCycle = false;
 	// first count length of list so we can allocate array
 	int length = 0;
 	int curNode = addr;
@@ -175,171 +181,88 @@ public class ListUtils {
 	}
 	return length;
   }
-  
-  public String[] intListToStringArray(int addr) throws SAXException {
-    IntRedBlackTree visited = new IntRedBlackTree();
-    boolean foundCycle = false;
-    // first count length of list so we can allocate array
-    int length = 0;
-    int curNode = addr;
-    while (cas.getHeapValue(curNode) == neIntListType) {
-      if (!visited.put(curNode, curNode)) {
-        foundCycle = true;
-        break;
-      }
-      length++;
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(intTailFeat));
-    }
-
-    String[] array = new String[length];
-
-    // now populate list
-    curNode = addr;
-    for (int i = 0; i < length; i++) {
-      array[i] = Integer.toString(cas.getHeapValue(curNode + cas.getFeatureOffset(intHeadFeat)));
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(intTailFeat));
-    }
-    if (foundCycle) {
-      reportWarning("Found a cycle in an IntegerList.  List truncated to "
-              + Arrays.asList(array).toString());
-    }
-    return array;
-  }
-
-  public String[] floatListToStringArray(int addr) throws SAXException {
-    boolean foundCycle = false;
-    IntRedBlackTree visited = new IntRedBlackTree();
-    // first count length of list so we can allocate array
-    int length = 0;
-    int curNode = addr;
-    while (cas.getHeapValue(curNode) == neFloatListType) {
-      if (!visited.put(curNode, curNode)) {
-        foundCycle = true;
-        break;
-      }
-      length++;
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(floatTailFeat));
-    }
-
-    String[] array = new String[length];
-
-    // now populate list
-    curNode = addr;
-    for (int i = 0; i < length; i++) {
-      array[i] = Float.toString(CASImpl.int2float(cas.getHeapValue(curNode
-              + cas.getFeatureOffset(floatHeadFeat))));
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(floatTailFeat));
-    }
-    if (foundCycle) {
-      reportWarning("Found a cycle in a FloatList.  List truncated to "
-              + Arrays.asList(array).toString() + ".");
+ 
+  public String[] anyListToStringArray(int curNode, XmiSerializationSharedData sharedData) throws SAXException {
+    final int type = cas.getHeapValue(curNode);
+    int headFeat = -1, tailFeat = -1, neListType = -1;
+    
+    if (isIntListType(type)) {
+      neListType = neIntListType;
+      headFeat = intHeadFeat;
+      tailFeat = intTailFeat;
+    } else if ( isFloatListType(type)) {
+      neListType = neFloatListType;
+      headFeat = floatHeadFeat;
+      tailFeat = floatTailFeat;
+    } else if (isStringListType(type)) {
+      neListType = neStringListType;
+      headFeat = stringHeadFeat;
+      tailFeat = stringTailFeat;
+    } else if (isFsListType(type)) {
+      neListType = neFsListType;
+      headFeat = fsHeadFeat;
+      tailFeat = fsTailFeat;
     }
-    return array;
-  }
 
-  public String[] stringListToStringArray(int addr) throws SAXException {
-    boolean foundCycle = false;
-    IntRedBlackTree visited = new IntRedBlackTree();
-    // first count length of list so we can allocate array
-    int length = 0;
-    int curNode = addr;
-    while (cas.getHeapValue(curNode) == neStringListType) {
-      if (!visited.put(curNode, curNode)) {
-        foundCycle = true;
-        break;
-      }
-      length++;
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(stringTailFeat));
-    }
 
+    int length = getLength(type, curNode, neListType, tailFeat);
     String[] array = new String[length];
 
     // now populate list
-    curNode = addr;
+//    curNode = addr;
     for (int i = 0; i < length; i++) {
-      array[i] = cas.getStringForCode(cas.getHeapValue(curNode
-              + cas.getFeatureOffset(stringHeadFeat)));
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(stringTailFeat));
-    }
-    if (foundCycle) {
-      reportWarning("Found a cycle in a StringList.  List truncated to "
-              + Arrays.asList(array).toString() + ".");
-    }
-    return array;
-  }
-
-  public String[] fsListToXmiIdStringArray(int addr, XmiSerializationSharedData sharedData)
-          throws SAXException {
-    boolean foundCycle = false;
-    IntRedBlackTree visited = new IntRedBlackTree();
-    // first count length of list so we can allocate array
-    int length = 0;
-    int curNode = addr;
-    while (cas.getHeapValue(curNode) == neFsListType) {
-      if (!visited.put(curNode, curNode)) {
-        foundCycle = true;
-        break;
-      }
-      length++;
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
-    }
-
-    String[] strArray = new String[length];
-
-    // now populate list
-    curNode = addr;
-    for (int i = 0; i < length; i++) {
-      int heapVal = cas.getHeapValue(curNode + cas.getFeatureOffset(fsHeadFeat));
-      if (heapVal == 0) {
-        //null value in list.  Represent with "0".
-        strArray[i] = "0";
-        // However, this may be null because the element was originally a reference to an 
-        // out-of-typesystem FS, so chck the XmiSerializationSharedData
-        if (sharedData != null) {
-          OotsElementData oed = sharedData.getOutOfTypeSystemFeatures(curNode);
-          if (oed != null) {
-            assert oed.attributes.size() == 1; //only the head feature can possibly be here
-            XmlAttribute attr = (XmlAttribute)oed.attributes.get(0);
-            assert CAS.FEATURE_BASE_NAME_HEAD.equals(attr.name);
-            strArray[i] = attr.value;
+      final int val = cas.getHeapValue(curNode + cas.getFeatureOffset(headFeat));
+      
+      if (neListType == neIntListType) {
+        array[i] = Integer.toString(val);
+      } else if (neListType == neFloatListType) {
+        array[i] = Float.toString(val);
+      } else if (neListType == neStringListType) {
+        array[i] = cas.getStringForCode(val);
+      } else if (neListType == neFsListType) {
+        if (val == 0) {
+          //null value in list.  Represent with "0".
+          array[i] = "0";
+          // However, this may be null because the element was originally a reference to an 
+          // out-of-typesystem FS, so chck the XmiSerializationSharedData
+          if (sharedData != null) {
+            OotsElementData oed = sharedData.getOutOfTypeSystemFeatures(curNode);
+            if (oed != null) {
+              assert oed.attributes.size() == 1; //only the head feature can possibly be here
+              XmlAttribute attr = (XmlAttribute)oed.attributes.get(0);
+              assert CAS.FEATURE_BASE_NAME_HEAD.equals(attr.name);
+              array[i] = attr.value;
+            }
+          }        
+        }
+        else {
+          if (sharedData != null) {
+            array[i] = (val == 0) ? "0" : sharedData.getXmiId(val);  // changed from null 8/2014 mis
+          } else {
+            array[i] = Integer.toString(val);
           }
-        }        
-      }
-      else {
-        if (sharedData != null) {
-          strArray[i] = heapVal == 0 ? null : sharedData.getXmiId(heapVal);
-        } else {
-          strArray[i] = Integer.toString(heapVal);
         }
       }
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
+      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(intTailFeat));
     }
     if (foundCycle) {
-      reportWarning("Found a cycle in an FSList.  List truncated to "
-              + Arrays.asList(strArray).toString() + ".");
+      reportWarning("Found a cycle in an IntegerList.  List truncated to "
+              + Arrays.asList(array).toString());
     }
-    return strArray;
+    return array;
   }
 
-  public int[] fsListToAddressArray(int addr) throws SAXException {
-    boolean foundCycle = false;
-    IntRedBlackTree visited = new IntRedBlackTree();
-    // first count length of list so we can allocate array
-    int length = 0;
-    int curNode = addr;
-    while (cas.getHeapValue(curNode) == neFsListType) {
-      if (!visited.put(curNode, curNode)) {
-        foundCycle = true;
-        break;
-      }
-      length++;
-      curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
-    }
-
+  public int[] fsListToAddressArray(int curNode) throws SAXException {
+    final int type = cas.getHeapValue(curNode);
+    int headFeat = fsHeadFeat;
+    int tailFeat = fsTailFeat;
+    int neListType = neFsListType;
+    
+    int length = getLength(type, curNode, neListType, tailFeat);
+    
     int[] array = new int[length];
 
     // now populate list
-    curNode = addr;
     for (int i = 0; i < length; i++) {
       array[i] = cas.getHeapValue(curNode + cas.getFeatureOffset(fsHeadFeat));
       curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));