You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2006/12/18 18:03:00 UTC

svn commit: r488340 - in /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima: cas/impl/ util/

Author: twgoetz
Date: Mon Dec 18 09:02:59 2006
New Revision: 488340

URL: http://svn.apache.org/viewvc?view=rev&rev=488340
Log:
Jira UIMA-128: string subtype values not checked on feature assignment.

https://issues.apache.org/jira/browse/UIMA-128

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/FeatureStructureImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelTypeSystem.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringTypeImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystem2Xml.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.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=488340&r1=488339&r2=488340
==============================================================================
--- 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 Mon Dec 18 09:02:59 2006
@@ -2908,8 +2908,20 @@
   }
 
   public final void ll_setStringValue(int fsRef, int featureCode, String value) {
+    String[] stringSet = this.ts.ll_getStringSet(this.ts.ll_getRangeType(featureCode));
+    if (stringSet != null) {
+      final int rc = Arrays.binarySearch(stringSet, value);
+      if (rc < 0) {
+        // Not a legal value.
+        CASRuntimeException e = new CASRuntimeException(CASRuntimeException.ILLEGAL_STRING_VALUE);
+        e.addArgument(value);
+        e.addArgument(this.ts.ll_getTypeForCode(this.ts.ll_getRangeType(featureCode)).getName());
+        throw e;
+      }
+    }
     final int stringAddr = (value == null) ? NULL : this.stringHeap.addString(value);
-    this.heap.heap[fsRef + this.featureOffset[featureCode]] = stringAddr;
+    final int valueAddr = fsRef + this.featureOffset[featureCode]; 
+    this.heap.heap[valueAddr] = stringAddr;
   }
 
   public final void ll_setRefValue(int fsRef, int featureCode, int value) {

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=488340&r1=488339&r2=488340
==============================================================================
--- 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 Mon Dec 18 09:02:59 2006
@@ -310,7 +310,7 @@
       typeCode = type.getCode();
       this.stringSubtypes[i] = typeCode;
       this.stringSubtypeValuePos[i] = pos;
-      stringSet = ts.getStringSet(type.getStringSet());
+      stringSet = ts.ll_getStringSet(typeCode);
       pos += stringSet.length;
       for (int j = 0; j < stringSet.length; j++) {
         strVals.add(stringSet[j]);

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImpl.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImpl.java Mon Dec 18 09:02:59 2006
@@ -134,8 +134,9 @@
     }
     // Check if we're dealing with a subtype of String.
     if (stringType != rangeType) {
-      final int stringSetCode = ((StringTypeImpl) ts.getType(rangeType)).getStringSet();
-      final String[] stringSet = ts.getStringSet(stringSetCode);
+      // We know that we're dealing with a proper subtype of string, so the resulting String[] is
+      // not null.
+      final String[] stringSet = ts.ll_getStringSet(rangeType);
       if (Arrays.binarySearch(stringSet, val) < 0) {
         // Not a legal value.
         CASRuntimeException e = new CASRuntimeException(CASRuntimeException.ILLEGAL_STRING_VALUE);

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java Mon Dec 18 09:02:59 2006
@@ -744,7 +744,6 @@
 
   double ll_getDoubleValue(int fsRef, int featureCode);
 
-  /** for jcas / featurepath * */
   byte ll_getByteValue(int fsRef, int featureCode, boolean doTypeChecks);
 
   boolean ll_getBooleanValue(int fsRef, int featureCode, boolean doTypeChecks);

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelTypeSystem.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelTypeSystem.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelTypeSystem.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelTypeSystem.java Mon Dec 18 09:02:59 2006
@@ -240,4 +240,12 @@
    * @return The type code of the parent type.
    */
   int ll_getParentType(int typeCode);
+  
+  /**
+   * Get the string set (sorted) for a string subtype.
+   * @param typeCode Input type code; should be a string subtype.
+   * @return The set of allowable string values for subtypes of uima.cas.String.  If the input type
+   * code is not a proper subtype of String, returns <code>null</code>. 
+   */
+  String[] ll_getStringSet(int typeCode);
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringTypeImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringTypeImpl.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringTypeImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringTypeImpl.java Mon Dec 18 09:02:59 2006
@@ -26,8 +26,6 @@
  */
 public class StringTypeImpl extends TypeImpl {
 
-  private final int stringSet;
-
   /**
    * Constructor for StringTypeImpl.
    * 
@@ -35,14 +33,8 @@
    * @param code
    * @param ts
    */
-  public StringTypeImpl(String name, int code, TypeSystemImpl ts, int stringSet) {
+  public StringTypeImpl(String name, int code, TypeSystemImpl ts) {
     super(name, code, ts);
-    this.stringSet = stringSet;
-  }
-
-  public int getStringSet() { // public for JCas access from TOP impl which
-    // impls FeatureStructureImpl
-    return this.stringSet;
   }
 
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystem2Xml.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystem2Xml.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystem2Xml.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystem2Xml.java Mon Dec 18 09:02:59 2006
@@ -106,8 +106,9 @@
 
       // check for string subtypes
       if (type instanceof StringTypeImpl) {
-        int stringSetId = ((StringTypeImpl) type).getStringSet();
-        String[] strings = ((TypeSystemImpl) aTypeSystem).getStringSet(stringSetId);
+	LowLevelTypeSystem lts = aTypeSystem.getLowLevelTypeSystem();
+	final int typeCode = lts.ll_getCodeForType(type);
+        String[] strings = lts.ll_getStringSet(typeCode);
         AllowedValue[] allowedVals = new AllowedValue[strings.length];
         for (int i = 0; i < strings.length; i++) {
           allowedVals[i] = factory.createAllowedValue();

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=488340&r1=488339&r2=488340
==============================================================================
--- 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 Mon Dec 18 09:02:59 2006
@@ -146,9 +146,6 @@
   // Code of root of hierarchy (will be 1 with current implementation)
   private int top;
 
-  // String sets for string subtypes.
-  private ArrayList stringSets;
-
   // A vector of TypeImpl objects.
   private ArrayList types;
 
@@ -158,7 +155,13 @@
   // List of parent types.
   private final IntVector parents;
 
-  BitSet isStringSubtype = new BitSet();
+  // String sets for string subtypes.
+  private final ArrayList stringSets;
+
+  
+  // This map contains an entry for every subtype of the string type.  The value is a pointer into
+  // the stringSets array list.
+  private final IntRedBlackTree stringSetMap;
 
   // For each type, remember of an array of this component type has already
   // been created.
@@ -257,6 +260,7 @@
     this.features = new ArrayList();
     this.features.add(null);
     this.stringSets = new ArrayList();
+    this.stringSetMap = new IntRedBlackTree();
     this.componentToArrayTypeMap = new IntRedBlackTree();
     this.arrayToComponentTypeMap = new IntRedBlackTree();
     this.arrayCodeToTypeMap = new RedBlackTree();
@@ -485,10 +489,10 @@
     }
     TypeImpl t;
     if (isStringType) {
-      this.isStringSubtype.set(type);
-      t = new StringTypeImpl(name, type, this, this.stringSets.size());
+      final int stringSetCode = this.stringSets.size();
+      this.stringSetMap.put(type, stringSetCode);
+      t = new StringTypeImpl(name, type, this);
     } else {
-      this.isStringSubtype.clear(type);
       t = new TypeImpl(name, type, this);
     }
     this.types.add(t);
@@ -1116,7 +1120,7 @@
   }
 
   public boolean ll_isStringSubtype(int type) {
-    return this.isStringSubtype.get(type);
+    return this.stringSetMap.containsKey(type);
   }
 
   public boolean ll_isRefType(int typeCode) {
@@ -1226,7 +1230,6 @@
     // Dummy call to keep the counts ok. Will never use these data
     // structures for array types.
     newType();
-    this.isStringSubtype.clear(arrayTypeCode);
     TypeImpl arrayType = new TypeImpl(arrayTypeName, arrayTypeCode, this);
     this.types.add(arrayType);
     this.parents.add(motherCode);
@@ -1268,6 +1271,16 @@
   /* note that subtypes of String are considered primitive */
   public boolean ll_isPrimitiveType(int typeCode) {
     return !ll_isRefType(typeCode);
+  }
+
+  public String[] ll_getStringSet(int typeCode) {
+    if (!ll_isValidTypeCode(typeCode)) {
+      return null;
+    }
+    if (!ll_isStringSubtype(typeCode)) {
+      return null;
+    }
+    return (String[]) this.stringSets.get(this.stringSetMap.get(typeCode));
   }
 
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.java?view=diff&rev=488340&r1=488339&r2=488340
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.java Mon Dec 18 09:02:59 2006
@@ -27,6 +27,7 @@
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.LowLevelTypeSystem;
 import org.apache.uima.cas.impl.StringTypeImpl;
 import org.apache.uima.cas.impl.TypeSystemImpl;
 import org.apache.uima.resource.metadata.AllowedValue;
@@ -126,7 +127,8 @@
    *         Type.
    */
   public static String[] getAllowedValuesForType(Type aType, TypeSystem aTypeSystem) {
-    return ((TypeSystemImpl) aTypeSystem).getStringSet(((StringTypeImpl) aType).getStringSet());
+    LowLevelTypeSystem lts = aTypeSystem.getLowLevelTypeSystem();
+    return lts.ll_getStringSet(lts.ll_getCodeForType(aType));
   }
 
 }