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 2016/12/29 16:38:39 UTC

svn commit: r1776450 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas: JCas.java cas/AnnotationBase_Type.java cas/TOP_Type.java impl/JCasImpl.java tcas/Annotation_Type.java

Author: schor
Date: Thu Dec 29 16:38:38 2016
New Revision: 1776450

URL: http://svn.apache.org/viewvc?rev=1776450&view=rev
Log:
[UIMA-5233] include common _Type classes for built-ins, marked deprecated, changed to throw exceptions, rather than have them missing.  This allows old code that references these to compile after v3 migration. 

Added:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/AnnotationBase_Type.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP_Type.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/tcas/Annotation_Type.java
Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java?rev=1776450&r1=1776449&r2=1776450&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/JCas.java Thu Dec 29 16:38:38 2016
@@ -52,6 +52,7 @@ import org.apache.uima.jcas.cas.IntegerA
 import org.apache.uima.jcas.cas.Sofa;
 import org.apache.uima.jcas.cas.StringArray;
 import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.cas.TOP_Type;
 import org.apache.uima.jcas.tcas.Annotation;
 
 /**
@@ -99,6 +100,28 @@ public interface JCas extends AbstractCa
   LowLevelCAS getLowLevelCas();
 
   /**
+   * Backwards Compatibility only - throws unsupported operation exception
+   * 
+   * get the JCas _Type instance for a particular CAS type constant
+   * 
+   * @param i
+   *          the CAS type constant, written as Foo.type
+   * @return the instance of the JCas xxx_Type object for the specified type
+   */
+  public abstract TOP_Type getType(int i);
+  
+  /**
+   * get the JCas x_Type instance for a particular Java instance of a type
+   * 
+   * @param instance instance
+   * @return the associated xxx_Type instance
+   * @deprecated use instance.jcasType instead - faster
+   */
+  @Deprecated
+  public abstract TOP_Type getType(TOP instance);
+
+
+  /**
    * Given Foo.type, return the corresponding CAS Type object. This is useful in the methods which
    * require a CAS Type, for instance iterator creation.
    * 

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/AnnotationBase_Type.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/AnnotationBase_Type.java?rev=1776450&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/AnnotationBase_Type.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/AnnotationBase_Type.java Thu Dec 29 16:38:38 2016
@@ -0,0 +1,76 @@
+/*
+ * 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.jcas.cas;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.SofaFS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+
+//*   Not used, only present to avoid compile errors
+//*   for old v2 style _Type classes
+/**
+ * for v2 compiling only
+ * @deprecated 
+ */
+@Deprecated
+public class AnnotationBase_Type extends org.apache.uima.jcas.cas.TOP_Type {
+  public final static int typeIndexID = -1;
+
+  public final static boolean featOkTst = JCasRegistry.getFeatOkTst("uima.cas.AnnotationBase");
+
+  final Feature casFeat_sofa;
+
+  final int casFeatCode_sofa;
+
+  public SofaFS getSofa(int addr) {
+    throw new RuntimeException("not supported");
+//    if (featOkTst && casFeat_sofa == null)
+//      this.jcas.throwFeatMissing("sofa", "uima.cas.AnnotationBase");
+//    return (SofaFS) ll_cas.ll_getFSForRef(addr);
+  }
+
+  public CAS getView(int addr) {
+    throw new RuntimeException("not supported");
+//    return casImpl.ll_getSofaCasView(addr);
+  }
+
+  // * initialize variables to correspond with Cas Type and Features
+  public AnnotationBase_Type(JCas jcas, Type casType) {
+    super(jcas, casType);
+    casFeat_sofa = null;
+    casFeatCode_sofa = JCas.INVALID_FEATURE_CODE;
+
+//     casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
+    return;
+//    casFeat_sofa = jcas.getRequiredFeatureDE(casType, "sofa", "uima.cas.Sofa", featOkTst);
+//    casFeatCode_sofa = (null == casFeat_sofa) ? JCas.INVALID_FEATURE_CODE
+//            : ((FeatureImpl) casFeat_sofa).getCode();
+  }
+
+  protected AnnotationBase_Type() { // block default new operator
+    casFeat_sofa = null;
+    casFeatCode_sofa = JCas.INVALID_FEATURE_CODE;
+    throw new RuntimeException("Internal Error-this constructor should never be called.");
+  }
+
+}

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP_Type.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP_Type.java?rev=1776450&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP_Type.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP_Type.java Thu Dec 29 16:38:38 2016
@@ -0,0 +1,211 @@
+/*
+ * 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.jcas.cas;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.LowLevelCAS;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.jcas.JCas;
+
+// *********************************
+// * Implementation of TOP_Type *
+// *   Not used, only present to avoid compile errors
+// *   for old v2 style _Type classes
+// *********************************
+/**
+ * hold Cas type information, link to JCas instance. One instance per Type, per CAS
+ * @deprecated
+ */
+@Deprecated
+public class TOP_Type {
+
+	/**
+   * each cover class when loaded sets an index. used in the JCas typeArray to go from the cover
+   * class or class instance to the corresponding instance of the _Type class
+   */
+	public final static int typeIndexID = -1;
+
+	// public final static int type = typeIndexID;
+
+	/**
+   * used to obtain reference to the TOP_Type instance
+   * 
+   * @return the type array index
+   */
+	public int getTypeIndexID() {
+		return typeIndexID;
+	}
+
+	/** the Cas Type associated with this Java Cas Model class */
+	public final Type casType; // JCas may refer to it?
+
+	public final int casTypeCode; // public so getters/setters in another package can see
+
+	/** reference to the Java Cas root */
+	public final JCas jcas; // public so _type generators can find it
+
+	/** ref to CAS for faster getters/setters */
+	public final CASImpl casImpl;
+
+	public final LowLevelCAS ll_cas;
+
+	// switch this to true if debugging wanted
+	final protected boolean lowLevelTypeChecks; // if true check int type
+
+	final protected boolean lowLevelArrayBoundChecks;
+
+	// next has to be public to be visible to inner class?
+	final public boolean useExistingInstance; // if true, implements reuse of existing instance
+
+	// generator used by the CAS system when it needs to make a new instance
+	/**
+   * This generator can be set up to either get the identical Java object (if it exists) or just
+   * make a new one. If making a new one - the java object made cannot contain any other data
+   * (because updates won't be reflected). Each class generated by JCasGen either does this (if it
+   * has additional java fields imbedded) or not.
+   */
+
+	// protected because field shared by all subtypes
+	// next field no longer needed except for backwards compatibility
+	// new subtypes of TOP_Type use <class-name>.this instead
+	protected final TOP_Type instanceOf_Type; // allow ref to this in inner class
+
+//  protected FSGenerator<?> getFSGenerator() {
+//    return null; // no longer used, but may be needed for compatibility with older existing JCasGen'd cover classes that might extend this class
+//  }
+//
+//	private FSGenerator fsGenerator = new FSGenerator() {
+//		@SuppressWarnings("unchecked")
+//    public TOP createFS(int addr, CASImpl cas) {
+//			if (TOP_Type.this.useExistingInstance) {
+//				// Return eq fs instance if already created
+//				TOP fs = TOP_Type.this.jcas.getJfsFromCaddr(addr);
+//				if (null == fs) {
+//					fs = new TOP(addr, TOP_Type.this);
+//					TOP_Type.this.jcas.putJfsFromCaddr(addr, fs);
+//					return fs;
+//				}
+//				return fs;
+//			} else
+//				return new TOP(addr, TOP_Type.this);
+//		}
+//	};
+
+	// cas.getKnownJCas().getType(TOP.typeIndexID));}
+
+	// private static final String casTypeName = CAS.TYPE_NAME_TOP;
+	// private String jTypeName = CAS.TYPE_NAME_TOP;
+	// protected String getCasTypeName() {return casTypeName;}
+	// protected String getJTypeName() {return jTypeName;}
+
+	/**
+   * protected constructor - disable default constructor - never called.
+   */
+	protected TOP_Type() { // block default new operator
+		instanceOf_Type = null;
+		jcas = null;
+		casTypeCode = 0;
+		casType = null;
+		casImpl = null;
+		lowLevelTypeChecks = false;
+		lowLevelArrayBoundChecks = false;
+		useExistingInstance = true;
+		ll_cas = null;
+		// used for test mocking
+//		throw new RuntimeException("Internal Error-this constructor should never be called.");
+	}
+
+	/*
+   * Internal - this constructor is called when new CAS creates corresponding jcas instance. During
+   * this process, all the types defined in the CAS are used to see if there are any corresponding
+   * jcas type defs defined. If so, they are loaded. This constructor is called via its being the
+   * superclass of classes being loaded.
+   */
+
+	// constructor execution order: 1: super, 2: instance expr, 3: body
+	public TOP_Type(JCas jcas, Type casType) {
+		this(jcas, casType, true);
+	}
+
+	/*
+   * DO NOT USE - for backwards compatibility only.
+   */
+	// constructor execution order: 1: super, 2: instance expr, 3: body
+	protected TOP_Type(JCas jcas, Type casType, boolean installGenerator) {
+		this.jcas = jcas;
+		this.casImpl = jcas.getCasImpl();
+		this.ll_cas = this.casImpl;
+		this.casType = casType;
+		this.instanceOf_Type = this;
+		this.casTypeCode = ((TypeImpl) this.casType).getCode();
+		this.lowLevelTypeChecks = false;
+		this.lowLevelArrayBoundChecks = false;
+		this.useExistingInstance = true;
+
+		// Add generator to CASImpl for this type
+		// NOTE Getter used for FSGenerator to get the subtype instance value
+		// NOTE Above comment is irrelevant - because this call has to be in
+		// every subclass, because at the time this executes in TOP_Type,
+		// it is because the subclass invoked it via super(x,y), and the
+		// subclass's instance vars haven't yet been set
+		// Solution: every superClass that could be instantiated (TOP is not one of them)
+		// during the super calls will incorrectly set the generator for the casType, but
+		// this is OK because after the supers all run, the bottom one runs and sets it correctly.
+
+//		if (installGenerator) {
+//			((CASImpl) ll_cas).getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType,
+//					getFSGenerator());
+//		}
+	}
+
+//	// ************ No Object support ********************
+//	protected void checkType(int inst) {
+//		if (!casImpl.getTypeSystemImpl().subsumes(casTypeCode, casImpl.getHeapValue(inst)))
+//			invalidTypeArg(inst);
+//	}
+//
+//	protected void invalidTypeArg(int inst) {
+//		CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_TYPE,
+//				new String[] { casType.getName(),
+//						this.casImpl.getTypeSystemImpl().ll_getTypeForCode(casImpl.getHeapValue(inst)).getName() });
+//		throw e;
+//	}
+
+	/**
+	 * add the corresponding FeatureStructure to all Cas indexes
+	 * @param inst the low level CAS Feature Structure reference
+	 */
+	public void addToIndexes(int inst) {
+		jcas.getLowLevelIndexRepository().ll_addFS(inst);
+	}
+
+	/**
+	 * remove the corresponding FeatureStructure from all Cas indexes
+	 * @param inst the low level CAS Feature Structure reference
+	 */
+	public void removeFromIndexes(int inst) {
+		jcas.getLowLevelIndexRepository().ll_removeFS(inst);
+	}
+
+	public int noObjCreate() {
+		return casImpl.ll_createFS(casTypeCode);
+	}
+}

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java?rev=1776450&r1=1776449&r2=1776450&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java Thu Dec 29 16:38:38 2016
@@ -61,6 +61,7 @@ import org.apache.uima.jcas.cas.IntegerA
 import org.apache.uima.jcas.cas.Sofa;
 import org.apache.uima.jcas.cas.StringArray;
 import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.cas.TOP_Type;
 import org.apache.uima.jcas.tcas.Annotation;
 
 // *********************************
