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/07/06 16:17:01 UTC

svn commit: r553888 - in /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl: CASImpl.java CASMgrSerializer.java TypeSystemImpl.java

Author: schor
Date: Fri Jul  6 07:17:00 2007
New Revision: 553888

URL: http://svn.apache.org/viewvc?view=rev&rev=553888
Log:
[UIMA-476] have the CAS Mgr Serializer handle deserializing 
types whose names look like xxxx[] as arrays.

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?view=diff&rev=553888&r1=553887&r2=553888
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Fri Jul  6 07:17:00 2007
@@ -2004,7 +2004,27 @@
       return;
     }
     ts.areBuiltInTypesSetup = true;
+    		
+		// W A R N I N G  (July 2007) 
+		
+    // C++ code has "hard-wired" the type code numbers for the 
+		//   built-in types, so you cannot change the order of the types
+    // Also, the complete serialization depends on the type-code numbers
+    //   for the client and the server for the built-in types being
+    //   the same.
     
+    // The initialization code for types cannot depend on the type system
+    //  having already been set up, because, obviously, it isn't set up (yet).
+
+    // It is important to add types in a particular order and to set
+		//   ts.xxx<type-name> and ts.xxx<type-name>code values so they are
+		//     set before they're used.  Some of the add-type logic is written
+		//     to depend on the built-in types already having these values set.
+		//     For example:  addType ( ARRAY_BASE ) calls, eventually, 
+		//        ts.ll_isPrimitiveType -> ll_isRefType ->ll_getTypeClass -> ll_subsumes
+		//        and along the way these are testing / comparing against type codes
+		//        for built-in types which need to have been set.
+		
 		// Create top type.
 		Type top = ts.addTopType(CAS.TYPE_NAME_TOP);
 		// Add basic data types.
@@ -2013,7 +2033,11 @@
 		Type stringT = ts.addType(CAS.TYPE_NAME_STRING, top);
 		// Add arrays.
 		Type array = ts.addType(CAS.TYPE_NAME_ARRAY_BASE, top);
+		ts.arrayBaseType = (TypeImpl)array;         // do here - used in next
+		ts.arrayBaseTypeCode = ts.arrayBaseType.getCode();
 		TypeImpl fsArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_FS_ARRAY, array);
+		ts.fsArrayType = fsArray;                   // do here - used in next 
+		ts.fsArrayTypeCode = fsArray.getCode();
 		TypeImpl floatArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_FLOAT_ARRAY, array);
 		TypeImpl intArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_INTEGER_ARRAY, array);
 		TypeImpl stringArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_STRING_ARRAY, array);
@@ -2050,6 +2074,7 @@
 		Type longT = ts.addType(CAS.TYPE_NAME_LONG, top);
 		Type doubleT = ts.addType(CAS.TYPE_NAME_DOUBLE, top);
 
+		// array type initialization must follow the component type it's based on
 		TypeImpl booleanArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_BOOLEAN_ARRAY, array);
 		TypeImpl byteArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_BYTE_ARRAY, array);
 		TypeImpl shortArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_SHORT_ARRAY, array);

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java?view=diff&rev=553888&r1=553887&r2=553888
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java Fri Jul  6 07:17:00 2007
@@ -406,47 +406,49 @@
 //    ts.addTopType(CAS.TYPE_NAME_TOP);  // does nothing, top type already there
     // HashMap nameMap = null;
     // Temporary. The name map will go away completely.
-    HashMap nameMap = new HashMap();
+//    HashMap nameMap = new HashMap();
     // if (source == SOURCE_TAF) {
     // nameMap = cas.mapTafTypesToCASTypes();
     // }
     String name;
-    int parent;
+//    int parent;
     // Now add all the other types.
