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 2007/01/19 14:08:20 UTC
svn commit: r497800 [2/10] - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/ main/java/org/apache/uima/cas/impl/
main/java/org/apache/uima/jcas/cas/ main/java/org/apache/uima/jcas/impl/
main/resources/org/apache/uima/ main...
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=497800&r1=497799&r2=497800
==============================================================================
--- 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 Jan 19 05:08:19 2007
@@ -87,1188 +87,1186 @@
*/
public class CASImpl extends AbstractCas_ImplBase implements CAS, CASMgr, LowLevelCAS {
- // Notes on the implementation
- // ---------------------------
+ // Notes on the implementation
+ // ---------------------------
- // Floats are handled by casting them to ints when they are stored
- // in the heap. Conveniently, 0 casts to 0.0f, which is the default
- // value.
+ // Floats are handled by casting them to ints when they are stored
+ // in the heap. Conveniently, 0 casts to 0.0f, which is the default
+ // value.
- public static final int NULL = 0;
+ public static final int NULL = 0;
- // Boolean scalar values are stored as ints in the fs heap.
- // TRUE is 1 and false is 0.
- public static final int TRUE = 1;
+ // Boolean scalar values are stored as ints in the fs heap.
+ // TRUE is 1 and false is 0.
+ public static final int TRUE = 1;
- public static final int FALSE = 0;
+ public static final int FALSE = 0;
- public static final int DEFAULT_INITIAL_HEAP_SIZE = 500000;
+ public static final int DEFAULT_INITIAL_HEAP_SIZE = 500000;
- public static final int DEFAULT_RESET_HEAP_SIZE = 5000000;
+ public static final int DEFAULT_RESET_HEAP_SIZE = 5000000;
- // this next seemingly non-sensical static block
- // is to force the classes needed by Eclipse debugging to load
- // otherwise, you get a com.sun.jdi.ClassNotLoadedException when
- // the class is used as part of formatting debugging messages
- static {
- new DebugNameValuePair(null, null);
- new DebugFSLogicalStructure();
- }
+ // this next seemingly non-sensical static block
+ // is to force the classes needed by Eclipse debugging to load
+ // otherwise, you get a com.sun.jdi.ClassNotLoadedException when
+ // the class is used as part of formatting debugging messages
+ static {
+ new DebugNameValuePair(null, null);
+ new DebugFSLogicalStructure();
+ }
- private final int resetHeapSize = DEFAULT_RESET_HEAP_SIZE;
+ private final int resetHeapSize = DEFAULT_RESET_HEAP_SIZE;
- protected TypeSystemImpl ts;
+ protected TypeSystemImpl ts;
- // The offset for the array length cell. An array consists of length+2
- // number
- // of cells, where the first cell contains the type, the second one the
- // length,
- // and the rest the actual content of the array.
- private static final int arrayLengthFeatOffset = 1;
+ // The offset for the array length cell. An array consists of length+2
+ // number
+ // of cells, where the first cell contains the type, the second one the
+ // length,
+ // and the rest the actual content of the array.
+ private static final int arrayLengthFeatOffset = 1;
- // The number of cells we need to skip to get to the array contents. That
- // is,
- // if we have an array starting at addr, the first cell is at
- // addr+arrayContentOffset.
- private static final int arrayContentOffset = 2;
+ // The number of cells we need to skip to get to the array contents. That
+ // is,
+ // if we have an array starting at addr, the first cell is at
+ // addr+arrayContentOffset.
+ private static final int arrayContentOffset = 2;
- protected Heap heap;
+ protected Heap heap;
- // private SymbolTable stringTable;
- // private ArrayList stringList;
- protected StringHeap stringHeap;
+ // private SymbolTable stringTable;
+ // private ArrayList stringList;
+ protected StringHeap stringHeap;
- protected ByteHeap byteHeap; // for storing 8 bit values
+ protected ByteHeap byteHeap; // for storing 8 bit values
- protected ShortHeap shortHeap; // for storing 16 bit values
+ protected ShortHeap shortHeap; // for storing 16 bit values
- protected LongHeap longHeap; // for storing 64 bit values
+ protected LongHeap longHeap; // for storing 64 bit values
- // The document text.
- private String documentText;
+ // The document text.
+ private String documentText;
- // The index repository.
- protected FSIndexRepositoryImpl indexRepository;
+ // The index repository.
+ protected FSIndexRepositoryImpl indexRepository;
- // A map from Sofas to IndexRepositories.
- private HashMap sofa2indexMap;
+ // A map from Sofas to IndexRepositories.
+ private HashMap sofa2indexMap;
- // A map from Sofas to CAS views.
- private HashMap sofa2tcasMap;
+ // A map from Sofas to CAS views.
+ private HashMap sofa2tcasMap;
- // A map from Sofas to JCas views.
- private HashMap sofa2jcasMap;
+ // A map from Sofas to JCas views.
+ private HashMap sofa2jcasMap;
- // Count of Sofa created in this cas
- protected HashSet sofaNameSet;
+ // Count of Sofa created in this cas
+ protected HashSet sofaNameSet;
- // Flag that initial Sofa has been created
- private boolean initialSofaCreated = false;
+ // Flag that initial Sofa has been created
+ private boolean initialSofaCreated = false;
- // set of instantiated sofaNames
- private int sofaCount;
+ // set of instantiated sofaNames
+ private int sofaCount;
- // Base CAS for all views
- protected CASImpl baseCAS;
+ // Base CAS for all views
+ protected CASImpl baseCAS;
- // the sofaFS this view is based on
- // SofaFS mySofa;
- protected int mySofaRef = 0;
+ // the sofaFS this view is based on
+ // SofaFS mySofa;
+ protected int mySofaRef = 0;
- // FS registry
- protected FSClassRegistry fsClassReg = null;
+ // FS registry
+ protected FSClassRegistry fsClassReg = null;
- private final boolean useFSCache;
+ private final boolean useFSCache;
- private static final boolean DEFAULT_USE_FS_CACHE = false;
+ private static final boolean DEFAULT_USE_FS_CACHE = false;
- // The ClassLoader that should be used by the JCas to load the generated
- // FS cover classes for this CAS. Defaults to the ClassLoader used
- // to load the CASImpl class.
- private ClassLoader jcasClassLoader = this.getClass().getClassLoader();
+ // The ClassLoader that should be used by the JCas to load the generated
+ // FS cover classes for this CAS. Defaults to the ClassLoader used
+ // to load the CASImpl class.
+ private ClassLoader jcasClassLoader = this.getClass().getClassLoader();
- // ///////////////////////////////////////////////////////
- // Data structures for type checking and feature encoding
+ // ///////////////////////////////////////////////////////
+ // Data structures for type checking and feature encoding
- // For each feature, what the offset from the start of the FS is.
- // That is, this will always be a number > 0. If you have the
- // address a of a structure of type t, then you can get the value of
- // feature f by getting (the value of) a+featureOffset[f] from the
- // heap. If f is not appropriate for t, anything can happen
- // (including an ArrayIndexOutOfBoundsException).
- private int[] featureOffset;
+ // For each feature, what the offset from the start of the FS is.
+ // That is, this will always be a number > 0. If you have the
+ // address a of a structure of type t, then you can get the value of
+ // feature f by getting (the value of) a+featureOffset[f] from the
+ // heap. If f is not appropriate for t, anything can happen
+ // (including an ArrayIndexOutOfBoundsException).
+ private int[] featureOffset;
- // For each type, how large structures of that type are. This will
- // also be > 0 for each type (since you need to store the type at a
- // minimum.
- private int[] fsSpaceReq;
+ // For each type, how large structures of that type are. This will
+ // also be > 0 for each type (since you need to store the type at a
+ // minimum.
+ private int[] fsSpaceReq;
- // For each type, remember if it's a regular type that can be created
- // with CAS.createFS() or not. Exceptions are built-in types float, int and
- // string, as well as arrays.
- private boolean[] creatableType;
+ // For each type, remember if it's a regular type that can be created
+ // with CAS.createFS() or not. Exceptions are built-in types float, int and
+ // string, as well as arrays.
+ private boolean[] creatableType;
- // ///////////////////////////////////////////////////////
- // Properties of types.
+ // ///////////////////////////////////////////////////////
+ // Properties of types.
- // Those types can not be created with CAS.createFS().
- private static String[] nonCreatableTypes = { CAS.TYPE_NAME_INTEGER, CAS.TYPE_NAME_FLOAT,
- CAS.TYPE_NAME_STRING, CAS.TYPE_NAME_ARRAY_BASE, CAS.TYPE_NAME_FS_ARRAY,
- CAS.TYPE_NAME_INTEGER_ARRAY, CAS.TYPE_NAME_FLOAT_ARRAY, CAS.TYPE_NAME_STRING_ARRAY,
- CAS.TYPE_NAME_SOFA, CAS.TYPE_NAME_BYTE, CAS.TYPE_NAME_BYTE_ARRAY, CAS.TYPE_NAME_BOOLEAN,
- CAS.TYPE_NAME_BOOLEAN_ARRAY, CAS.TYPE_NAME_SHORT, CAS.TYPE_NAME_SHORT_ARRAY,
- CAS.TYPE_NAME_LONG, CAS.TYPE_NAME_LONG_ARRAY, CAS.TYPE_NAME_DOUBLE,
- CAS.TYPE_NAME_DOUBLE_ARRAY };
+ // Those types can not be created with CAS.createFS().
+ private static String[] nonCreatableTypes = { CAS.TYPE_NAME_INTEGER, CAS.TYPE_NAME_FLOAT,
+ CAS.TYPE_NAME_STRING, CAS.TYPE_NAME_ARRAY_BASE, CAS.TYPE_NAME_FS_ARRAY,
+ CAS.TYPE_NAME_INTEGER_ARRAY, CAS.TYPE_NAME_FLOAT_ARRAY, CAS.TYPE_NAME_STRING_ARRAY,
+ CAS.TYPE_NAME_SOFA, CAS.TYPE_NAME_BYTE, CAS.TYPE_NAME_BYTE_ARRAY, CAS.TYPE_NAME_BOOLEAN,
+ CAS.TYPE_NAME_BOOLEAN_ARRAY, CAS.TYPE_NAME_SHORT, CAS.TYPE_NAME_SHORT_ARRAY,
+ CAS.TYPE_NAME_LONG, CAS.TYPE_NAME_LONG_ARRAY, CAS.TYPE_NAME_DOUBLE,
+ CAS.TYPE_NAME_DOUBLE_ARRAY };
- // References to built-in types.
- private TypeImpl topType;
+ // References to built-in types.
+ private TypeImpl topType;
- private TypeImpl intType;
+ private TypeImpl intType;
- private TypeImpl stringType;
+ private TypeImpl stringType;
- private TypeImpl floatType;
+ private TypeImpl floatType;
- private TypeImpl arrayBaseType;
+ private TypeImpl arrayBaseType;
- private TypeImpl intArrayType;
+ private TypeImpl intArrayType;
- private TypeImpl floatArrayType;
+ private TypeImpl floatArrayType;
- private TypeImpl stringArrayType;
+ private TypeImpl stringArrayType;
- private TypeImpl fsArrayType;
+ private TypeImpl fsArrayType;
- private TypeImpl sofaType;
+ private TypeImpl sofaType;
- private TypeImpl annotType;
+ private TypeImpl annotType;
- private TypeImpl annotBaseType;
+ private TypeImpl annotBaseType;
- private TypeImpl docType;
+ private TypeImpl docType;
- private FeatureImpl startFeat;
+ private FeatureImpl startFeat;
- private FeatureImpl endFeat;
+ private FeatureImpl endFeat;
- private FeatureImpl langFeat;
+ private FeatureImpl langFeat;
- private TypeImpl byteType;
+ private TypeImpl byteType;
- private TypeImpl byteArrayType;
+ private TypeImpl byteArrayType;
- private TypeImpl booleanType;
+ private TypeImpl booleanType;
- private TypeImpl booleanArrayType;
+ private TypeImpl booleanArrayType;
- private TypeImpl shortType;
+ private TypeImpl shortType;
- private TypeImpl shortArrayType;
+ private TypeImpl shortArrayType;
- private TypeImpl longType;
+ private TypeImpl longType;
- private TypeImpl longArrayType;
+ private TypeImpl longArrayType;
- private TypeImpl doubleType;
+ private TypeImpl doubleType;
- private TypeImpl doubleArrayType;
+ private TypeImpl doubleArrayType;
- // private int topTypeCode;
- private int intTypeCode;
+ // private int topTypeCode;
+ private int intTypeCode;
- private int stringTypeCode;
+ private int stringTypeCode;
- private int floatTypeCode;
+ private int floatTypeCode;
- // private int arrayBaseTypeCode;
- private int intArrayTypeCode;
+ // private int arrayBaseTypeCode;
+ private int intArrayTypeCode;
- private int floatArrayTypeCode;
+ private int floatArrayTypeCode;
- private int stringArrayTypeCode;
+ private int stringArrayTypeCode;
- private int fsArrayTypeCode;
+ private int fsArrayTypeCode;
- private int sofaTypeCode;
+ private int sofaTypeCode;
- protected int annotTypeCode;
+ protected int annotTypeCode;
- private int annotBaseTypeCode;
+ private int annotBaseTypeCode;
- private int byteTypeCode;
+ private int byteTypeCode;
- private int booleanTypeCode;
+ private int booleanTypeCode;
- private int shortTypeCode;
+ private int shortTypeCode;
- private int longTypeCode;
+ private int longTypeCode;
- private int doubleTypeCode;
+ private int doubleTypeCode;
- private int byteArrayTypeCode;
+ private int byteArrayTypeCode;
- private int booleanArrayTypeCode;
+ private int booleanArrayTypeCode;
- private int shortArrayTypeCode;
+ private int shortArrayTypeCode;
- private int longArrayTypeCode;
+ private int longArrayTypeCode;
- private int doubleArrayTypeCode;
+ private int doubleArrayTypeCode;
- private int sofaNumFeatCode;
+ private int sofaNumFeatCode;
- private int sofaIdFeatCode;
+ private int sofaIdFeatCode;
- private int sofaMimeFeatCode;
+ private int sofaMimeFeatCode;
- private int sofaUriFeatCode;
+ private int sofaUriFeatCode;
- private int sofaArrayFeatCode;
+ private int sofaArrayFeatCode;
- int annotSofaFeatCode;
+ int annotSofaFeatCode;
- int startFeatCode;
+ int startFeatCode;
- int endFeatCode;
+ int endFeatCode;
- protected int langFeatCode;
+ protected int langFeatCode;
- // If this CAS can be flushed or not.
- private boolean flushEnabled = true;
+ // If this CAS can be flushed or not.
+ private boolean flushEnabled = true;
- private boolean annotIndexInitialized = false;
+ private boolean annotIndexInitialized = false;
- protected JCas jcas = null;
+ protected JCas jcas = null;
- private ComponentInfo componentInfo;
+ private ComponentInfo componentInfo;
- private final ArrayList getStringList() {
- ArrayList stringList = new ArrayList();
- stringList.add(null);
- int pos = this.stringHeap.getLeastStringCode();
- final int end = this.stringHeap.getLargestStringCode();
- while (pos <= end) {
- stringList.add(this.stringHeap.getStringForCode(pos));
- ++pos;
- }
- return stringList;
- }
+ private final ArrayList getStringList() {
+ ArrayList stringList = new ArrayList();
+ stringList.add(null);
+ int pos = this.stringHeap.getLeastStringCode();
+ final int end = this.stringHeap.getLargestStringCode();
+ while (pos <= end) {
+ stringList.add(this.stringHeap.getStringForCode(pos));
+ ++pos;
+ }
+ return stringList;
+ }
- /*
+ /*
* (non-Javadoc)
*
* @see org.apache.uima.cas.admin.CASMgr#setCAS(org.apache.uima.cas.CAS)
*/
- public void setCAS(CAS cas) {
- CASImpl in = (CASImpl) cas;
- this.baseCAS = in;
- this.ts = in.ts;
- this.heap = in.heap;
- this.stringHeap = in.stringHeap;
- this.byteHeap = in.byteHeap;
- this.shortHeap = in.shortHeap;
- this.longHeap = in.longHeap;
-
- this.indexRepository = in.indexRepository;
- this.sofa2indexMap = in.sofa2indexMap;
- this.sofa2tcasMap = in.sofa2tcasMap;
- this.sofa2jcasMap = in.sofa2jcasMap;
- this.sofaNameSet = in.sofaNameSet;
- this.fsClassReg = in.fsClassReg;
- this.featureOffset = in.featureOffset;
- this.fsSpaceReq = in.fsSpaceReq;
- this.creatableType = in.creatableType;
- this.topType = in.topType;
- this.intType = in.intType;
- this.stringType = in.stringType;
- this.floatType = in.floatType;
- this.arrayBaseType = in.arrayBaseType;
- this.intArrayType = in.intArrayType;
- this.floatArrayType = in.floatArrayType;
- this.stringArrayType = in.stringArrayType;
- this.fsArrayType = in.fsArrayType;
- this.annotType = in.annotType;
- this.annotBaseType = in.annotBaseType;
- this.sofaType = in.sofaType;
- this.docType = in.docType;
-
- this.byteType = in.byteType;
- this.byteArrayType = in.byteArrayType;
- this.booleanType = in.booleanType;
- this.booleanArrayType = in.booleanArrayType;
- this.shortType = in.shortType;
- this.shortArrayType = in.shortArrayType;
- this.longType = in.longType;
- this.longArrayType = in.longArrayType;
- this.doubleType = in.doubleType;
- this.doubleArrayType = in.doubleArrayType;
-
- this.flushEnabled = in.flushEnabled;
- initTypeCodeVars();
- // this.jcas = in.jcas;
- }
-
- // CASImpl(TypeSystemImpl typeSystem) {
- // this(typeSystem, DEFAULT_INITIAL_HEAP_SIZE);
- // }
-
-// // Reference existing CAS
-// // For use when creating views of the CAS
-// CASImpl(CAS cas) {
-// this.setCAS(cas);
-// this.useFSCache = false;
-// initTypeVariables();
-// }
-
- public CASImpl(TypeSystemImpl typeSystem, int initialHeapSize) {
- this(typeSystem, initialHeapSize, DEFAULT_USE_FS_CACHE);
- }
-
- CASImpl(TypeSystemImpl typeSystem, int initialHeapSize, boolean useFSCache) {
- super();
- this.useFSCache = useFSCache;
- final boolean externalTypeSystem = (typeSystem != null);
- if (externalTypeSystem) {
- this.ts = typeSystem;
- redoTypeSystemSetup();
- this.ts.setCommitted(true);
- } else {
- this.ts = new TypeSystemImpl();
- setupTSDefault();
- }
- this.initTypeVariables();
- this.heap = new Heap(initialHeapSize);
- initStringTable();
-
- // initial size 16
- this.byteHeap = new ByteHeap();
- this.shortHeap = new ShortHeap();
- this.longHeap = new LongHeap();
-
- if (externalTypeSystem) {
- commitTypeSystem();
- }
- this.sofa2indexMap = new HashMap();
- this.sofa2tcasMap = new HashMap();
- this.sofa2jcasMap = new HashMap();
- this.sofaNameSet = new HashSet();
- this.initialSofaCreated = false;
- this.sofaCount = 0;
- this.baseCAS = this;
- }
+ public void setCAS(CAS cas) {
+ CASImpl in = (CASImpl) cas;
+ this.baseCAS = in;
+ this.ts = in.ts;
+ this.heap = in.heap;
+ this.stringHeap = in.stringHeap;
+ this.byteHeap = in.byteHeap;
+ this.shortHeap = in.shortHeap;
+ this.longHeap = in.longHeap;
+
+ this.indexRepository = in.indexRepository;
+ this.sofa2indexMap = in.sofa2indexMap;
+ this.sofa2tcasMap = in.sofa2tcasMap;
+ this.sofa2jcasMap = in.sofa2jcasMap;
+ this.sofaNameSet = in.sofaNameSet;
+ this.fsClassReg = in.fsClassReg;
+ this.featureOffset = in.featureOffset;
+ this.fsSpaceReq = in.fsSpaceReq;
+ this.creatableType = in.creatableType;
+ this.topType = in.topType;
+ this.intType = in.intType;
+ this.stringType = in.stringType;
+ this.floatType = in.floatType;
+ this.arrayBaseType = in.arrayBaseType;
+ this.intArrayType = in.intArrayType;
+ this.floatArrayType = in.floatArrayType;
+ this.stringArrayType = in.stringArrayType;
+ this.fsArrayType = in.fsArrayType;
+ this.annotType = in.annotType;
+ this.annotBaseType = in.annotBaseType;
+ this.sofaType = in.sofaType;
+ this.docType = in.docType;
+
+ this.byteType = in.byteType;
+ this.byteArrayType = in.byteArrayType;
+ this.booleanType = in.booleanType;
+ this.booleanArrayType = in.booleanArrayType;
+ this.shortType = in.shortType;
+ this.shortArrayType = in.shortArrayType;
+ this.longType = in.longType;
+ this.longArrayType = in.longArrayType;
+ this.doubleType = in.doubleType;
+ this.doubleArrayType = in.doubleArrayType;
+
+ this.flushEnabled = in.flushEnabled;
+ initTypeCodeVars();
+ // this.jcas = in.jcas;
+ }
+
+ // CASImpl(TypeSystemImpl typeSystem) {
+ // this(typeSystem, DEFAULT_INITIAL_HEAP_SIZE);
+ // }
+
+ // // Reference existing CAS
+ // // For use when creating views of the CAS
+ // CASImpl(CAS cas) {
+ // this.setCAS(cas);
+ // this.useFSCache = false;
+ // initTypeVariables();
+ // }
+
+ public CASImpl(TypeSystemImpl typeSystem, int initialHeapSize) {
+ this(typeSystem, initialHeapSize, DEFAULT_USE_FS_CACHE);
+ }
+
+ CASImpl(TypeSystemImpl typeSystem, int initialHeapSize, boolean useFSCache) {
+ super();
+ this.useFSCache = useFSCache;
+ final boolean externalTypeSystem = (typeSystem != null);
+ if (externalTypeSystem) {
+ this.ts = typeSystem;
+ redoTypeSystemSetup();
+ this.ts.setCommitted(true);
+ } else {
+ this.ts = new TypeSystemImpl();
+ setupTSDefault();
+ }
+ this.initTypeVariables();
+ this.heap = new Heap(initialHeapSize);
+ initStringTable();
+
+ // initial size 16
+ this.byteHeap = new ByteHeap();
+ this.shortHeap = new ShortHeap();
+ this.longHeap = new LongHeap();
+
+ if (externalTypeSystem) {
+ commitTypeSystem();
+ }
+ this.sofa2indexMap = new HashMap();
+ this.sofa2tcasMap = new HashMap();
+ this.sofa2jcasMap = new HashMap();
+ this.sofaNameSet = new HashSet();
+ this.initialSofaCreated = false;
+ this.sofaCount = 0;
+ this.baseCAS = this;
+ }
- /**
+ /**
* Constructor. Use only if you want to use the low-level APIs.
*/
- public CASImpl() {
- this(DEFAULT_INITIAL_HEAP_SIZE);
- }
-
- public CASImpl(int initialHeapSize) {
- this((TypeSystemImpl) null, initialHeapSize);
- }
-
- public CASImpl(CASMgrSerializer ser) {
- this();
- this.ts = ser.getTypeSystem();
- commitTypeSystem();
- this.initTypeVariables();
- redoTypeSystemSetup();
- checkInternalCodes(ser);
- // assert(ts != null);
- // assert(getTypeSystem() != null);
- this.setIndexRepository(ser.getIndexRepository(this));
- }
-
- // Use this when creating a CAS view
- CASImpl(CAS cas, SofaFS aSofa) {
-
- this.setCAS(cas);
- this.useFSCache = false;
- initTypeVariables();
-
- // this.mySofa = aSofa;
- if (aSofa != null) {
- // save address of SofaFS
- this.mySofaRef = aSofa.hashCode();
- } else {
- // this is the InitialView
- this.mySofaRef = -1;
- }
-
- initFSClassRegistry();
-
- // get the indexRepository for this Sofa
- this.indexRepository = (this.mySofaRef == -1) ? (FSIndexRepositoryImpl) ((CASImpl) cas)
- .getSofaIndexRepository(1) : (FSIndexRepositoryImpl) ((CASImpl) cas)
- .getSofaIndexRepository(aSofa);
- if (null == this.indexRepository) {
- // create the indexRepository for this CAS
- // use the baseIR to create a lightweight IR copy
- this.indexRepository = new FSIndexRepositoryImpl(this,
- (FSIndexRepositoryImpl) ((CASImpl) cas).getBaseIndexRepository());
- this.indexRepository.commit();
- // save new sofa index
- if (this.mySofaRef == -1) {
- ((CASImpl) cas).setSofaIndexRepository(1, this.indexRepository);
- } else {
- ((CASImpl) cas).setSofaIndexRepository(aSofa, this.indexRepository);
- }
- }
- }
-
- // Use this when creating a CAS view
- protected void refreshView(CAS cas, SofaFS aSofa) {
- this.setCAS(cas);
- if (aSofa != null) {
- // save address of SofaFS
- this.mySofaRef = aSofa.hashCode();
- } else {
- // this is the InitialView
- this.mySofaRef = -1;
- }
-
- // toss the JCas, if it exists
- this.jcas = null;
-
- // create the indexRepository for this Sofa
- this.indexRepository = new FSIndexRepositoryImpl(this,
- (FSIndexRepositoryImpl) ((CASImpl) cas).getBaseIndexRepository());
- this.indexRepository.commit();
- // save new sofa index
- if (this.mySofaRef == -1) {
- ((CASImpl) cas).setSofaIndexRepository(1, this.indexRepository);
- } else {
- ((CASImpl) cas).setSofaIndexRepository(aSofa, this.indexRepository);
- }
- }
-
- private final void initTypeVariables() {
- // Type objects.
- this.topType = (TypeImpl) this.ts.getTopType();
- this.intType = (TypeImpl) this.ts.getType(TYPE_NAME_INTEGER);
- this.stringType = (TypeImpl) this.ts.getType(TYPE_NAME_STRING);
- this.floatType = (TypeImpl) this.ts.getType(TYPE_NAME_FLOAT);
- this.arrayBaseType = (TypeImpl) this.ts.getType(TYPE_NAME_ARRAY_BASE);
- this.intArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_INTEGER_ARRAY);
- this.floatArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_FLOAT_ARRAY);
- this.stringArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_STRING_ARRAY);
- this.fsArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_FS_ARRAY);
- this.sofaType = (TypeImpl) this.ts.getType(TYPE_NAME_SOFA);
- this.annotType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_ANNOTATION);
- this.annotBaseType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_ANNOTATION_BASE);
- this.startFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
- this.endFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_END);
- this.langFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_LANGUAGE);
- this.docType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
-
- this.byteType = (TypeImpl) this.ts.getType(TYPE_NAME_BYTE);
- this.byteArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_BYTE_ARRAY);
- this.booleanType = (TypeImpl) this.ts.getType(TYPE_NAME_BOOLEAN);
- this.booleanArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_BOOLEAN_ARRAY);
- this.shortType = (TypeImpl) this.ts.getType(TYPE_NAME_SHORT);
- this.shortArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_SHORT_ARRAY);
- this.longType = (TypeImpl) this.ts.getType(TYPE_NAME_LONG);
- this.longArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_LONG_ARRAY);
- this.doubleType = (TypeImpl) this.ts.getType(TYPE_NAME_DOUBLE);
- this.doubleArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_DOUBLE_ARRAY);
-
- // Type codes.
- initTypeCodeVars();
- }
-
- private final void initTypeCodeVars() {
- this.intTypeCode = this.intType.getCode();
- this.stringTypeCode = this.stringType.getCode();
- this.floatTypeCode = this.floatType.getCode();
- // this.arrayBaseTypeCode = arrayBaseType.getCode();
- this.intArrayTypeCode = this.intArrayType.getCode();
- this.floatArrayTypeCode = this.floatArrayType.getCode();
- this.stringArrayTypeCode = this.stringArrayType.getCode();
- this.fsArrayTypeCode = this.fsArrayType.getCode();
- this.sofaTypeCode = this.sofaType.getCode();
- this.annotTypeCode = this.annotType.getCode();
- this.annotBaseTypeCode = this.annotBaseType.getCode();
-
- this.byteArrayTypeCode = this.byteArrayType.getCode();
- this.byteTypeCode = this.byteType.getCode();
- this.booleanTypeCode = this.booleanType.getCode();
- this.booleanArrayTypeCode = this.booleanArrayType.getCode();
- this.shortTypeCode = this.shortType.getCode();
- this.shortArrayTypeCode = this.shortArrayType.getCode();
- this.longTypeCode = this.longType.getCode();
- this.longArrayTypeCode = this.longArrayType.getCode();
- this.doubleTypeCode = this.doubleType.getCode();
- this.doubleArrayTypeCode = this.doubleArrayType.getCode();
-
- this.sofaNumFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFANUM));
- this.sofaIdFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAID));
- this.sofaMimeFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAMIME));
- this.sofaUriFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAURI));
- this.sofaArrayFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAARRAY));
- this.annotSofaFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.annotBaseType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_SOFA));
- this.startFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.annotType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN));
- this.endFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.annotType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END));
- this.langFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
- this.docType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE));
- }
-
- private void checkInternalCodes(CASMgrSerializer ser) throws CASAdminException {
- if ((ser.topTypeCode > 0) && (ser.topTypeCode != ((TypeImpl) this.ts.getTopType()).getCode())) {
- throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
- }
- if (ser.featureOffsets == null) {
- return;
- }
- if (ser.featureOffsets.length != this.featureOffset.length) {
- throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
- }
- for (int i = 1; i < ser.featureOffsets.length; i++) {
- if (ser.featureOffsets[i] != this.featureOffset[i]) {
- throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
- }
- }
- }
-
- public void enableReset(boolean flag) {
- this.flushEnabled = flag;
- }
-
- public TypeSystem getTypeSystem() {
- if (this.ts.isCommitted()) {
- return this.ts;
- }
- throw new CASRuntimeException(CASRuntimeException.TYPESYSTEM_NOT_LOCKED);
- }
-
- public ConstraintFactory getConstraintFactory() {
- return ConstraintFactory.instance();
- }
-
- public FeatureStructure createFS(Type type) {
- final int typeCode = ((TypeImpl) type).getCode();
- if (!isCreatableType(typeCode)) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.NON_CREATABLE_TYPE);
- e.addArgument(type.getName());
- e.addArgument("CAS.createFS()");
- throw e;
- }
- final int addr = createTempFS(typeCode);
- final boolean isAnnot = this.ts.subsumes(this.annotBaseTypeCode, typeCode);
- if (isAnnot && this == this.getBaseCAS()) {
- // Can't create annotation on base CAS
- // TODO add new runtime exception for this problem
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.NON_CREATABLE_TYPE);
- e.addArgument(type.getName());
- e.addArgument("CAS.createFS()");
- throw e;
- }
- final FeatureStructure newFS = this.fsClassReg.createFS(addr, this);
- if (isAnnot) {
- final int llsofa = getLowLevelCAS().ll_getFSRef(newFS);
- getLowLevelCAS().ll_setIntValue(llsofa, this.annotSofaFeatCode, this.getSofaRef());
- }
- return newFS;
- }
-
- // public FeatureStructure createPermFS(Type type) {
- // final int addr = createPermFS(((TypeImpl) type).getCode());
- // return getFSClassRegistry().createFS(addr, this);
- // }
-
- public ArrayFS createArrayFS(int length) {
- checkArrayPreconditions(length);
- final int addr = createTempArray(this.fsArrayType.getCode(), length);
- return (ArrayFS) createFS(addr);
- }
-
- public IntArrayFS createIntArrayFS(int length) {
- checkArrayPreconditions(length);
- final int addr = createTempArray(this.intArrayType.getCode(), length);
- return (IntArrayFS) createFS(addr);
- }
-
- public FloatArrayFS createFloatArrayFS(int length) {
- checkArrayPreconditions(length);
- final int addr = createTempArray(this.floatArrayType.getCode(), length);
- return (FloatArrayFS) createFS(addr);
- }
-
- public StringArrayFS createStringArrayFS(int length) {
- checkArrayPreconditions(length);
- final int addr = createTempArray(this.stringArrayType.getCode(), length);
- return (StringArrayFS) createFS(addr);
- }
-
- public final void checkArrayPreconditions(int len) throws CASRuntimeException {
- // Check array size.
- if (len < 0) {
- throw new CASRuntimeException(CASRuntimeException.ILLEGAL_ARRAY_SIZE);
- }
- }
-
- // return true if only one sofa and it is the default text sofa
- public boolean isBackwardCompatibleCas() {
- // check that there is exactly one sofa
- if (this.baseCAS.sofaCount != 1) {
- return false;
- }
-
- if (!this.baseCAS.initialSofaCreated) {
- return false;
- }
- final int llsofa = getLowLevelCAS().ll_getFSRef(this.getInitialView().getSofa());
-
- // check for mime type exactly equal to "text"
- String sofaMime = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaMimeFeatCode);
- if (!"text".equals(sofaMime))
- return false;
- // check that sofaURI and sofaArray are not set
- String sofaUri = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaUriFeatCode);
- if (sofaUri != null)
- return false;
- int sofaArray = getLowLevelCAS().ll_getRefValue(llsofa, this.sofaArrayFeatCode);
- if (sofaArray != CASImpl.NULL)
- return false;
- // check that name is NAME_DEFAULT_SOFA
- String sofaname = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaIdFeatCode);
- return NAME_DEFAULT_SOFA.equals(sofaname);
- }
-
- protected int getBaseSofaCount() {
- return this.baseCAS.sofaCount;
- }
-
- protected FSIndexRepository getSofaIndexRepository(SofaFS aSofa) {
- return getSofaIndexRepository(aSofa.getSofaRef());
- }
-
- protected FSIndexRepository getSofaIndexRepository(int aSofaRef) {
- return (FSIndexRepositoryImpl) this.sofa2indexMap.get(new Integer(aSofaRef));
- }
-
- protected void setSofaIndexRepository(SofaFS aSofa, FSIndexRepository indxRepos) {
- setSofaIndexRepository(aSofa.getSofaRef(), indxRepos);
- }
-
- protected void setSofaIndexRepository(int aSofaRef, FSIndexRepository indxRepos) {
- this.sofa2indexMap.put(new Integer(aSofaRef), indxRepos);
- }
+ public CASImpl() {
+ this(DEFAULT_INITIAL_HEAP_SIZE);
+ }
+
+ public CASImpl(int initialHeapSize) {
+ this((TypeSystemImpl) null, initialHeapSize);
+ }
+
+ public CASImpl(CASMgrSerializer ser) {
+ this();
+ this.ts = ser.getTypeSystem();
+ commitTypeSystem();
+ this.initTypeVariables();
+ redoTypeSystemSetup();
+ checkInternalCodes(ser);
+ // assert(ts != null);
+ // assert(getTypeSystem() != null);
+ this.setIndexRepository(ser.getIndexRepository(this));
+ }
+
+ // Use this when creating a CAS view
+ CASImpl(CAS cas, SofaFS aSofa) {
+
+ this.setCAS(cas);
+ this.useFSCache = false;
+ initTypeVariables();
+
+ // this.mySofa = aSofa;
+ if (aSofa != null) {
+ // save address of SofaFS
+ this.mySofaRef = aSofa.hashCode();
+ } else {
+ // this is the InitialView
+ this.mySofaRef = -1;
+ }
+
+ initFSClassRegistry();
+
+ // get the indexRepository for this Sofa
+ this.indexRepository = (this.mySofaRef == -1) ? (FSIndexRepositoryImpl) ((CASImpl) cas)
+ .getSofaIndexRepository(1) : (FSIndexRepositoryImpl) ((CASImpl) cas)
+ .getSofaIndexRepository(aSofa);
+ if (null == this.indexRepository) {
+ // create the indexRepository for this CAS
+ // use the baseIR to create a lightweight IR copy
+ this.indexRepository = new FSIndexRepositoryImpl(this,
+ (FSIndexRepositoryImpl) ((CASImpl) cas).getBaseIndexRepository());
+ this.indexRepository.commit();
+ // save new sofa index
+ if (this.mySofaRef == -1) {
+ ((CASImpl) cas).setSofaIndexRepository(1, this.indexRepository);
+ } else {
+ ((CASImpl) cas).setSofaIndexRepository(aSofa, this.indexRepository);
+ }
+ }
+ }
+
+ // Use this when creating a CAS view
+ protected void refreshView(CAS cas, SofaFS aSofa) {
+ this.setCAS(cas);
+ if (aSofa != null) {
+ // save address of SofaFS
+ this.mySofaRef = aSofa.hashCode();
+ } else {
+ // this is the InitialView
+ this.mySofaRef = -1;
+ }
+
+ // toss the JCas, if it exists
+ this.jcas = null;
+
+ // create the indexRepository for this Sofa
+ this.indexRepository = new FSIndexRepositoryImpl(this, (FSIndexRepositoryImpl) ((CASImpl) cas)
+ .getBaseIndexRepository());
+ this.indexRepository.commit();
+ // save new sofa index
+ if (this.mySofaRef == -1) {
+ ((CASImpl) cas).setSofaIndexRepository(1, this.indexRepository);
+ } else {
+ ((CASImpl) cas).setSofaIndexRepository(aSofa, this.indexRepository);
+ }
+ }
+
+ private final void initTypeVariables() {
+ // Type objects.
+ this.topType = (TypeImpl) this.ts.getTopType();
+ this.intType = (TypeImpl) this.ts.getType(TYPE_NAME_INTEGER);
+ this.stringType = (TypeImpl) this.ts.getType(TYPE_NAME_STRING);
+ this.floatType = (TypeImpl) this.ts.getType(TYPE_NAME_FLOAT);
+ this.arrayBaseType = (TypeImpl) this.ts.getType(TYPE_NAME_ARRAY_BASE);
+ this.intArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_INTEGER_ARRAY);
+ this.floatArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_FLOAT_ARRAY);
+ this.stringArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_STRING_ARRAY);
+ this.fsArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_FS_ARRAY);
+ this.sofaType = (TypeImpl) this.ts.getType(TYPE_NAME_SOFA);
+ this.annotType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_ANNOTATION);
+ this.annotBaseType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_ANNOTATION_BASE);
+ this.startFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
+ this.endFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_END);
+ this.langFeat = (FeatureImpl) this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_LANGUAGE);
+ this.docType = (TypeImpl) this.ts.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
+
+ this.byteType = (TypeImpl) this.ts.getType(TYPE_NAME_BYTE);
+ this.byteArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_BYTE_ARRAY);
+ this.booleanType = (TypeImpl) this.ts.getType(TYPE_NAME_BOOLEAN);
+ this.booleanArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_BOOLEAN_ARRAY);
+ this.shortType = (TypeImpl) this.ts.getType(TYPE_NAME_SHORT);
+ this.shortArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_SHORT_ARRAY);
+ this.longType = (TypeImpl) this.ts.getType(TYPE_NAME_LONG);
+ this.longArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_LONG_ARRAY);
+ this.doubleType = (TypeImpl) this.ts.getType(TYPE_NAME_DOUBLE);
+ this.doubleArrayType = (TypeImpl) this.ts.getType(TYPE_NAME_DOUBLE_ARRAY);
+
+ // Type codes.
+ initTypeCodeVars();
+ }
+
+ private final void initTypeCodeVars() {
+ this.intTypeCode = this.intType.getCode();
+ this.stringTypeCode = this.stringType.getCode();
+ this.floatTypeCode = this.floatType.getCode();
+ // this.arrayBaseTypeCode = arrayBaseType.getCode();
+ this.intArrayTypeCode = this.intArrayType.getCode();
+ this.floatArrayTypeCode = this.floatArrayType.getCode();
+ this.stringArrayTypeCode = this.stringArrayType.getCode();
+ this.fsArrayTypeCode = this.fsArrayType.getCode();
+ this.sofaTypeCode = this.sofaType.getCode();
+ this.annotTypeCode = this.annotType.getCode();
+ this.annotBaseTypeCode = this.annotBaseType.getCode();
+
+ this.byteArrayTypeCode = this.byteArrayType.getCode();
+ this.byteTypeCode = this.byteType.getCode();
+ this.booleanTypeCode = this.booleanType.getCode();
+ this.booleanArrayTypeCode = this.booleanArrayType.getCode();
+ this.shortTypeCode = this.shortType.getCode();
+ this.shortArrayTypeCode = this.shortArrayType.getCode();
+ this.longTypeCode = this.longType.getCode();
+ this.longArrayTypeCode = this.longArrayType.getCode();
+ this.doubleTypeCode = this.doubleType.getCode();
+ this.doubleArrayTypeCode = this.doubleArrayType.getCode();
+
+ this.sofaNumFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFANUM));
+ this.sofaIdFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAID));
+ this.sofaMimeFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAMIME));
+ this.sofaUriFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAURI));
+ this.sofaArrayFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.sofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFAARRAY));
+ this.annotSofaFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.annotBaseType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_SOFA));
+ this.startFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.annotType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN));
+ this.endFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.annotType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END));
+ this.langFeatCode = ll_getTypeSystem().ll_getCodeForFeature(
+ this.docType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE));
+ }
+
+ private void checkInternalCodes(CASMgrSerializer ser) throws CASAdminException {
+ if ((ser.topTypeCode > 0) && (ser.topTypeCode != ((TypeImpl) this.ts.getTopType()).getCode())) {
+ throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
+ }
+ if (ser.featureOffsets == null) {
+ return;
+ }
+ if (ser.featureOffsets.length != this.featureOffset.length) {
+ throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
+ }
+ for (int i = 1; i < ser.featureOffsets.length; i++) {
+ if (ser.featureOffsets[i] != this.featureOffset[i]) {
+ throw new CASAdminException(CASAdminException.DESERIALIZATION_ERROR);
+ }
+ }
+ }
+
+ public void enableReset(boolean flag) {
+ this.flushEnabled = flag;
+ }
+
+ public TypeSystem getTypeSystem() {
+ if (this.ts.isCommitted()) {
+ return this.ts;
+ }
+ throw new CASRuntimeException(CASRuntimeException.TYPESYSTEM_NOT_LOCKED);
+ }
+
+ public ConstraintFactory getConstraintFactory() {
+ return ConstraintFactory.instance();
+ }
+
+ public FeatureStructure createFS(Type type) {
+ final int typeCode = ((TypeImpl) type).getCode();
+ if (!isCreatableType(typeCode)) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.NON_CREATABLE_TYPE,
+ new String[] { type.getName(), "CAS.createFS()" });
+ throw e;
+ }
+ final int addr = createTempFS(typeCode);
+ final boolean isAnnot = this.ts.subsumes(this.annotBaseTypeCode, typeCode);
+ if (isAnnot && this == this.getBaseCAS()) {
+ // Can't create annotation on base CAS
+ // TODO add new runtime exception for this problem
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.NON_CREATABLE_TYPE,
+ new String[] { type.getName(), "CAS.createFS()" });
+ throw e;
+ }
+ final FeatureStructure newFS = this.fsClassReg.createFS(addr, this);
+ if (isAnnot) {
+ final int llsofa = getLowLevelCAS().ll_getFSRef(newFS);
+ getLowLevelCAS().ll_setIntValue(llsofa, this.annotSofaFeatCode, this.getSofaRef());
+ }
+ return newFS;
+ }
+
+ // public FeatureStructure createPermFS(Type type) {
+ // final int addr = createPermFS(((TypeImpl) type).getCode());
+ // return getFSClassRegistry().createFS(addr, this);
+ // }
+
+ public ArrayFS createArrayFS(int length) {
+ checkArrayPreconditions(length);
+ final int addr = createTempArray(this.fsArrayType.getCode(), length);
+ return (ArrayFS) createFS(addr);
+ }
+
+ public IntArrayFS createIntArrayFS(int length) {
+ checkArrayPreconditions(length);
+ final int addr = createTempArray(this.intArrayType.getCode(), length);
+ return (IntArrayFS) createFS(addr);
+ }
+
+ public FloatArrayFS createFloatArrayFS(int length) {
+ checkArrayPreconditions(length);
+ final int addr = createTempArray(this.floatArrayType.getCode(), length);
+ return (FloatArrayFS) createFS(addr);
+ }
+
+ public StringArrayFS createStringArrayFS(int length) {
+ checkArrayPreconditions(length);
+ final int addr = createTempArray(this.stringArrayType.getCode(), length);
+ return (StringArrayFS) createFS(addr);
+ }
+
+ public final void checkArrayPreconditions(int len) throws CASRuntimeException {
+ // Check array size.
+ if (len < 0) {
+ throw new CASRuntimeException(CASRuntimeException.ILLEGAL_ARRAY_SIZE);
+ }
+ }
+
+ // return true if only one sofa and it is the default text sofa
+ public boolean isBackwardCompatibleCas() {
+ // check that there is exactly one sofa
+ if (this.baseCAS.sofaCount != 1) {
+ return false;
+ }
+
+ if (!this.baseCAS.initialSofaCreated) {
+ return false;
+ }
+ final int llsofa = getLowLevelCAS().ll_getFSRef(this.getInitialView().getSofa());
+
+ // check for mime type exactly equal to "text"
+ String sofaMime = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaMimeFeatCode);
+ if (!"text".equals(sofaMime))
+ return false;
+ // check that sofaURI and sofaArray are not set
+ String sofaUri = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaUriFeatCode);
+ if (sofaUri != null)
+ return false;
+ int sofaArray = getLowLevelCAS().ll_getRefValue(llsofa, this.sofaArrayFeatCode);
+ if (sofaArray != CASImpl.NULL)
+ return false;
+ // check that name is NAME_DEFAULT_SOFA
+ String sofaname = getLowLevelCAS().ll_getStringValue(llsofa, this.sofaIdFeatCode);
+ return NAME_DEFAULT_SOFA.equals(sofaname);
+ }
+
+ protected int getBaseSofaCount() {
+ return this.baseCAS.sofaCount;
+ }
+
+ protected FSIndexRepository getSofaIndexRepository(SofaFS aSofa) {
+ return getSofaIndexRepository(aSofa.getSofaRef());
+ }
+
+ protected FSIndexRepository getSofaIndexRepository(int aSofaRef) {
+ return (FSIndexRepositoryImpl) this.sofa2indexMap.get(new Integer(aSofaRef));
+ }
+
+ protected void setSofaIndexRepository(SofaFS aSofa, FSIndexRepository indxRepos) {
+ setSofaIndexRepository(aSofa.getSofaRef(), indxRepos);
+ }
+
+ protected void setSofaIndexRepository(int aSofaRef, FSIndexRepository indxRepos) {
+ this.sofa2indexMap.put(new Integer(aSofaRef), indxRepos);
+ }
- /**
+ /**
* @deprecated
*/
- public SofaFS createSofa(SofaID sofaID, String mimeType) {
- // extract absolute SofaName string from the ID
- return createSofa(sofaID.getSofaID(), mimeType);
- }
-
- protected SofaFS createSofa(String sofaName, String mimeType) {
- final int addr = createTempFS(this.sofaTypeCode);
- final FeatureStructure sofa = this.fsClassReg.createFS(addr, this);
- addSofa(sofa, sofaName, mimeType);
- return (SofaFS) sofa;
- }
-
- protected SofaFS createInitialSofa(String mimeType) {
- final int addr = createTempFS(this.sofaTypeCode);
- final FeatureStructure sofa = this.fsClassReg.createFS(addr, this);
- final int llsofa = getLowLevelCAS().ll_getFSRef(sofa);
- getLowLevelCAS().ll_setIntValue(llsofa, this.sofaNumFeatCode, 1);
- addSofa(sofa, CAS.NAME_DEFAULT_SOFA, mimeType);
- registerInitialSofa();
- this.mySofaRef = sofa.hashCode();
- return (SofaFS) sofa;
- }
-
- protected void registerInitialSofa() {
- this.baseCAS.initialSofaCreated = true;
- }
-
- protected boolean isInitialSofaCreated() {
- return this.baseCAS.initialSofaCreated;
- }
-
- // Internal use only
- public void addSofa(FeatureStructure sofa, String sofaName, String mimeType) {
- if (this.baseCAS.sofaNameSet.contains(sofaName)) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_ALREADY_EXISTS);
- e.addArgument(sofaName);
- throw e;
- }
- final int llsofa = getLowLevelCAS().ll_getFSRef(sofa);
- if (0 == getLowLevelCAS().ll_getIntValue(llsofa, this.sofaNumFeatCode)) {
- getLowLevelCAS().ll_setIntValue(llsofa, this.sofaNumFeatCode, ++this.baseCAS.sofaCount);
- }
- getLowLevelCAS().ll_setStringValue(llsofa, this.sofaIdFeatCode, sofaName);
- getLowLevelCAS().ll_setStringValue(llsofa, this.sofaMimeFeatCode, mimeType);
- this.getBaseIndexRepository().addFS(sofa);
- this.baseCAS.sofaNameSet.add(sofaName);
- }
+ public SofaFS createSofa(SofaID sofaID, String mimeType) {
+ // extract absolute SofaName string from the ID
+ return createSofa(sofaID.getSofaID(), mimeType);
+ }
+
+ protected SofaFS createSofa(String sofaName, String mimeType) {
+ final int addr = createTempFS(this.sofaTypeCode);
+ final FeatureStructure sofa = this.fsClassReg.createFS(addr, this);
+ addSofa(sofa, sofaName, mimeType);
+ return (SofaFS) sofa;
+ }
+
+ protected SofaFS createInitialSofa(String mimeType) {
+ final int addr = createTempFS(this.sofaTypeCode);
+ final FeatureStructure sofa = this.fsClassReg.createFS(addr, this);
+ final int llsofa = getLowLevelCAS().ll_getFSRef(sofa);
+ getLowLevelCAS().ll_setIntValue(llsofa, this.sofaNumFeatCode, 1);
+ addSofa(sofa, CAS.NAME_DEFAULT_SOFA, mimeType);
+ registerInitialSofa();
+ this.mySofaRef = sofa.hashCode();
+ return (SofaFS) sofa;
+ }
+
+ protected void registerInitialSofa() {
+ this.baseCAS.initialSofaCreated = true;
+ }
+
+ protected boolean isInitialSofaCreated() {
+ return this.baseCAS.initialSofaCreated;
+ }
+
+ // Internal use only
+ public void addSofa(FeatureStructure sofa, String sofaName, String mimeType) {
+ if (this.baseCAS.sofaNameSet.contains(sofaName)) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_ALREADY_EXISTS,
+ new String[] { sofaName });
+ throw e;
+ }
+ final int llsofa = getLowLevelCAS().ll_getFSRef(sofa);
+ if (0 == getLowLevelCAS().ll_getIntValue(llsofa, this.sofaNumFeatCode)) {
+ getLowLevelCAS().ll_setIntValue(llsofa, this.sofaNumFeatCode, ++this.baseCAS.sofaCount);
+ }
+ getLowLevelCAS().ll_setStringValue(llsofa, this.sofaIdFeatCode, sofaName);
+ getLowLevelCAS().ll_setStringValue(llsofa, this.sofaMimeFeatCode, mimeType);
+ this.getBaseIndexRepository().addFS(sofa);
+ this.baseCAS.sofaNameSet.add(sofaName);
+ }
- /**
+ /**
* @deprecated
*/
- public SofaFS getSofa(SofaID sofaID) {
- // extract absolute SofaName string from the ID
- return getSofa(sofaID.getSofaID());
- }
-
- private SofaFS getSofa(String sofaName) {
- FSIterator iterator = this.baseCAS.getSofaIterator();
- while (iterator.isValid()) {
- SofaFS sofa = (SofaFS) iterator.get();
- if (sofaName.equals(getStringValue(sofa.hashCode(), this.sofaIdFeatCode))) {
- return sofa;
- }
- iterator.moveToNext();
- }
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_NOT_FOUND);
- e.addArgument(sofaName);
- throw e;
- }
-
- protected SofaFS getSofa(int sofaRef) {
- SofaFS aSofa = (SofaFS) this.ll_getFSForRef(sofaRef);
- if (aSofa == null) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFAREF_NOT_FOUND);
- throw e;
- }
- return aSofa;
- }
-
- public CASImpl getBaseCAS() {
- return this.baseCAS;
- }
-
- public FSIterator getSofaIterator() {
- FSIndex sofaIndex = this.baseCAS.indexRepository.getIndex(CAS.SOFA_INDEX_NAME);
- return sofaIndex.iterator();
- }
-
- // For internal use only
- public void setSofaFeat(int addr, int sofa) {
- setFeatureValue(addr, this.annotSofaFeatCode, sofa);
- }
-
- // For internal use only
- public int getSofaFeat(int addr) {
- return getFeatureValue(addr, this.annotSofaFeatCode);
- }
-
- // For internal use only
- public int getSofaRef() {
- if (this.mySofaRef == -1) {
- // create the SofaFS for _InitialView ...
- // ... and reset mySofaRef to point to it
- this.mySofaRef = this.createInitialSofa(null).hashCode();
- }
- return this.mySofaRef;
- }
-
- // For internal use only
- public InputStream getSofaDataStream(SofaFS aSofa) {
- try {
-
- if (null != aSofa.getLocalStringData()) {
- ByteArrayInputStream bis = new ByteArrayInputStream(aSofa.getLocalStringData().getBytes(
- "UTF-8"));
- return bis;
- } else if (null != aSofa.getLocalFSData()) {
- FeatureStructureImpl fs = (FeatureStructureImpl) aSofa.getLocalFSData();
-
- int arrayStart = 0;
- int arraySize = this.getArraySize(fs.getAddress());
- ByteBuffer buf = null;
- Type type = fs.getType();
- if (type.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) {
- arrayStart = getArrayStartAddress(fs.getAddress());
- buf = ByteBuffer.allocate(arraySize * 4);
- IntBuffer intbuf = buf.asIntBuffer();
- intbuf.put(this.heap.heap, arrayStart, arraySize);
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
- arrayStart = getArrayStartAddress(fs.getAddress());
- buf = ByteBuffer.allocate(arraySize * 4);
- FloatBuffer floatbuf = buf.asFloatBuffer();
- float[] floatArray = new float[arraySize];
- for (int i = arrayStart; i < arrayStart + arraySize; i++) {
- floatArray[i - arrayStart] = Float.intBitsToFloat(this.heap.heap[i]);
- }
- floatbuf.put(floatArray);
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY)
- || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
- arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
- buf = ByteBuffer.allocate(arraySize);
- buf.put(this.byteHeap.heap, arrayStart, arraySize);
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
- arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
- buf = ByteBuffer.allocate(arraySize * 2);
- ShortBuffer shortbuf = buf.asShortBuffer();
- shortbuf.put(this.shortHeap.heap, arrayStart, arraySize);
-
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
- arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
- buf = ByteBuffer.allocate(arraySize * 8);
- LongBuffer longbuf = buf.asLongBuffer();
- longbuf.put(this.longHeap.heap, arrayStart, arraySize);
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- } else if (type.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
- arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
- buf = ByteBuffer.allocate(arraySize * 8);
- DoubleBuffer doublebuf = buf.asDoubleBuffer();
- double[] doubleArray = new double[arraySize];
- for (int i = arrayStart; i < arrayStart + arraySize; i++) {
- doubleArray[i - arrayStart] = Double.longBitsToDouble(this.longHeap.heap[i]);
- }
- doublebuf.put(doubleArray);
- ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
- return bis;
- }
-
- } else if (null != aSofa.getSofaURI()) {
- URL url = new URL(aSofa.getSofaURI());
- return url.openStream();
- } else {
- return null;
- }
- } catch (MalformedURLException exc) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR);
- e.addArgument(exc.getMessage());
- throw e;
- } catch (CASRuntimeException exc) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR);
- e.addArgument(exc.getMessage());
- throw e;
- } catch (IOException exc) {
- CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR);
- e.addArgument(exc.getMessage());
- throw e;
- }
- return null;
- }
-
- public FSIterator createFilteredIterator(FSIterator it, FSMatchConstraint cons) {
- return new FilteredIterator(it, cons);
- }
-
- public void commitTypeSystem() {
- this.ts.commit();
- redoTypeSystemSetup();
- initFSClassRegistry();
- // After the type system has been committed, we can create the
- // index repository.
- createIndexRepository();
- }
-
- private void createIndexRepository() {
- if (!this.getTypeSystemMgr().isCommitted()) {
- throw new CASAdminException(CASAdminException.MUST_COMMIT_TYPE_SYSTEM);
- }
- if (this.indexRepository == null) {
- this.indexRepository = new FSIndexRepositoryImpl(this);
- }
- }
-
- public FSIndexRepositoryMgr getIndexRepositoryMgr() {
- // assert(this.cas.getIndexRepository() != null);
- return this.indexRepository;
- }
+ public SofaFS getSofa(SofaID sofaID) {
+ // extract absolute SofaName string from the ID
+ return getSofa(sofaID.getSofaID());
+ }
+
+ private SofaFS getSofa(String sofaName) {
+ FSIterator iterator = this.baseCAS.getSofaIterator();
+ while (iterator.isValid()) {
+ SofaFS sofa = (SofaFS) iterator.get();
+ if (sofaName.equals(getStringValue(sofa.hashCode(), this.sofaIdFeatCode))) {
+ return sofa;
+ }
+ iterator.moveToNext();
+ }
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_NOT_FOUND,
+ new String[] { sofaName });
+ throw e;
+ }
+
+ protected SofaFS getSofa(int sofaRef) {
+ SofaFS aSofa = (SofaFS) this.ll_getFSForRef(sofaRef);
+ if (aSofa == null) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFAREF_NOT_FOUND);
+ throw e;
+ }
+ return aSofa;
+ }
+
+ public CASImpl getBaseCAS() {
+ return this.baseCAS;
+ }
+
+ public FSIterator getSofaIterator() {
+ FSIndex sofaIndex = this.baseCAS.indexRepository.getIndex(CAS.SOFA_INDEX_NAME);
+ return sofaIndex.iterator();
+ }
+
+ // For internal use only
+ public void setSofaFeat(int addr, int sofa) {
+ setFeatureValue(addr, this.annotSofaFeatCode, sofa);
+ }
+
+ // For internal use only
+ public int getSofaFeat(int addr) {
+ return getFeatureValue(addr, this.annotSofaFeatCode);
+ }
+
+ // For internal use only
+ public int getSofaRef() {
+ if (this.mySofaRef == -1) {
+ // create the SofaFS for _InitialView ...
+ // ... and reset mySofaRef to point to it
+ this.mySofaRef = this.createInitialSofa(null).hashCode();
+ }
+ return this.mySofaRef;
+ }
+
+ // For internal use only
+ public InputStream getSofaDataStream(SofaFS aSofa) {
+ try {
+
+ if (null != aSofa.getLocalStringData()) {
+ ByteArrayInputStream bis = new ByteArrayInputStream(aSofa.getLocalStringData().getBytes(
+ "UTF-8"));
+ return bis;
+ } else if (null != aSofa.getLocalFSData()) {
+ FeatureStructureImpl fs = (FeatureStructureImpl) aSofa.getLocalFSData();
+
+ int arrayStart = 0;
+ int arraySize = this.getArraySize(fs.getAddress());
+ ByteBuffer buf = null;
+ Type type = fs.getType();
+ if (type.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) {
+ arrayStart = getArrayStartAddress(fs.getAddress());
+ buf = ByteBuffer.allocate(arraySize * 4);
+ IntBuffer intbuf = buf.asIntBuffer();
+ intbuf.put(this.heap.heap, arrayStart, arraySize);
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
+ arrayStart = getArrayStartAddress(fs.getAddress());
+ buf = ByteBuffer.allocate(arraySize * 4);
+ FloatBuffer floatbuf = buf.asFloatBuffer();
+ float[] floatArray = new float[arraySize];
+ for (int i = arrayStart; i < arrayStart + arraySize; i++) {
+ floatArray[i - arrayStart] = Float.intBitsToFloat(this.heap.heap[i]);
+ }
+ floatbuf.put(floatArray);
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY)
+ || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
+ arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
+ buf = ByteBuffer.allocate(arraySize);
+ buf.put(this.byteHeap.heap, arrayStart, arraySize);
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
+ arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
+ buf = ByteBuffer.allocate(arraySize * 2);
+ ShortBuffer shortbuf = buf.asShortBuffer();
+ shortbuf.put(this.shortHeap.heap, arrayStart, arraySize);
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
+ arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
+ buf = ByteBuffer.allocate(arraySize * 8);
+ LongBuffer longbuf = buf.asLongBuffer();
+ longbuf.put(this.longHeap.heap, arrayStart, arraySize);
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ } else if (type.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
+ arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
+ buf = ByteBuffer.allocate(arraySize * 8);
+ DoubleBuffer doublebuf = buf.asDoubleBuffer();
+ double[] doubleArray = new double[arraySize];
+ for (int i = arrayStart; i < arrayStart + arraySize; i++) {
+ doubleArray[i - arrayStart] = Double.longBitsToDouble(this.longHeap.heap[i]);
+ }
+ doublebuf.put(doubleArray);
+ ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
+ return bis;
+ }
+
+ } else if (null != aSofa.getSofaURI()) {
+ URL url = new URL(aSofa.getSofaURI());
+ return url.openStream();
+ } else {
+ return null;
+ }
+ } catch (MalformedURLException exc) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR,
+ new String[] { exc.getMessage() });
+ throw e;
+ } catch (CASRuntimeException exc) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR,
+ new String[] { exc.getMessage() });
+ throw e;
+ } catch (IOException exc) {
+ CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFADATASTREAM_ERROR,
+ new String[] { exc.getMessage() });
+ throw e;
+ }
+ return null;
+ }
+
+ public FSIterator createFilteredIterator(FSIterator it, FSMatchConstraint cons) {
+ return new FilteredIterator(it, cons);
+ }
+
+ public void commitTypeSystem() {
+ this.ts.commit();
+ redoTypeSystemSetup();
+ initFSClassRegistry();
+ // After the type system has been committed, we can create the
+ // index repository.
+ createIndexRepository();
+ }
+
+ private void createIndexRepository() {
+ if (!this.getTypeSystemMgr().isCommitted()) {
+ throw new CASAdminException(CASAdminException.MUST_COMMIT_TYPE_SYSTEM);
+ }
+ if (this.indexRepository == null) {
+ this.indexRepository = new FSIndexRepositoryImpl(this);
+ }
+ }
+
+ public FSIndexRepositoryMgr getIndexRepositoryMgr() {
+ // assert(this.cas.getIndexRepository() != null);
+ return this.indexRepository;
+ }
- /**
+ /**
* @deprecated
*/
- public void commitFS(FeatureStructure fs) {
- getIndexRepository().addFS(fs);
- }
+ public void commitFS(FeatureStructure fs) {
+ getIndexRepository().addFS(fs);
+ }
- public FeaturePath createFeaturePath() {
- return new FeaturePathImpl();
- }
+ public FeaturePath createFeaturePath() {
+ return new FeaturePathImpl();
+ }
- // Implement the ConstraintFactory interface.
+ // Implement the ConstraintFactory interface.
- /**
+ /**
* @see org.apache.uima.cas.admin.CASMgr#getTypeSystemMgr()
*/
- public TypeSystemMgr getTypeSystemMgr() {
- return this.ts;
- }
-
- public void reset() {
- if (!this.flushEnabled) {
- throw new CASAdminException(CASAdminException.FLUSH_DISABLED);
- }
- if (this == this.baseCAS) {
- resetNoQuestions();
- return;
- }
- // called from a CAS view.
- // clear CAS ...
- this.baseCAS.resetNoQuestions();
- }
-
- private void resetView() {
- this.indexRepository.flush();
- this.documentText = null;
- if (this.mySofaRef > 0 && this.getSofa().getSofaRef() == 1) {
- // indicate no Sofa exists for the initial view
- this.mySofaRef = -1;
- } else {
- this.mySofaRef = 0;
- }
- if (this.jcas != null) {
- try {
- JCasImpl.clearData(this);
- } catch (CASException e) {
- CASAdminException cae = new CASAdminException(CASAdminException.JCAS_ERROR);
- cae.addArgument(e.getMessage());
- throw cae;
- }
- }
- }
-
- public void resetNoQuestions() {
- int numViews = this.getBaseSofaCount();
- // Flush indexRepository for all Sofa
- for (int view = 1; view <= numViews; view++) {
- CAS tcas = (view == 1) ? getInitialView() : getView(view);
- if (tcas != null) {
- ((CASImpl) tcas).resetView();
- }
- }
- if (this.heap.getCurrentTempSize() > this.resetHeapSize) {
- this.heap.resetTempHeap(true);
- resetStringTable(true);
- } else {
- this.heap.resetTempHeap(false);
- resetStringTable(false);
- }
-
- this.byteHeap.reset();
- this.shortHeap.reset();
- this.longHeap.reset();
-
- this.indexRepository.flush();
- this.baseCAS.sofaNameSet.clear();
- this.initialSofaCreated = false;
- // always an Initial View now!!!
- this.sofaCount = 1;
-
- if (null != this.fsClassReg) {
- // TODO figure out why this is needed
- this.fsClassReg.flush();
- }
- if (this.jcas != null) {
- try {
- JCasImpl.clearData(this);
- } catch (CASException e) {
- CASAdminException cae = new CASAdminException(CASAdminException.JCAS_ERROR);
- cae.addArgument(e.getMessage());
- throw cae;
- }
- }
- }
+ public TypeSystemMgr getTypeSystemMgr() {
+ return this.ts;
+ }
+
+ public void reset() {
+ if (!this.flushEnabled) {
+ throw new CASAdminException(CASAdminException.FLUSH_DISABLED);
+ }
+ if (this == this.baseCAS) {
+ resetNoQuestions();
+ return;
+ }
+ // called from a CAS view.
+ // clear CAS ...
+ this.baseCAS.resetNoQuestions();
+ }
+
+ private void resetView() {
+ this.indexRepository.flush();
+ this.documentText = null;
+ if (this.mySofaRef > 0 && this.getSofa().getSofaRef() == 1) {
+ // indicate no Sofa exists for the initial view
+ this.mySofaRef = -1;
+ } else {
+ this.mySofaRef = 0;
+ }
+ if (this.jcas != null) {
+ try {
+ JCasImpl.clearData(this);
+ } catch (CASException e) {
+ CASAdminException cae = new CASAdminException(CASAdminException.JCAS_ERROR);
+ cae.addArgument(e.getMessage());
+ throw cae;
+ }
+ }
+ }
+
+ public void resetNoQuestions() {
+ int numViews = this.getBaseSofaCount();
+ // Flush indexRepository for all Sofa
+ for (int view = 1; view <= numViews; view++) {
+ CAS tcas = (view == 1) ? getInitialView() : getView(view);
+ if (tcas != null) {
+ ((CASImpl) tcas).resetView();
+ }
+ }
+ if (this.heap.getCurrentTempSize() > this.resetHeapSize) {
+ this.heap.resetTempHeap(true);
+ resetStringTable(true);
+ } else {
+ this.heap.resetTempHeap(false);
+ resetStringTable(false);
+ }
+
+ this.byteHeap.reset();
+ this.shortHeap.reset();
+ this.longHeap.reset();
+
+ this.indexRepository.flush();
+ this.baseCAS.sofaNameSet.clear();
+ this.initialSofaCreated = false;
+ // always an Initial View now!!!
+ this.sofaCount = 1;
+
+ if (null != this.fsClassReg) {
+ // TODO figure out why this is needed
+ this.fsClassReg.flush();
+ }
+ if (this.jcas != null) {
+ try {
+ JCasImpl.clearData(this);
+ } catch (CASException e) {
+ CASAdminException cae = new CASAdminException(CASAdminException.JCAS_ERROR);
+ cae.addArgument(e.getMessage());
+ throw cae;
+ }
+ }
+ }
- /**
+ /**
* @deprecated Use {@link #reset reset()}instead.
*/
- public void flush() {
- reset();
- }
-
- /**
- *
- */
- public FSIndexRepository getIndexRepository() {
- if (this == this.baseCAS) {
- // BaseCas has no indexes for users
- return null;
- }
- if (this.indexRepository.isCommitted()) {
- return this.indexRepository;
- }
- return null;
- }
-
- protected FSIndexRepository getBaseIndexRepository() {
- if (this.baseCAS.indexRepository.isCommitted()) {
- return this.baseCAS.indexRepository;
- }
- return null;
- }
-
- protected void addSofaFsToIndex(SofaFS sofa) {
- this.baseCAS.getBaseIndexRepository().addFS(sofa);
- }
-
- protected void registerView(SofaFS aSofa) {
- this.mySofaRef = aSofa.hashCode();
- }
-
- public void reinit(CASSerializer ser) {
- if (this != this.baseCAS) {
- this.baseCAS.reinit(ser);
- return;
- }
- this.resetNoQuestions();
- reinit(ser.getHeapMetadata(), ser.getHeapArray(), ser.getStringTable(), ser.getFSIndex(), ser
- .getByteArray(), ser.getShortArray(), ser.getLongArray());
- }
+ public void flush() {
+ reset();
+ }
+
+ /**
+ *
+ */
+ public FSIndexRepository getIndexRepository() {
+ if (this == this.baseCAS) {
+ // BaseCas has no indexes for users
+ return null;
+ }
+ if (this.indexRepository.isCommitted()) {
+ return this.indexRepository;
+ }
+ return null;
+ }
+
+ protected FSIndexRepository getBaseIndexRepository() {
+ if (this.baseCAS.indexRepository.isCommitted()) {
+ return this.baseCAS.indexRepository;
+ }
+ return null;
+ }
+
+ protected void addSofaFsToIndex(SofaFS sofa) {
+ this.baseCAS.getBaseIndexRepository().addFS(sofa);
+ }
+
+ protected void registerView(SofaFS aSofa) {
+ this.mySofaRef = aSofa.hashCode();
+ }
+
+ public void reinit(CASSerializer ser) {
+ if (this != this.baseCAS) {
+ this.baseCAS.reinit(ser);
+ return;
+ }
+ this.resetNoQuestions();
+ reinit(ser.getHeapMetadata(), ser.getHeapArray(), ser.getStringTable(), ser.getFSIndex(), ser
+ .getByteArray(), ser.getShortArray(), ser.getLongArray());
+ }
- /**
+ /**
* @see org.apache.uima.cas.CAS#fs2listIterator(FSIterator)
*/
- public ListIterator fs2listIterator(FSIterator it) {
- return new FSListIteratorImpl(it);
- }
+ public ListIterator fs2listIterator(FSIterator it) {
+ return new FSListIteratorImpl(it);
+ }
- /**
+ /**
* @see org.apache.uima.cas.admin.CASMgr#getCAS()
*/
- public CAS getCAS() {
- if (this.indexRepository.isCommitted()) {
- return this;
- }
- throw new CASAdminException(CASAdminException.MUST_COMMIT_INDEX_REPOSITORY);
- }
-
- void resetStringTable() {
- this.resetStringTable(false);
- }
-
- void resetStringTable(boolean doFullReset) {
- this.stringHeap.reset(doFullReset);
- }
-
- private void initStringTable() {
- this.stringHeap = new StringHeap();
- }
-
- public void setFSClassRegistry(FSClassRegistry fsClassReg) {
- this.fsClassReg = fsClassReg;
- }
-
- void initFSClassRegistry() {
- // System.out.println("Initializing FSClassRegistry");
- this.fsClassReg = new FSClassRegistry(this.ts, this.useFSCache);
- this.fsClassReg.addClassForType(this.fsArrayType, new ArrayFSGenerator());
- this.fsClassReg.addClassForType(this.intArrayType, IntArrayFSImpl.generator());
- this.fsClassReg.addClassForType(this.floatArrayType, FloatArrayFSImpl.generator());
- this.fsClassReg.addClassForType(this.stringArrayType, StringArrayFSImpl.generator());
- this.fsClassReg.addClassForType(this.sofaType, SofaFSImpl.getSofaFSGenerator());
- this.fsClassReg
- .addClassForType(this.annotBaseType, AnnotationBaseImpl.getAnnotationGenerator());
- this.fsClassReg.addClassForType(this.annotType, AnnotationImpl.getAnnotationGenerator());
- this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_BYTE_ARRAY),
- ByteArrayFSImpl.generator());
- this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_BOOLEAN_ARRAY),
- BooleanArrayFSImpl.generator());
- this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_SHORT_ARRAY),
- ShortArrayFSImpl.generator());
- this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_LONG_ARRAY),
- LongArrayFSImpl.generator());
- this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_DOUBLE_ARRAY),
- DoubleArrayFSImpl.generator());
-
- // assert(fsClassReg != null);
- }
-
- public FSClassRegistry getFSClassRegistry() // for JCas integration
- {
- return this.fsClassReg;
- }
-
- private void initCreatableTypeTable() {
- this.creatableType = new boolean[this.ts.getTypeArraySize()];
- Arrays.fill(this.creatableType, true);
- int typeCode;
- for (int i = 0; i < nonCreatableTypes.length; i++) {
- typeCode = ((TypeImpl) this.ts.getType(nonCreatableTypes[i])).getCode();
- for (int subType = this.ts.getSmallestType(); subType < this.creatableType.length; subType++) {
- if (this.ts.subsumes(typeCode, subType)) {
- this.creatableType[subType] = false;
- }
- }
- }
- }
-
- void setIndexRepository(FSIndexRepositoryImpl ir) {
- this.indexRepository = ir;
- }
-
- public void reinit(CASCompleteSerializer casCompSer) {
- if (this != this.baseCAS) {
- this.baseCAS.reinit(casCompSer);
- return;
- }
- this.ts = casCompSer.getCASMgrSerializer().getTypeSystem();
- commitTypeSystem();
- this.initTypeVariables();
- this.redoTypeSystemSetup();
-
- // reset index repositories -- wipes out Sofa index
- this.indexRepository = casCompSer.getCASMgrSerializer().getIndexRepository(this);
- this.indexRepository.commit();
-
- // get handle to existing initial View
- CAS initialView = (CAS) this.getInitialView();
-
- // throw away all other View information as the CAS definition may have changed
- this.sofa2indexMap.clear();
- this.sofa2tcasMap.clear();
- this.sofaCount = 0;
-
- // freshen the initial view
- ((CASImpl) initialView).refreshView(this.baseCAS, null);
- this.sofa2tcasMap.put(new Integer(1), initialView);
- this.baseCAS.sofaCount = 1;
-
- // deserialize heap
- CASSerializer casSer = casCompSer.getCASSerializer();
- reinit(casSer.getHeapMetadata(), casSer.getHeapArray(), casSer.getStringTable(), casSer
- .getFSIndex(), casSer.getByteArray(), casSer.getShortArray(), casSer.getLongArray());
-
- // we also need to throw away the JCAS. A new JCAS will be created on
- // the next
- // call to getJCas(). As with the CAS, we are counting on the fact that
- // this happens only in a service, where JCAS handles are not held on
- // to.
- this.jcas = null;
- this.sofa2jcasMap.clear();
- }
-
- void reinit(int[] heapMetadata, int[] heapArray, String[] stringTable, int[] fsIndex,
- byte[] byteHeapArray, short[] shortHeapArray, long[] longHeapArray) {
- createStringTableFromArray(stringTable);
- this.heap.reinit(heapMetadata, heapArray);
- if (byteHeapArray != null)
- this.byteHeap.reinit(byteHeapArray);
- if (shortHeapArray != null)
- this.shortHeap.reinit(shortHeapArray);
- if (longHeapArray != null)
- this.longHeap.reinit(longHeapArray);
+ public CAS getCAS() {
+ if (this.indexRepository.isCommitted()) {
+ return this;
+ }
+ throw new CASAdminException(CASAdminException.MUST_COMMIT_INDEX_REPOSITORY);
+ }
+
+ void resetStringTable() {
+ this.resetStringTable(false);
+ }
+
+ void resetStringTable(boolean doFullReset) {
+ this.stringHeap.reset(doFullReset);
+ }
+
+ private void initStringTable() {
+ this.stringHeap = new StringHeap();
+ }
+
+ public void setFSClassRegistry(FSClassRegistry fsClassReg) {
+ this.fsClassReg = fsClassReg;
+ }
+
+ void initFSClassRegistry() {
+ // System.out.println("Initializing FSClassRegistry");
+ this.fsClassReg = new FSClassRegistry(this.ts, this.useFSCache);
+ this.fsClassReg.addClassForType(this.fsArrayType, new ArrayFSGenerator());
+ this.fsClassReg.addClassForType(this.intArrayType, IntArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(this.floatArrayType, FloatArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(this.stringArrayType, StringArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(this.sofaType, SofaFSImpl.getSofaFSGenerator());
+ this.fsClassReg
+ .addClassForType(this.annotBaseType, AnnotationBaseImpl.getAnnotationGenerator());
+ this.fsClassReg.addClassForType(this.annotType, AnnotationImpl.getAnnotationGenerator());
+ this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_BYTE_ARRAY),
+ ByteArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_BOOLEAN_ARRAY),
+ BooleanArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_SHORT_ARRAY),
+ ShortArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_LONG_ARRAY),
+ LongArrayFSImpl.generator());
+ this.fsClassReg.addClassForType(getTypeSystem().getType(CAS.TYPE_NAME_DOUBLE_ARRAY),
+ DoubleArrayFSImpl.generator());
+
+ // assert(fsClassReg != null);
+ }
+
+ public FSClassRegistry getFSClassRegistry() // for JCas integration
+ {
+ return this.fsClassReg;
+ }
+
+ private void initCreatableTypeTable() {
+ this.creatableType = new boolean[this.ts.getTypeArraySize()];
+ Arrays.fill(this.creatableType, true);
+ int typeCode;
+ for (int i = 0; i < nonCreatableTypes.length; i++) {
+ typeCode = ((TypeImpl) this.ts.getType(nonCreatableTypes[i])).getCode();
+ for (int subType = this.ts.getSmallestType(); subType < this.creatableType.length; subType++) {
+ if (this.ts.subsumes(typeCode, subType)) {
+ this.creatableType[subType] = false;
+ }
+ }
+ }
+ }
+
+ void setIndexRepository(FSIndexRepositoryImpl ir) {
+ this.indexRepository = ir;
+ }
+
+ public void reinit(CASCompleteSerializer casCompSer) {
+ if (this != this.baseCAS) {
+ this.baseCAS.reinit(casCompSer);
+ return;
+ }
+ this.ts = casCompSer.getCASMgrSerializer().getTypeSystem();
+ commitTypeSystem();
+ this.initTypeVariables();
+ this.redoTypeSystemSetup();
+
+ // reset index repositories -- wipes out Sofa index
+ this.indexRepository = casCompSer.getCASMgrSerializer().getIndexRepository(this);
+ this.indexRepository.commit();
+
+ // get handle to existing initial View
+ CAS initialView = this.getInitialView();
+
+ // throw away all other View information as the CAS definition may have changed
+ this.sofa2indexMap.clear();
+ this.sofa2tcasMap.clear();
+ this.sofaCount = 0;
+
+ // freshen the initial view
+ ((CASImpl) initialView).refreshView(this.baseCAS, null);
+ this.sofa2tcasMap.put(new Integer(1), initialView);
+ this.baseCAS.sofaCount = 1;
+
+ // deserialize heap
+ CASSerializer casSer = casCompSer.getCASSerializer();
+ reinit(casSer.getHeapMetadata(), casSer.getHeapArray(), casSer.getStringTable(), casSer
+ .getFSIndex(), casSer.getByteArray(), casSer.getShortArray(), casSer.getLongArray());
+
+ // we also need to throw away the JCAS. A new JCAS will be created on
+ // the next
+ // call to getJCas(). As with the CAS, we are counting on the fact that
+ // this happens only in a service, where JCAS handles are not held on
+ // to.
+ this.jcas = null;
+ this.sofa2jcasMap.clear();
+ }
+
+ void reinit(int[] heapMetadata, int[] heapArray, String[] stringTable, int[] fsIndex,
+ byte[] byteHeapArray, short[] shortHeapArray, long[] longHeapArray) {
+ createStringTableFromArray(stringTable);
+ this.heap.reinit(heapMetadata, heapArray);
+ if (byteHeapArray != null)
+ this.byteHeap.reinit(byteHeapArray);
+ if (shortHeapArray != null)
+ this.shortHeap.reinit(shortHeapArray);
+ if (longHeapArray != null)
+ this.longHeap.reinit(longHeapArray);
- reinitIndexedFSs(fsIndex);
- }
+ reinitIndexedFSs(fsIndex);
+ }
- /**
+ /**
* --------------------------------------------------------------------- Blob Format
*
* Element Size Number of Description (bytes) Elements ------------ ---------
@@ -1287,330 +1285,329 @@
* @param istream
* @throws CASRuntimeException
*/
- public void reinit(InputStream istream) throws CASRuntimeException {
- if (this != this.baseCAS) {
- this.baseCAS.reinit(istream);
- return;
- }
- this.resetNoQuestions();
- DataInputStream dis = new DataInputStream(istream);
-
- try {
- // key
- // deteremine if byte swap if needed based on key
- byte[] bytebuf = new byte[4];
- bytebuf[0] = dis.readByte();
- bytebuf[1] = dis.readByte();
- bytebuf[2] = dis.readByte();
- bytebuf[3] = dis.readByte();
-
- boolean swap = false;
- // check if first byte is ascii char U
- if (bytebuf[0] != 65) {
- swap = true;
- }
-
- // version
- // NOTE: even though nothing ever uses the version (yet), we MUST
- // read it
- // from the stream or else subsequent reads will not work. So that's
- // why
- // we are reading here and not assigning to any variable.
- if (swap) {
- swap4(dis, bytebuf);
- } else {
- dis.readInt();
- }
-
- // main fsheap
- int fsheapsz = 0;
- if (swap) {
- fsheapsz = swap4(dis, bytebuf);
- } else {
- fsheapsz = dis.readInt();
- }
-
- this.heap.reinitSizeOnly(fsheapsz);
- for (int i = 0; i < fsheapsz; i++) {
- if (swap) {
- this.heap.heap[i] = swap4(dis, bytebuf);
- } else {
- this.heap.heap[i] = dis.readInt();
- }
- }
-
- // string heap
- int stringheapsz = 0;
- if (swap) {
- stringheapsz = swap4(dis, bytebuf);
- } else {
- stringheapsz = dis.readInt();
- }
-
- this.stringHeap.stringHeap = new char[stringheapsz];
- for (int i = 0; i < stringheapsz; i++) {
- if (swap) {
- this.stringHeap.stringHeap[i] = swap2(dis, bytebuf);
- } else {
- this.stringHeap.stringHeap[i] = dis.readChar();
- }
- }
- this.stringHeap.charHeapPos = stringheapsz;
-
- // word alignment
- if (stringheapsz % 2 != 0) {
- dis.readChar();
- }
-
- // string ref heap
- int refheapsz = 0;
- if (swap) {
- refheapsz = swap4(dis, bytebuf);
- } else {
- refheapsz = dis.readInt();
- }
-
- refheapsz--;
- refheapsz = refheapsz / 2;
- refheapsz = refheapsz * 3;
-
- // read back into references consisting to three ints
- // --stringheap offset,length, stringlist offset
- this.stringHeap.refHeap = new int[StringHeap.FIRST_CELL_REF + refheapsz];
-
- dis.readInt(); // 0
- for (int i = this.stringHeap.refHeapPos; i < this.stringHeap.refHeap.length; i += StringHeap.REF_HEAP_CELL_SIZE) {
- if (swap) {
- this.stringHeap.refHeap[i + StringHeap.CHAR_HEAP_POINTER_OFFSET] = swap4(dis, bytebuf);
- this.stringHeap.refHeap[i + StringHeap.CHAR_HEAP_STRLEN_OFFSET] = swap4(dis, bytebuf);
- } else {
- this.stringHeap.refHeap[i + StringHeap.CHAR_HEAP_POINTER_OFFSET] = dis.readInt();
- this.stringHeap.refHeap[i + StringHeap.CHAR_HEAP_STRLEN_OFFSET] = dis.readInt();
- }
- this.stringHeap.refHeap[i + StringHeap.STRING_LIST_ADDR_OFFSET] = 0;
- }
- this.stringHeap.refHeapPos = refheapsz;
-
- // indexed FSs
- int fsindexsz = 0;
- if (swap) {
- fsindexsz = swap4(dis, bytebuf);
- } else {
- fsindexsz = dis.readInt();
- }
- int[] fsindexes = new int[fsindexsz];
- for (int i = 0; i < fsindexsz; i++) {
- if (swap) {
- fsindexes[i] = swap4(dis, bytebuf);
- } else {
- fsindexes[i] = dis.readInt();
- }
- }
-
- // build the index
- reinitIndexedFSs(fsindexes);
-
- // byte heap
- int byteheapsz = 0;
- if (swap) {
- byteheapsz = swap4(dis, bytebuf);
- } else {
- byteheapsz = dis.readInt();
- }
-
- this.byteHeap.heap = new byte[Math.max(16, byteheapsz)]; // must
- // be >
- // 0
- for (int i = 0; i < byteheapsz; i++) {
- this.byteHeap.heap[i] = dis.readByte();
- }
- this.byteHeap.heapPos = byteheapsz;
-
- // word alignment
- int align = byteheapsz % 4;
- for (int i = 0; i < align; i++) {
- dis.readByte();
- }
-
- // short heap
- int shortheapsz = 0;
- if (swap) {
- shortheapsz = swap4(dis, bytebuf);
- } else {
- shortheapsz = dis.readInt();
- }
- this.shortHeap.heap = new short[Math.max(16, shortheapsz)]; // must
- // be >
- // 0
- for (int i = 0; i < shortheapsz; i++) {
- if (swap) {
- this.shortHeap.heap[i] = (short) swap2(dis, bytebuf);
- } else {
- this.shortHeap.heap[i] = dis.readShort();
- }
- }
- this.shortHeap.heapPos = shortheapsz;
-
- // word alignment
- if (shortheapsz % 2 != 0) {
- dis.readChar();
- }
-
- // long heap
- int longheapsz = 0;
- if (swap) {
- longheapsz = swap4(dis, bytebuf);
- bytebuf = new byte[8];
- } else {
- longheapsz = dis.readInt();
- }
- this.longHeap.heap = new long[Math.max(16, longheapsz)]; // must
- // be >
- // 0
- for (int i = 0; i < longheapsz; i++) {
- if (swap) {
- this.longHeap.heap[i] = swap8(dis, bytebuf);
- } else {
- this.longHeap.heap[i] = dis.readLong();
- }
- }
- this.longHeap.heapPos = longheapsz;
-
- } catch (IOException e) {
- CASRuntimeException exception = new CASRuntimeException(
- CASRuntimeException.BLOB_DESERIALIZATION);
- exception.addArgument(e.getMessage());
- throw exception;
- }
- }
-
- private long swap8(DataInputStream dis, byte[] buf) throws IOException {
-
- buf[7] = dis.readByte();
- buf[6] = dis.readByte();
- buf[5] = dis.readByte();
- buf[4] = dis.readByte();
- buf[3] = dis.readByte();
- buf[2] = dis.readByte();
- buf[1] = dis.readByte();
- buf[0] = dis.readByte();
- ByteBuffer bb = ByteBuffer.wrap(buf);
- return bb.getLong();
- }
-
- private int swap4(DataInputStream dis, byte[] buf) throws IOException {
- buf[3] = dis.readByte();
- buf[2] = dis.readByte();
- buf[1] = dis.readByte();
- buf[0] = dis.readByte();
- ByteBuffer bb = ByteBuffer.wrap(buf);
- return bb.getInt();
- }
-
- private char swap2(DataInputStream dis, byte[] buf) throws IOException {
- buf[1] = dis.readByte();
- buf[0] = dis.readByte();
- ByteBuffer bb = ByteBuffer.wrap(buf, 0, 2);
- return bb.getChar();
- }
-
- private void reinitIndexedFSs(int[] fsIndex) {
- // Add FSs to index repository for base CAS
- int numViews = fsIndex[0];
- int loopLen = fsIndex[1];
- for (int i = 2; i < loopLen + 2; i++) {
- this.indexRepository.addFS(fsIndex[i]);
- }
- int loopStart = loopLen + 2;
-
- FSIterator iterator = this.baseCAS.getSofaIterator();
- final Feature idFeat = getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFAID);
- // Add FSs to index repository for each View
- while (iterator.isValid()) {
- SofaFS sofa = (SofaFS) iterator.get();
- String id = getLowLevelCAS().ll_getStringValue(sofa.hashCode(),
- ((FeatureImpl) idFeat).getCode());
- this.sofaNameSet.add(id);
- if (CAS.NAME_DEFAULT_SOFA.equals(id)) {
- this.registerInitialSofa();
- } else {
- // only bump count if not the initial view
- this.baseCAS.sofaCount++;
- }
- ((CASImpl) this.getView(sofa)).registerView(sofa);
- iterator.moveToNext();
- }
- for (int view = 1; view <= numViews; view++) {
- CAS tcas = (view == 1) ? getInitialView() : getView(view);
- if (tcas != null) {
- FSIndexRepositoryImpl loopIndexRep = (FSIndexRepositoryImpl) getSofaIndexRepository(view);
- loopLen = fsIndex[loopStart];
- for (int i = loopStart + 1; i < loopStart + 1 + loopLen; i++) {
- loopIndexRep.addFS(fsIndex[i]);
- }
- loopStart += loopLen + 1;
- ((CASImpl) tcas).updateDocumentAnnotation();
- } else {
- loopStart += 1;
- }
- }
- }
-
- // IndexedFSs format:
- // number of views
- // number of sofas
- // [sofa-1 ... sofa-n]
- // number of FS indexed in View1
- // [FS-1 ... FS-n]
- // etc.
- int[] getIndexedFSs() {
- IntVector v = new IntVector();
- int[] fsLoopIndex;
-
- int numViews = this.getBaseSofaCount();
- v.add(numViews);
-
- // Get indexes for base CAS
- fsLoopIndex = this.baseCAS.indexRepository.getIndexedFSs();
- v.add(fsLoopIndex.length);
- for (int k = 0; k < fsLoopIndex.length; k++) {
- v.add(fsLoopIndex[k]);
- }
-
- // Get indexes for each SofaFS in the CAS
- for (int sofaNum = 1; sofaNum <= numViews; sofaNum++) {
- FSIndexRepositoryImpl loopIndexRep = (FSIndexRepositoryImpl) this.baseCAS
- .getSofaIndexRepository(sofaNum);
- if (loopIndexRep != null)
- fsLoopIndex = loopIndexRep.getIndexedFSs();
- else
- fsLoopIndex = (new IntVector()).toArray();
- v.add(fsLoopIndex.length);
- for (int k = 0; k < fsLoopIndex.length; k++) {
- v.add(fsLoopIndex[k]);
- }
- }
- return v.toArray();
- }
-
- void createStringTableFromArray(String[] stringTable) {
- // why a new heap instead of reseting the old one???
- // this.stringHeap = new StringHeap();
- this.stringHeap.reset();
- for (int i = 1; i < stringTable.length; i++) {
- this.stringHeap.addString(stringTable[i]);
- }
- }
-
- static String mapName(String name, HashMap map) {
- String out = (String) map.get(name);
- if (out != null) {
- return out;
- }
- return name;
- }
+ public void reinit(InputStream istream) throws CASRuntimeException {
+ if (this != this.baseCAS) {
+ this.baseCAS.reinit(istream);
+ return;
+ }
+ this.resetNoQuestions();
+ DataInputStream dis = new DataInputStream(istream);
+
+ try {
+ // key
+ // deteremine if byte swap if needed based on key
+ byte[] bytebuf = new byte[4];
+ bytebuf[0] = dis.readByte();
+ bytebuf[1] = dis.readByte();
+ bytebuf[2] = dis.readByte();
+ bytebuf[3] = dis.readByte();
+
+ boolean swap = false;
+ // check if first byte is ascii char U
+ if (bytebuf[0] != 65) {
+ swap = true;
+ }
+
+ // version
+ // NOTE: even though nothing ever uses the version (yet), we MUST
+ // read it
[... 4631 lines stripped ...]