@@ -246,6 +247,25 @@ public class JCasImpl extends AbstractCa
   }
   
   /*
+   * @see org.apache.uima.jcas.JCas#getType(int)
+   */
+  public TOP_Type getType(final int i) {
+    throw new UnsupportedOperationException("UIMA V2 operation not supported in V3");
+//    if (i >= typeArray.length || null == typeArray[i]) {
+//      getTypeInit(i); 
+//    }
+//    return typeArray[i];
+  }
+
+  /*
+   * @see org.apache.uima.jcas.JCas#getType(org.apache.uima.jcas.cas.TOP)
+   */
+  public TOP_Type getType(TOP instance) {
+    return getType(instance.getTypeIndexID());
+  }
+
+  
+  /*
    * Given Foo.type, return the corresponding CAS Type object. This is useful in the methods which
    * require a CAS Type, for instance iterator creation.
    * (non-Javadoc)

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/tcas/Annotation_Type.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/tcas/Annotation_Type.java?rev=1776450&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/tcas/Annotation_Type.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/tcas/Annotation_Type.java Thu Dec 29 16:38:38 2016
@@ -0,0 +1,135 @@
+/*
+ * 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.jcas.tcas;
+
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+
+//*   Not used, only present to avoid compile errors
+//*   for old v2 style _Type classes
+/**
+ * @deprecated
+ */
+@Deprecated
+public class Annotation_Type extends org.apache.uima.jcas.cas.AnnotationBase_Type {
+//  protected FSGenerator<?> getFSGenerator() {
+//    return null; // no longer used, but may be needed for compatibility with older existing JCasGen'd cover classes that might extend this class
+//  }
+//
+//  private final FSGenerator fsGenerator = new FSGenerator() {
+//    @SuppressWarnings("unchecked")
+//    public Annotation createFS(int addr, CASImpl cas) {
+//      if (Annotation_Type.this.useExistingInstance) {
+//        // Return eq fs instance if already created
+//        Annotation fs = (Annotation) Annotation_Type.this.jcas.getJfsFromCaddr(addr);
+//        if (null == fs) {
+//          fs = new Annotation(addr, Annotation_Type.this);
+//          Annotation_Type.this.jcas.putJfsFromCaddr(addr, fs);
+//          return fs;
+//        }
+//        return fs;
+//      } else
+//        return new Annotation(addr, Annotation_Type.this);
+//    }
+//  };
+
+  public final static int typeIndexID = -1;
+
+  public final static boolean featOkTst = JCasRegistry.getFeatOkTst("uima.tcas.Annotation");
+
+  final Feature casFeat_begin = null;
+
+  final int casFeatCode_begin = -1;
+
+  public int getBegin(int addr) {
+    throw new RuntimeException("not supported");
+    // not needed - is built in
+//    if (featOkTst && casFeat_begin == null)
+//      this.jcas.throwFeatMissing("begin", "uima.tcas.Annotation");
+//    return casImpl.ll_getAnnotBegin(addr);
+//    return ll_cas.ll_getIntValue(addr, casFeatCode_begin);
+  }
+
+  public void setBegin(int addr, int v) {
+    throw new RuntimeException("JCas _Type v2 not supported");
+//    if (featOkTst && casFeat_begin == null)
+//      this.jcas.throwFeatMissing("begin", "uima.tcas.Annotation");
+//    ll_cas.ll_setIntValue(addr, casFeatCode_begin, v);
+  }
+
+  final Feature casFeat_end = null;
+
+  final int casFeatCode_end = -1;
+  
+  public int getEnd(int addr) {
+    throw new RuntimeException("JCas _Type v2 not supported");
+    // not needed - is built in
+//    if (featOkTst && casFeat_end == null)
+//      this.jcas.throwFeatMissing("end", "uima.tcas.Annotation");
+//    return casImpl.ll_getAnnotEnd(addr);
+//    return ll_cas.ll_getIntValue(addr, casFeatCode_end);
+  }
+
+  public void setEnd(int addr, int v) {
+    throw new RuntimeException("JCas _Type v2 not supported");
+//    if (featOkTst && casFeat_end == null)
+//      this.jcas.throwFeatMissing("end", "uima.tcas.Annotation");
+//    ll_cas.ll_setIntValue(addr, casFeatCode_end, v);
+  }
+
+  /**
+   * @see org.apache.uima.cas.text.AnnotationFS#getCoveredText()
+   * @param inst low level reference to a Feature Structure
+   * @return null or the covered text
+   */
+  public String getCoveredText(int inst) { 
+    final CASImpl casView = ll_cas.ll_getSofaCasView(inst);
+    final String text = casView.getDocumentText();
+    if (text == null) {
+      return null;
+    }
+    return text.substring(getBegin(inst), getEnd(inst)); 
+  }
+
+  // * initialize variables to correspond with Cas Type and Features
+  public Annotation_Type(JCas jcas, Type casType) {
+    super(jcas, casType);
+//    casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
+
+//    casFeat_begin = jcas.getRequiredFeatureDE(casType, "begin", "uima.cas.Integer", featOkTst);
+//    casFeatCode_begin = (null == casFeat_begin) ? JCas.INVALID_FEATURE_CODE
+//            : ((FeatureImpl) casFeat_begin).getCode();
+//    casFeat_end = jcas.getRequiredFeatureDE(casType, "end", "uima.cas.Integer", featOkTst);
+//    casFeatCode_end = (null == casFeat_end) ? JCas.INVALID_FEATURE_CODE
+//            : ((FeatureImpl) casFeat_end).getCode();
+  }
+
+  protected Annotation_Type() { // block default new operator
+//    casFeat_begin = null;
+//    casFeatCode_begin = JCas.INVALID_FEATURE_CODE;
+//    casFeat_end = null;
+//    casFeatCode_end = JCas.INVALID_FEATURE_CODE;
+//    throw new RuntimeException("Internal Error-this constructor should never be called.");
+  }
+
+}