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 2015/11/02 13:19:46 UTC
svn commit: r1711942 [2/2] -
/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/NonEmptyStringList.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/NonEmptyStringList.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/NonEmptyStringList.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/NonEmptyStringList.java Mon Nov 2 12:19:46 2015
@@ -19,10 +19,14 @@
package org.apache.uima.jcas.cas;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.cas.impl.TypeSystemImpl;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
-public class NonEmptyStringList extends StringList {
+public class NonEmptyStringList extends StringList implements NonEmptyList {
public final static int typeIndexID = JCasRegistry.register(NonEmptyStringList.class);
@@ -32,56 +36,62 @@ public class NonEmptyStringList extends
return typeIndexID;
}
- // Never called. Disable default constructor
- protected NonEmptyStringList() {
+ private final static int head_featCode;
+ private final static int tail_featCode;
+
+ static {
+ TypeSystemImpl tsi = TypeSystemImpl.staticTsi;
+ TypeImpl listType = tsi.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST);
+
+ head_featCode = listType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD).getCode();
+ tail_featCode = listType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL).getCode();
}
- /* Internal - Constructor used by generator */
- public NonEmptyStringList(int addr, TOP_Type type) {
- super(addr, type);
+ /* local data */
+ private String _F_head;
+ private StringList _F_tail;
+
+ // Never called. Disable default constructor
+ protected NonEmptyStringList() {
}
public NonEmptyStringList(JCas jcas) {
super(jcas);
}
- // *------------------*
+ /**
+ * used by generator
+ * Make a new AnnotationBase
+ * @param c -
+ * @param t -
+ */
+
+ public NonEmptyStringList(TypeImpl t, CASImpl c) {
+ super(t, c);
+ }
+
+// *------------------*
// * Feature: head
/* getter for head * */
- public String getHead() {
- if (NonEmptyStringList_Type.featOkTst
- && ((NonEmptyStringList_Type) jcasType).casFeat_head == null)
- this.jcasType.jcas.throwFeatMissing("head", "uima.cas.NonEmptyStringList");
- return jcasType.ll_cas.ll_getStringValue(addr,
- ((NonEmptyStringList_Type) jcasType).casFeatCode_head);
- }
+ public String getHead() { return _F_head; }
/* setter for head * */
public void setHead(String v) {
- if (NonEmptyStringList_Type.featOkTst
- && ((NonEmptyStringList_Type) jcasType).casFeat_head == null)
- this.jcasType.jcas.throwFeatMissing("head", "uima.cas.NonEmptyStringList");
- jcasType.ll_cas.ll_setStringValue(addr, ((NonEmptyStringList_Type) jcasType).casFeatCode_head,
- v);
+ _F_head = v;
+ // no corruption check - can't be a key
+ _casView.maybeLogUpdate(this, head_featCode);
}
// *------------------*
// * Feature: tail
/* getter for tail * */
- public StringList getTail() {
- if (NonEmptyStringList_Type.featOkTst
- && ((NonEmptyStringList_Type) jcasType).casFeat_tail == null)
- this.jcasType.jcas.throwFeatMissing("tail", "uima.cas.NonEmptyStringList");
- return (StringList) (jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr,
- ((NonEmptyStringList_Type) jcasType).casFeatCode_tail)));
- }
+ public StringList getTail() { return _F_tail; }
/* setter for tail * */
- public void setTail(StringList v) {
- if (NonEmptyStringList_Type.featOkTst
- && ((NonEmptyStringList_Type) jcasType).casFeat_tail == null)
- this.jcasType.jcas.throwFeatMissing("tail", "uima.cas.NonEmptyStringList");
- jcasType.ll_cas.ll_setRefValue(addr, ((NonEmptyStringList_Type) jcasType).casFeatCode_tail,
- jcasType.ll_cas.ll_getFSRef(v));
+ public void setTail(CommonList v) {
+ _F_tail = (StringList) v;
+ // no corruption check - can't be a key
+ _casView.maybeLogUpdate(this, tail_featCode);
}
+
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/ShortArray.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/ShortArray.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/ShortArray.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/ShortArray.java Mon Nov 2 12:19:46 2015
@@ -20,11 +20,13 @@
package org.apache.uima.jcas.cas;
import org.apache.uima.cas.ShortArrayFS;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
/** JCas class model for ShortArray */
-public final class ShortArray extends TOP implements ShortArrayFS {
+public final class ShortArray extends TOP implements CommonPrimitiveArray, ShortArrayFS {
/**
* 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
@@ -43,13 +45,11 @@ public final class ShortArray extends TO
return typeIndexID;
}
+ private final short[] theArray;
// never called. Here to disable default constructor
+ @SuppressWarnings("unused")
private ShortArray() {
- }
-
- /* Internal - Constructor used by generator */
- public ShortArray(int addr, TOP_Type type) {
- super(addr, type);
+ theArray = null;
}
/**
@@ -58,79 +58,80 @@ public final class ShortArray extends TO
* @param length The number of elements in the new array
*/
public ShortArray(JCas jcas, int length) {
- this(jcas.getLowLevelCas().ll_createShortArray(length), jcas.getType(typeIndexID));
+ super(jcas);
+ theArray = new short[length];
+ }
+
+ /**
+ * used by generator
+ * Make a new ShortArray of given size
+ * @param c -
+ * @param t -
+ * @param length The number of elements in the new array
+ */
+ public ShortArray(TypeImpl t, CASImpl c, int length) {
+ super(t, c);
+ theArray = new short[length];
}
/**
* @see org.apache.uima.cas.ShortArrayFS#get(int)
*/
public short get(int i) {
- jcasType.casImpl.checkArrayBounds(addr, i);
- return jcasType.ll_cas.ll_getShortArrayValue(addr, i);
+ return theArray[i];
}
/**
* @see org.apache.uima.cas.ShortArrayFS#set(int , short)
*/
public void set(int i, short v) {
- jcasType.casImpl.checkArrayBounds(addr, i);
- jcasType.ll_cas.ll_setShortArrayValue(addr, i, v);
+ theArray[i] = v;
+ _casView.maybeLogArrayUpdate(this, null, i);
}
/**
* @see org.apache.uima.cas.ShortArrayFS#copyFromArray(short[], int, int, int)
*/
- public void copyFromArray(short[] src, int srcOffset, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, destOffset, length);
- for (int i = 0; i < length; i++) {
- jcasType.ll_cas.ll_setShortArrayValue(addr, i + destOffset, src[i + srcOffset]);
- }
+ public void copyFromArray(short[] src, int srcPos, int destPos, int length) {
+ System.arraycopy(src, srcPos, theArray, destPos, length);
}
/**
* @see org.apache.uima.cas.ShortArrayFS#copyToArray(int, short[], int, int)
*/
- public void copyToArray(int srcOffset, short[] dest, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, srcOffset, length);
- for (int i = 0; i < length; i++) {
- dest[i + destOffset] = jcasType.ll_cas.ll_getShortArrayValue(addr, i + srcOffset);
- }
+ public void copyToArray(int srcPos, short[] dest, int destPos, int length) {
+ System.arraycopy(theArray, srcPos, dest, destPos, length);
}
/**
* @see org.apache.uima.cas.ShortArrayFS#toArray()
*/
public short[] toArray() {
- final int size = size();
- short[] outArray = new short[size];
- copyToArray(0, outArray, 0, size);
- return outArray;
+ return theArray.clone();
}
/** return the size of the array */
public int size() {
- return jcasType.casImpl.ll_getArraySize(addr);
+ return theArray.length;
}
/**
* @see org.apache.uima.cas.ShortArrayFS#copyToArray(int, String[], int, int)
*/
- public void copyToArray(int srcOffset, String[] dest, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, srcOffset, length);
+ public void copyToArray(int srcPos, String[] dest, int destPos, int length) {
+ _casView.checkArrayBounds(theArray.length, srcPos, length);
for (int i = 0; i < length; i++) {
- dest[i + destOffset] = Short.toString(jcasType.ll_cas.ll_getShortArrayValue(addr, i
- + srcOffset));
+ dest[i + destPos] = Short.toString(theArray[i + srcPos]);
}
}
/**
* @see org.apache.uima.cas.ShortArrayFS#copyFromArray(String[], int, int, int)
*/
- public void copyFromArray(String[] src, int srcOffset, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, destOffset, length);
+ public void copyFromArray(String[] src, int srcPos, int destPos, int length) {
+ _casView.checkArrayBounds(theArray.length, destPos, length);
for (int i = 0; i < length; i++) {
- jcasType.ll_cas.ll_setShortArrayValue(addr, i + destOffset, Short.parseShort(src[i
- + srcOffset]));
+ theArray[i + destPos] = Short.parseShort(src[i + srcPos]);
}
}
@@ -140,4 +141,19 @@ public final class ShortArray extends TO
copyToArray(0, strArray, 0, size);
return strArray;
}
+
+ // internal use
+ public short[] _getTheArray() {
+ return theArray;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonArray#copyValuesFrom(org.apache.uima.jcas.cas.CommonArray)
+ */
+ @Override
+ public void copyValuesFrom(CommonArray v) {
+ ShortArray bv = (ShortArray) v;
+ System.arraycopy(bv.theArray, 0, theArray, 0, theArray.length);
+ }
+
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/Sofa.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/Sofa.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/Sofa.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/Sofa.java Mon Nov 2 12:19:46 2015
@@ -21,264 +21,223 @@ package org.apache.uima.jcas.cas;
import java.io.InputStream;
-import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.SofaFS;
-import org.apache.uima.cas.SofaID;
import org.apache.uima.cas.impl.CASImpl;
-import org.apache.uima.cas.impl.FeatureImpl;
-import org.apache.uima.jcas.JCas;
+import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.jcas.JCasRegistry;
-import org.apache.uima.jcas.impl.JCasImpl;
-/**
- * Updated by JCasGen Fri Apr 29 16:05:04 EDT 2005
- */
public class Sofa extends TOP implements SofaFS {
- /**
- * @generated
- * @ordered
- */
+
public final static int typeIndexID = JCasRegistry.register(Sofa.class);
- /**
- * @generated
- * @ordered
- */
public final static int type = typeIndexID;
+ @Override
+ public int getTypeIndexID() {
+ return typeIndexID;
+ }
+
+ /* local data */
+
+ private final int _F_sofaNum;
+ private final String _F_sofaID; // view name or _InitialView
+ private String _F_mimeType; // may be changed
+ private TOP _F_sofaArray;
+ private String _F_sofaString;
+ private String _F_sofaURI;
+
+ protected Sofa() {
+ _F_sofaNum = 0;
+ _F_sofaID = null;
+ _F_mimeType = null;
+ }
+
+ /**
+ * used by generator, not used
+ * Make a new Sofa
+ * @param c -
+ * @param t -
+ */
+ public Sofa(TypeImpl t, CASImpl c) {
+ super(t, c);
+ _F_sofaNum = 0;
+ _F_sofaID = null;
+ }
+
+ public Sofa(TypeImpl t, CASImpl c, int sofaNum, String viewName, String mimeType) {
+ super(t, c);
+ _F_sofaNum = sofaNum;
+ _F_sofaID = viewName;
+ _F_mimeType = mimeType;
+ }
- /** @generated */
- public int getTypeIndexID() {
- return typeIndexID;
- }
-
- /**
- * Never called. Disable default constructor
- *
- * @generated
- */
- protected Sofa() {
- }
-
- /**
- * Internal - constructor used by generator
- *
- * @generated
- * @param addr the address
- * @param type the type
- */
- public Sofa(int addr, TOP_Type type) {
- super(addr, type);
- readObject();
- }
-
- /**
- *
- * @param jcas JCas
- * @param ID the sofa ID
- * @param mimeType the mime type
- *
- * @deprecated As of v2.0, use {@link JCasImpl#createView(String)} to create a view, which will
- * also create the Sofa for that view.
-
- */
- @Deprecated
- public Sofa(JCas jcas, SofaID ID, String mimeType) {
- super(jcas);
- final CASImpl casImpl = jcasType.casImpl;
- casImpl.addSofa(casImpl.createFS(this.addr), ID.getSofaID(), mimeType);
- casImpl.getView(this); // needed to make reset work
- }
-
- /**
- * <!-- begin-user-doc --> Write your own initialization here <!-- end-user-doc -->
- *
- * @generated modifiable
- */
-
- private void readObject() {
- }
+ // no constructor for Sofa for users
+ // use cas createSofa instead
+
+
+// /**
+// *
+// * @param jcas JCas
+// * @param ID the sofa ID
+// * @param mimeType the mime type
+// *
+// * @deprecated As of v2.0, use {@link JCasImpl#createView(String)} to create a view, which will
+// * also create the Sofa for that view.
+//
+// */
+// @Deprecated
+// public Sofa(JCas jcas, SofaID ID, String mimeType) {
+// super(jcas);
+// final CASImpl casImpl = jcasType.casImpl;
+// casImpl.addSofa(this, ID.getSofaID(), mimeType);
+// casImpl.getView(this); // needed to make reset work
+// }
// *--------------*
// * Feature: sofaNum
// ** Note: this gets the same feature, sofaNum, as getSofaRef, below
/**
- * getter for sofaNum - gets
- *
- * @generated
+ * getter for sofaNum
* @return the sofa number
*/
- public int getSofaNum() {
- if (Sofa_Type.featOkTst && ((Sofa_Type) jcasType).casFeat_sofaNum == null)
- this.jcasType.jcas.throwFeatMissing("sofaNum", "uima.cas.Sofa");
- return jcasType.ll_cas.ll_getIntValue(addr, ((Sofa_Type) jcasType).casFeatCode_sofaNum);
- }
-
+ public int getSofaNum() { return _F_sofaNum; }
+
// *--------------*
// * Feature: sofaID
/**
- * getter for sofaID - gets
- *
- * @generated
+ * getter for sofaID
+ * @return the sofaID, which is the same as the view name
*/
- public String getSofaID() {
- if (Sofa_Type.featOkTst && ((Sofa_Type) jcasType).casFeat_sofaID == null)
- this.jcasType.jcas.throwFeatMissing("sofaID", "uima.cas.Sofa");
- return jcasType.ll_cas.ll_getStringValue(addr, ((Sofa_Type) jcasType).casFeatCode_sofaID);
- }
+ @Override
+ public String getSofaID() { return _F_sofaID; }
// *--------------*
// * Feature: mimeType
/**
* getter for mimeType - gets
- *
- * @generated
* @return the mime type
*/
- public String getMimeType() {
- if (Sofa_Type.featOkTst && ((Sofa_Type) jcasType).casFeat_mimeType == null)
- this.jcasType.jcas.throwFeatMissing("mimeType", "uima.cas.Sofa");
- return jcasType.ll_cas.ll_getStringValue(addr, ((Sofa_Type) jcasType).casFeatCode_mimeType);
- }
-
- // IMPORTANT: Methods below here are duplicated in SofaFSImpl. If they are
- // changed here they must be changed in SofaFSImpl as well.
+ public String getMimeType() { return _F_mimeType; }
/**
* @see org.apache.uima.cas.SofaFS#setLocalSofaData(FeatureStructure) This method is duplicated in
* SofaFSImpl. Any changes should be made in both places.
+ * aFS must be an array
*/
- public void setLocalSofaData(FeatureStructure aFS) {
- final Feature arrayFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAARRAY);
- if (isSofaDataSet()) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATA_ALREADY_SET,
- new String[] { "setLocalSofaData()" });
- throw e;
- }
- super.setFeatureValue(arrayFeat, aFS);
+ @Override
+ public void setLocalSofaData(FeatureStructure aFS) {
+ if (isSofaDataSet()) { throwAlreadySet("setLocalSofaData()"); }
+ _F_sofaArray = (TOP) aFS;
+ }
+
+ public void setLocalSofaData(FeatureStructure aFS, String mimeType) {
+ setLocalSofaData(aFS);
+ _F_mimeType = mimeType;
}
/**
* @see org.apache.uima.cas.SofaFS#setLocalSofaData(String) This method is duplicated in
* SofaFSImpl. Any changes should be made in both places.
*/
- public void setLocalSofaData(String aString) {
- final Feature stringFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFASTRING);
- if (isSofaDataSet()) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATA_ALREADY_SET,
- new String[] { "setLocalSofaData()" });
- throw e;
- }
- super.setStringValue(stringFeat, aString);
- // create or update the document annotation for this Sofa's view
- CAS view = this.getCASImpl().getView(this);
- ((CASImpl) view).updateDocumentAnnotation();
+ @Override
+ public void setLocalSofaData(String aString) {
+ if (isSofaDataSet()) { throwAlreadySet("setLocalSofaData()"); }
+ _F_sofaString = aString;
+
+ // create or update the document annotation for this Sofa's view
+ ((CASImpl)(_casView.getView(this))).updateDocumentAnnotation();
+ }
+
+ public void setLocalSofaData(String aString, String mimeType) {
+ setLocalSofaData(aString);
+ _F_mimeType = mimeType;
}
/**
- * @see org.apache.uima.cas.SofaFS#getLocalFSData() This method is duplicated in SofaFSImpl. Any
- * changes should be made in both places.
+ * @see org.apache.uima.cas.SofaFS#getLocalFSData()
+ * returns an UIMA Array whose data represents the sofa
*/
- public FeatureStructure getLocalFSData() {
- final Feature arrayFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAARRAY);
- return this.getFeatureValue(arrayFeat);
- }
+ @Override
+ public FeatureStructure getLocalFSData() { return _F_sofaArray; }
/**
* @see org.apache.uima.cas.SofaFS#getLocalStringData() This method is duplicated in SofaFSImpl.
* Any changes should be made in both places.
*/
- public String getLocalStringData() {
- final Feature stringFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFASTRING);
- return this.getStringValue(stringFeat);
- }
+ @Override
+ public String getLocalStringData() { return _F_sofaString; }
/**
* @see org.apache.uima.cas.SofaFS#setRemoteSofaURI(String) This method is duplicated in
* SofaFSImpl. Any changes should be made in both places.
*/
- public void setRemoteSofaURI(String aURI) {
- final Feature uriFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAURI);
- if (isSofaDataSet()) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATA_ALREADY_SET,
- new String[] { "setRemoteSofaURI()" });
- throw e;
- }
- super.setStringValue(uriFeat, aURI);
+ @Override
+ public void setRemoteSofaURI(String aURI) {
+ if (isSofaDataSet()) { throwAlreadySet("setRemoteSofaURI()"); }
+ _F_sofaURI = aURI;
+ }
+
+ public void setRemoteSofaURI(String aURI, String mimeType) {
+ setRemoteSofaURI(aURI);
+ _F_mimeType = mimeType;
}
private boolean isSofaDataSet() {
- final Feature uriFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAURI);
- final Feature arrayFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAARRAY);
- final Feature stringFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFASTRING);
-
- if (null != this.getStringValue(uriFeat) || null != this.getFeatureValue(arrayFeat)
- || null != this.getStringValue(stringFeat)) {
- return true;
- }
- return false;
- }
+ return getLocalStringData() != null || // string data
+ getLocalFSData() != null || // array data
+ getSofaURI() != null; // remote data
+ }
+
+ @Override
+ public String getSofaMime() { return _F_mimeType; }
- // override setStringValue for SofaFS to not work!
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- public void setStringValue(Feature feat, String val) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
- throw e;
- }
+ @Override
+ public String getSofaURI() { return _F_sofaURI; }
- // override setFeatureValue for SofaFS to not work!
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- public void setFeatureValue(Feature feat, FeatureStructure fs) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
- throw e;
- }
+ // ** Note: this gets the feature named "sofaNum"
+ @Override
+ public int getSofaRef() { return _F_sofaNum; }
- // override setIntValue for SofaFS to not work!
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- public void setIntValue(Feature feat, Integer val) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
- throw e;
+ @Override
+ public InputStream getSofaDataStream() {
+ return _casView.getSofaDataStream(this);
}
-
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- public String getSofaMime() {
- final Feature mimeFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAMIME);
- return jcasType.casImpl.getLowLevelCAS().ll_getStringValue(super.addr,
- ((FeatureImpl) mimeFeat).getCode());
+
+ /**
+ * These getter methods are for creating method handle access
+ * The getter name must match the feature name + transformation
+ * - used in generic pretty printing routines
+ */
+
+ public TOP getSofaArray() { return _F_sofaArray; }
+
+ public String getSofaString() { return _F_sofaString; }
+
+
+ // override setStringValue for SofaFS to prohibit setting in this manner!
+ @Override
+ public void setStringValue(Feature feat, String val) {
+ throw new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
+ }
+
+ // override setFeatureValue for SofaFS to prohibit setting in this manner!
+ @Override
+ public void setFeatureValue(Feature feat, FeatureStructure fs) {
+ throw new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
}
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- public String getSofaURI() {
- final Feature uriFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAURI);
- return jcasType.casImpl.getLowLevelCAS().ll_getStringValue(super.addr,
- ((FeatureImpl) uriFeat).getCode());
- }
-
- // This method is duplicated in SofaFSImpl. Any changes should be made in both places.
- // ** Note: this gets the feature named "sofaNum"
- public int getSofaRef() {
- final Feature numFeat = jcasType.casImpl.getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFANUM);
- return jcasType.casImpl.getLowLevelCAS().ll_getIntValue(super.addr,
- ((FeatureImpl) numFeat).getCode());
- }
+ // override setIntValue for SofaFS to prohibit setting in this manner!
+ public void setIntValue(Feature feat, Integer val) {
+ throw new CASRuntimeException(CASRuntimeException.PROTECTED_SOFA_FEATURE);
+ }
- public InputStream getSofaDataStream() {
- return jcasType.casImpl.getSofaDataStream(this);
+
+ private void throwAlreadySet(String msg) {
+ throw new CASRuntimeException(CASRuntimeException.SOFADATA_ALREADY_SET, msg);
}
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringArray.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringArray.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringArray.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringArray.java Mon Nov 2 12:19:46 2015
@@ -20,11 +20,13 @@
package org.apache.uima.jcas.cas;
import org.apache.uima.cas.StringArrayFS;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
/** JCas class model for StringArray */
-public final class StringArray extends TOP implements StringArrayFS {
+public final class StringArray extends TOP implements CommonPrimitiveArray, StringArrayFS {
/**
* 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
@@ -43,13 +45,11 @@ public final class StringArray extends T
return typeIndexID;
}
+ private final String[] theArray;
// never called. Here to disable default constructor
+ @SuppressWarnings("unused")
private StringArray() {
- }
-
- /* Internal - Constructor used by generator */
- public StringArray(int addr, TOP_Type type) {
- super(addr, type);
+ theArray = null;
}
/**
@@ -58,61 +58,60 @@ public final class StringArray extends T
* @param length The number of elements in the new array
*/
public StringArray(JCas jcas, int length) {
- this(
- /* addr */jcas.getLowLevelCas().ll_createArray(jcas.getType(typeIndexID).casTypeCode, length,
- true),
- /* type */jcas.getType(typeIndexID));
+ super(jcas);
+ theArray = new String[length];
+ }
+
+ /**
+ * used by generator
+ * Make a new StringArray of given size
+ * @param c -
+ * @param t -
+ * @param length the length of the array in bytes
+ */
+ public StringArray(TypeImpl t, CASImpl c, int length) {
+ super(t, c);
+ theArray = new String[length];
}
/**
* @see org.apache.uima.cas.StringArrayFS#get(int)
*/
public String get(int i) {
- jcasType.casImpl.checkArrayBounds(addr, i);
- return jcasType.ll_cas.ll_getStringArrayValue(addr, i);
+ return theArray[i];
}
/**
* @see org.apache.uima.cas.StringArrayFS#set(int, String)
*/
public void set(int i, String v) {
- jcasType.casImpl.checkArrayBounds(addr, i);
- jcasType.ll_cas.ll_setStringArrayValue(addr, i, v);
+ theArray[i] = v;
}
/**
* @see org.apache.uima.cas.StringArrayFS#copyFromArray(String[], int, int, int)
*/
- public void copyFromArray(String[] src, int srcOffset, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, destOffset, length);
- for (int i = 0; i < length; i++) {
- jcasType.ll_cas.ll_setStringArrayValue(addr, i + destOffset, src[i + srcOffset]);
- }
+ public void copyFromArray(String[] src, int srcPos, int destPos, int length) {
+ System.arraycopy(src, srcPos, theArray, destPos, length);
}
/**
* @see org.apache.uima.cas.StringArrayFS#copyToArray(int, String[], int, int)
*/
- public void copyToArray(int srcOffset, String[] dest, int destOffset, int length) {
- jcasType.casImpl.checkArrayBounds(addr, srcOffset, length);
- for (int i = 0; i < length; i++) {
- dest[i + destOffset] = jcasType.ll_cas.ll_getStringArrayValue(addr, i + srcOffset);
- }
+ public void copyToArray(int srcPos, String[] dest, int destPos, int length) {
+ System.arraycopy(theArray, srcPos, dest, destPos, length);
}
/**
* @see org.apache.uima.cas.StringArrayFS#toArray()
*/
public String[] toArray() {
- final int size = size();
- String[] outArray = new String[size];
- copyToArray(0, outArray, 0, size);
- return outArray;
+ return theArray.clone();
}
/** return the size of the array */
public int size() {
- return jcasType.casImpl.ll_getArraySize(addr);
+ return theArray.length;
}
public String[] toStringArray() {
@@ -121,4 +120,19 @@ public final class StringArray extends T
copyToArray(0, strArray, 0, size);
return strArray;
}
+
+ // internal use
+ public String[] _getTheArray() {
+ return theArray;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonArray#copyValuesFrom(org.apache.uima.jcas.cas.CommonArray)
+ */
+ @Override
+ public void copyValuesFrom(CommonArray v) {
+ StringArray bv = (StringArray) v;
+ System.arraycopy(bv.theArray, 0, theArray, 0, theArray.length);
+ }
+
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringList.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringList.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringList.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/StringList.java Mon Nov 2 12:19:46 2015
@@ -19,58 +19,75 @@
package org.apache.uima.jcas.cas;
-import org.apache.uima.cas.CASRuntimeException;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.JCasRegistry;
-public class StringList extends org.apache.uima.jcas.cas.TOP {
-
- public final static int typeIndexID = JCasRegistry.register(StringList.class);
-
- public final static int type = typeIndexID;
-
- public int getTypeIndexID() {
- return typeIndexID;
- }
+public abstract class StringList extends CommonList {
// Never called.
protected StringList() { // Disable default constructor
}
- /* Internal - Constructor used by generator */
- public StringList(int addr, TOP_Type type) {
- super(addr, type);
- }
-
public StringList(JCas jcas) {
super(jcas);
}
- public String getNthElement(int i) {
- if (this instanceof EmptyStringList) {
- CASRuntimeException casEx = new CASRuntimeException(
- CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST, new String[] { "EmptyStringList" });
- throw casEx;
- }
-
- if (i < 0) {
- CASRuntimeException casEx = new CASRuntimeException(
- CASRuntimeException.JCAS_GET_NTH_NEGATIVE_INDEX, new String[] { Integer.toString(i) });
- throw casEx;
- }
-
- int originali = i;
- StringList cg = this;
- for (;; i--) {
- if (cg instanceof EmptyStringList) {
- CASRuntimeException casEx = new CASRuntimeException(
- CASRuntimeException.JCAS_GET_NTH_PAST_END, new String[] { Integer.toString(originali) });
- throw casEx;
- }
- NonEmptyStringList c = (NonEmptyStringList) cg;
- if (i == 0)
- return c.getHead();
- cg = c.getTail();
- }
- }
+ /**
+ * used by generator
+ * Make a new AnnotationBase
+ * @param c -
+ * @param t -
+ */
+
+ public StringList(TypeImpl t, CASImpl c) {
+ super(t, c);
+ }
+
+ public String getNthElement(int i) {
+ return ((NonEmptyStringList) getNonEmptyNthNode(i)).getHead();
+ }
+
+ public NonEmptyStringList createNonEmptyNode(CommonList tail) {
+ NonEmptyStringList node = new NonEmptyStringList(this._typeImpl, this._casView);
+ node.setTail((StringList) tail);
+ return node;
+ }
+
+ public NonEmptyStringList createNonEmptyNode() { return createNonEmptyNode(null); }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonList#getEmptyNode()
+ */
+ @Override
+ public EmptyStringList getEmptyNode() {
+ return EmptyStringList.singleton;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonList#get_headAsString()
+ */
+ @Override
+ public String get_headAsString() {
+ return ((NonEmptyStringList)this).getHead();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonList#getTail()
+ */
+ @Override
+ public CommonList getTail() {
+ return ((NonEmptyStringList)this).getTail();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.jcas.cas.CommonList#setTail(org.apache.uima.jcas.cas.CommonList)
+ */
+ @Override
+ public void setTail(CommonList v) {
+ ((NonEmptyStringList)this).setTail(v);
+ }
+
+
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP.java?rev=1711942&r1=1711941&r2=1711942&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/cas/TOP.java Mon Nov 2 12:19:46 2015
@@ -19,166 +19,62 @@
package org.apache.uima.jcas.cas;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.impl.CASImpl;
-import org.apache.uima.cas.impl.FeatureStructureImpl;
-import org.apache.uima.cas.impl.LowLevelCAS;
+import org.apache.uima.cas.impl.FeatureStructureImplC;
+import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.jcas.impl.JCasImpl;
// *********************************
// * Implementation of TOP *
// *********************************
/**
- * The Java Class model corresponding to the Cas TOP type. This type is the super type of all
- * feature structures. This type implements FeatureStructure since subclasses of it are the FSs
- * generated by this system.
+ * The JCas Class model corresponding to the Cas TOP type. This type is the super type of all
+ * JCas feature structures.
*/
-public class TOP extends FeatureStructureImpl {
+public class TOP extends FeatureStructureImplC {
/**
* 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 = JCasRegistry.register(TOP.class);
+ public final static int typeIndexID = JCasRegistry.register(AnnotationBase.class);
public final static int type = typeIndexID;
/**
- * used to obtain reference to the TOP_Type instance
*
* @return the type array index
*/
// can't be factored - refs locally defined field
+ @Override
public int getTypeIndexID() {
return typeIndexID;
}
- /*
- * Note this class doesn't extend FeatureStructureImpl because that would add one more slot (the
- * casImpl ref) to every instance.
- *
- * Note: the jcasType slot points to an instance of the _Type class;
- * there's one per CAS (unique base cas)
- * This slot is updated to reflect the current View, though, to make add to indexes more likely to be what's intended
- */
- /** used to reference the corresponding TOP_Type instance */
- public TOP_Type jcasType;
-
- /** used to reference the corresponding Cas instance */
- protected final int addr;
-
- // This constructor is never called .
- // Have to set "final" values to avoid compile errors
- protected TOP() {
- jcasType = null;
- addr = 0;
- throw new RuntimeException("Internal Error: TOP() constructor should never be called.");
- }
-
- /*
- * (Internal) make a new instance of TOP, linking it with a pre-existing Cas FeatureStructure
- * object. Note: this function invoked via the generator in TOP_Type whenever the CAS needs to
- * make a java instance
- */
- public TOP(int addr, TOP_Type jcasType) {
- this.addr = addr;
- this.jcasType = jcasType;
- }
-
- /*
- * (Internal) create a new instance of TOP (or subclass of TOP) in Java and Cas, and make them
- * correspond.
- */
- public TOP(JCas jcas) {
- CASImpl casImpl = (CASImpl)jcas.getCas();
- this.jcasType = jcas.getType(getTypeIndexID());
- if (null == jcasType) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS,
- new String[] { this.getClass().getName() });
- throw e;
- }
- boolean isSubtypeOfAnnotationBase = casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode);
- if (isSubtypeOfAnnotationBase &&
- (casImpl.getBaseCAS() == casImpl)) {
- throw new CASRuntimeException(CASRuntimeException.DISALLOW_CREATE_ANNOTATION_IN_BASE_CAS,
- new String[] { this.getClass().getName() });
- }
- this.addr = jcasType.ll_cas.ll_createFS(jcasType.casTypeCode);
- jcas.putJfsFromCaddr(addr, this);
-
- if (casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode)) {
- casImpl.setSofaFeat(addr, casImpl.getSofaRef());
- }
- }
-
- /** add the corresponding FeatureStructure to all Cas indexes in the view where this FS was created*/
- public void addToIndexes() {
- addToIndexes(jcasType.jcas);
- }
-
- /**
- * add this FS to indexes in a specific view, perhaps different from the creation view
- * @param jcas the JCas
- */
- public void addToIndexes(JCas jcas) {
- jcas.getCas().addFsToIndexes(this);
- }
-
- /** remove the corresponding FeatureStructure from all Cas indexes in the view where this FS was created */
- public void removeFromIndexes() {
- removeFromIndexes(jcasType.jcas);
- }
-
- /**
- * remove this FS from indexes in a specific view, perhaps different from the view where this was created.
- * @param jcas the JCas
- */
- public void removeFromIndexes(JCas jcas) {
- jcas.getLowLevelIndexRepository().ll_removeFS(this.addr);
- }
-
- /*
- * functions needed to to implement the FeatureStructure interface
- * Note we don't simply implement this class as a subclass of FeatureStructureImpl
- * because that would add one more slot to every instance
+ // never called. Here to disable default constructor
+ protected TOP() {
+ }
+
+ /**
+ * used by generator
+ * Make a new TOP
+ * @param c -
+ * @param t -
*/
- public int getAddress() {
- return this.addr;
- }
-
- public CASImpl getCASImpl() {
- return jcasType.casImpl;
+ public TOP(TypeImpl t, CASImpl c) {
+ super(t, c);
}
/**
- * @return the CAS view where this FS was created
+ * This version is used by user code new XXX(jcas)
+ * @param jcas
*/
- public CAS getCAS() {
- return jcasType.casImpl;
- }
-
- public LowLevelCAS getLowLevelCas() {
- return jcasType.casImpl;
- }
-
- public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
- if (!(o instanceof TOP))
- return false;
- TOP fs = (TOP) o;
- if ((this.addr == fs.addr) && (this.jcasType.casImpl.getBaseCAS() == fs.jcasType.casImpl.getBaseCAS())) {
- return true;
- }
- return false;
+ public TOP(JCas jcas) {
+ super((JCasImpl) jcas);
}
- public int hashCode() {
- return this.addr;
- }
}