-    if (this.source == SOURCE_TAF) {
-      for (int i = 2; i < this.typeNames.length; i++) {
-        parent = this.typeInheritance[i];
-        name = CASImpl.mapName(this.typeNames[i], nameMap);
-        // Check if the type we're adding is a subtype of string, in
-        // which case
-        // we need to call a different type system api.
-        int pos = isStringSubtype(i);
-        if (pos >= 0) {
-          ts.addStringSubtype(name, getStringArray(pos));
-        } else {
-          ts.addType(name, parent);
-        }
-      }
-    } else {
+//    if (this.source == SOURCE_TAF) {
+//      for (int i = 2; i < this.typeNames.length; i++) {
+//        parent = this.typeInheritance[i];
+//        name = CASImpl.mapName(this.typeNames[i], nameMap);
+//        // Check if the type we're adding is a subtype of string, in
+//        // which case
+//        // we need to call a different type system api.
+//        int pos = isStringSubtype(i);
+//        if (pos >= 0) {
+//          ts.addStringSubtype(name, getStringArray(pos));
+//        } else {
+//          ts.addType(name, parent);
+//        }
+//      }
+//    } else {
       for (int i = 2; i < this.typeNames.length; i++) {
         name = this.typeNames[i];
         int pos = isStringSubtype(i);
         if (pos >= 0) {
           ts.addStringSubtype(name, getStringArray(pos));
+        } else if (TypeSystemImpl.isArrayTypeNameButNotBuiltIn(name)) {
+        	  ts.getArrayType(ts.getType(TypeSystemImpl.getArrayComponentName(name)));
         } else {
-          ts.addType(name, this.typeInheritance[i]);
+            ts.addType(name, this.typeInheritance[i]);
         }
       }
-    }
+//    }
 
     // Add feature declarations.
     final int max = this.featureNames.length;
     for (int i = 1; i < max; i++) {
-      if (this.source == SOURCE_TAF) {
-        name = CASImpl.mapName(this.featureNames[i], nameMap);
-      } else {
+//      if (this.source == SOURCE_TAF) {
+//        name = CASImpl.mapName(this.featureNames[i], nameMap);
+//      } else {
         name = this.featureNames[i];
-      }
+//      }
       ts.addFeature(name, this.featDecls[i * 2], this.featDecls[(i * 2) + 1]);
     }
     return ts;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java?view=diff&rev=553888&r1=553887&r2=553888
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Fri Jul  6 07:17:00 2007
@@ -470,12 +470,12 @@
     // note: not using this.top - until we can confirm this is set
         // in all cases
         (ll_getTypeForCode(componentType).getName().equals(CAS.TYPE_NAME_TOP))) {
-      return ll_getCodeForTypeName(CAS.TYPE_NAME_ARRAY_BASE);
+      return this.arrayBaseTypeCode;
     }
     // is a subtype of FSArray.
     // note: not using this.fsArray - until we can confirm this is set in
     // all cases
-    return ll_getCodeForTypeName(CAS.TYPE_NAME_FS_ARRAY);
+    return this.fsArrayTypeCode;
     // return ll_getArrayType(ll_getParentType(componentType));
   }
 
@@ -547,6 +547,14 @@
     // }
     // return typeName + arrayTypeSuffix;
   }
+  
+  static final String getArrayComponentName(String arrayTypeName) {
+  	return arrayTypeName.substring(0, arrayTypeName.length() - 2);
+  }
+  
+  static boolean isArrayTypeNameButNotBuiltIn(String typeName) {
+  	return typeName.endsWith(arrayTypeSuffix);
+  }
 
   private static final String getBuiltinArrayComponent(String typeName) {
     // if typeName is not contained in the map, the "get" returns null
@@ -1277,7 +1285,10 @@
     if (typeCode == this.doubleTypeCode) {
       return LowLevelCAS.TYPE_CLASS_DOUBLE;
     }
-    if (ll_subsumes(this.stringTypeCode, typeCode)) {
+    // false if string type code not yet set up (during initialization)
+    //   need this to avoid NPE in subsumes
+    if ((this.stringTypeCode != LowLevelTypeSystem.UNKNOWN_TYPE_CODE) &&
+          ll_subsumes(this.stringTypeCode, typeCode)) {
       return LowLevelCAS.TYPE_CLASS_STRING;
     }
     if (typeCode == this.booleanArrayTypeCode) {
@@ -1345,8 +1356,8 @@
     // to the inheritance tree. This sucks. Assumptions about the base
     // array are all over the place. Would be nice to just remove it.
     // Add an edge to the tree.
-    if (!isCommitted()) {
-      final int arrayBaseTypeCodeBeforeCommitted = ll_getCodeForTypeName(CAS.TYPE_NAME_ARRAY_BASE);
+    if (!isCommitted() && motherCode != fsArrayTypeCode ) {
+      final int arrayBaseTypeCodeBeforeCommitted = this.arrayBaseTypeCode;
       ((IntVector) this.tree.get(arrayBaseTypeCodeBeforeCommitted)).add(arrayTypeCode);
       // Update subsumption relation.
       updateSubsumption(arrayTypeCode, this.arrayBaseTypeCode);