Author: schor
Date: Tue Jan 23 19:55:56 2018
New Revision: 1822043

URL: http://svn.apache.org/viewvc?rev=1822043&view=rev
Log:
[UIMA-5698] add a kind of pseudo feature, not in the type system, but imputed 
from the JCas class definition for the type.

Added:
    
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl_jcas_only.java
Modified:
    
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl.java

Modified: 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl.java?rev=1822043&r1=1822042&r2=1822043&view=diff
==============================================================================
--- 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl.java
 (original)
+++ 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl.java
 Tue Jan 23 19:55:56 2018
@@ -92,23 +92,32 @@ public class FeatureImpl implements Feat
   }
 
   FeatureImpl(TypeImpl typeImpl, String shortName, TypeImpl rangeType, 
TypeSystemImpl tsi, boolean isMultipleRefsAllowed, SlotKind slotKind) {
-//  this.code = code;
-  this.highestDefiningType = typeImpl;  
-  List<FeatureImpl> feats = tsi.features;
-  featureCode = feats.size();
-  
-  this.rangeType = rangeType;
-  this.isLongOrDouble = rangeType.isLongOrDouble;
-  this.slotKind = slotKind;
-  this.shortName = shortName;
-  this.isMultipleRefsAllowed = isMultipleRefsAllowed;
-  this.isAnnotBaseSofaRef = (highestDefiningType.getCode() == 
TypeSystemConstants.annotBaseTypeCode) && 
shortName.equals(CAS.FEATURE_BASE_NAME_SOFA);
-  this.isInInt = tsi.isInInt(rangeType);
-  this.rangeTypeClass = CasSerializerSupport.classifyType(rangeType);
-  this.hashCodeLong = computeHashCodeLong();
-  typeImpl.addFeature(this);  // might throw if existing feature with 
different range
-  feats.add(this);
-}
+  //  this.code = code;
+    this.highestDefiningType = typeImpl;  
+    List<FeatureImpl> feats = (tsi == null) ? null : tsi.features;
+    this.featureCode = (feats == null) ? -1 : feats.size();
+    
+    this.rangeType = rangeType;
+    this.isLongOrDouble = (rangeType == null) ? false : 
rangeType.isLongOrDouble;
+    this.slotKind = slotKind;
+    this.shortName = shortName;
+    this.isMultipleRefsAllowed = isMultipleRefsAllowed;
+    this.isAnnotBaseSofaRef = (highestDefiningType == null) 
+                                ? false
+                                : ((highestDefiningType.getCode() == 
TypeSystemConstants.annotBaseTypeCode) && 
shortName.equals(CAS.FEATURE_BASE_NAME_SOFA));
+    this.isInInt = (rangeType == null) 
+                     ? false 
+                     : (rangeType.getTypeSystem().isInInt(rangeType));
+    this.rangeTypeClass = (rangeType == null) 
+                     ? null
+                     : CasSerializerSupport.classifyType(rangeType);
+    this.hashCodeLong = computeHashCodeLong();
+    if (typeImpl != null) {
+      // if typeImpl is null, this is a "jcas only" defined feature, not a 
real feature
+      typeImpl.addFeature(this);  // might throw if existing feature with 
different range
+      feats.add(this);
+    }
+  }
 
   /**
    * @return the internal code of this feature. Necessary when using low-level 
APIs.

Added: 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl_jcas_only.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl_jcas_only.java?rev=1822043&view=auto
==============================================================================
--- 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl_jcas_only.java
 (added)
+++ 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureImpl_jcas_only.java
 Tue Jan 23 19:55:56 2018
@@ -0,0 +1,47 @@
+/*
+ * 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.cas.impl;
+
+/**
+ * The implementation of jcas-only features in the type system.
+ * JCas-only features are not real features in the type system, but are 
features inferred
+ *   by the existence of JCas class information
+ * They cannot be set or referenced, but exist in order to properly set up the
+ *   "offsets" for the JCas class, so that 
+ *   that same JCas class can be used with a different type system which 
**does** define that feature.
+ */
+public class FeatureImpl_jcas_only extends FeatureImpl {
+        
+  FeatureImpl_jcas_only(String shortName, TypeImpl rangeType) {
+    super(null, shortName, rangeType, null, false, null);
+  }
+
+  /* (non-Javadoc)
+   * @see java.lang.Object#toString()
+   */
+  @Override
+  public String toString() {
+    return String.format("FeatureImpl_jcas_only [%s, range:=%s]",
+        getShortName(), getRangeImpl());
+  }
+  
+  
+        
+}


Reply via email to