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 2008/08/30 00:11:30 UTC
svn commit: r690405 [20/26] - in /incubator/uima/uimaj/trunk/uimaj-core: ./
src/main/java/org/apache/uima/
src/main/java/org/apache/uima/analysis_component/
src/main/java/org/apache/uima/analysis_engine/
src/main/java/org/apache/uima/analysis_engine/an...
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/OperationalProperties_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ProcessingResourceMetaData_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/PropertyXmlInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ResourceManagerConfiguration_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ResourceMetaData_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/SimplePrecondition_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/TypeDescription_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/TypePriorities_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/TypePriorityList_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/TypeSystemDescription_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/XmlizationInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/service/impl/ResourceServiceAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/service/impl/ResourceService_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/Attribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/Filter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/IndexBuildItem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/IndexBuildSpecification.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/IndexRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/IndexingException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/Mapping.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/Style.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/Attribute_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/Filter_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/IndexBuildItem_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/IndexBuildSpecification_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/IndexRule_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/Mapping_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/Style_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/impl/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/search/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/CppUimajEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/UimacppAnalysisComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/UimacppEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/uimacpp/UimacppException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/AnalysisEnginePerformanceReports.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/AnalysisEngineUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java?rev=690405&r1=690404&r2=690405&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java Fri Aug 29 15:10:52 2008
@@ -1,408 +1,408 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.uima.util;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.uima.UIMARuntimeException;
-import org.apache.uima.cas.ArrayFS;
-import org.apache.uima.cas.BooleanArrayFS;
-import org.apache.uima.cas.ByteArrayFS;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.CASRuntimeException;
-import org.apache.uima.cas.DoubleArrayFS;
-import org.apache.uima.cas.FSIndex;
-import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.cas.FloatArrayFS;
-import org.apache.uima.cas.IntArrayFS;
-import org.apache.uima.cas.LongArrayFS;
-import org.apache.uima.cas.ShortArrayFS;
-import org.apache.uima.cas.SofaFS;
-import org.apache.uima.cas.StringArrayFS;
-import org.apache.uima.cas.Type;
-import org.apache.uima.cas.impl.CASImpl;
-import org.apache.uima.cas.impl.LowLevelCAS;
-import org.apache.uima.cas.text.AnnotationFS;
-
-/**
- * Utility class for doing deep copies of FeatureStructures from one CAS to another. To handle cases
- * where the source CAS has multiple references to the same FS, you can create one instance of
- * CasCopier and use it to copy multiple FeatureStructures. The CasCopier will remember previously
- * copied FeatureStructures, so if you later copy another FS that has a reference to a previously
- * copied FS, it will not duplicate the multiply-referenced FS.
- */
-public class CasCopier {
- private CAS mSrcCas;
- private CAS mDestCas;
- private LowLevelCAS mLowLevelDestCas;
- private Feature mDestSofaFeature;
-
- private Map mFsMap = new HashMap();
-
- /**
- * Creates a new CasCopier that can be used to copy FeatureStructures from one CAS to another.
- * Note that if you are merging data from multiple CASes, you must create a new CasCopier
- * for each source CAS.
- *
- * @param aSrcCas
- * the CAS to copy from.
- * @param aDestCas
- * the CAS to copy into.
- */
- public CasCopier(CAS aSrcCas, CAS aDestCas) {
- mSrcCas = aSrcCas;
- mDestCas = aDestCas;
- mLowLevelDestCas = aDestCas.getLowLevelCAS();
- mDestSofaFeature = aDestCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA);
- }
-
- /**
- * Does a complete deep copy of one CAS into another CAS. The contents of each view
- * in the source CAS will be copied to the same-named view in the destination CAS. If
- * the view does not already exist it will be created. All FeatureStructures that are
- * indexed in a view in the source CAS will become indexed in the same-named view in the
- * destination CAS.
- *
- * @param aSrcCas
- * the CAS to copy from
- * @param aDestCas
- * the CAS to copy to
- * @param aCopySofa
- * if true, the sofa data and mimeType of each view will be copied. If false they will not.
- */
- public static void copyCas(CAS aSrcCas, CAS aDestCas, boolean aCopySofa) {
- CasCopier copier = new CasCopier(aSrcCas, aDestCas);
-
- Iterator sofaIter = aSrcCas.getSofaIterator();
- while (sofaIter.hasNext()) {
- SofaFS sofa = ((SofaFS)sofaIter.next());
- CAS view = aSrcCas.getView(sofa);
- copier.copyCasView(view, aCopySofa);
- }
- }
-
- /**
- * Does a deep copy of the contents of one CAS View into another CAS.
- * If a view with the same name as <code>aSrcCasView</code> exists in the destination CAS,
- * then it will be the target of the copy. Otherwise, a new view will be created with
- * that name and will become the target of the copy. All FeatureStructures that are indexed
- * in the source CAS view will become indexed in the target view.
- *
- * @param aSrcCasView
- * the CAS to copy from
- * @param aCopySofa
- * if true, the sofa data and mimeType will be copied. If false they will not.
- */
- public void copyCasView(CAS aSrcCasView, boolean aCopySofa) {
- //get or create the target view
- CAS targetView = getOrCreateView(mDestCas, aSrcCasView.getViewName());
-
- if (aCopySofa) {
- // can't copy the SofaFS - just copy the sofa data and mime type
- String sofaMime = aSrcCasView.getSofa().getSofaMime();
- if (aSrcCasView.getDocumentText() != null) {
- targetView.setSofaDataString(aSrcCasView.getDocumentText(), sofaMime);
- } else if (aSrcCasView.getSofaDataURI() != null) {
- targetView.setSofaDataURI(aSrcCasView.getSofaDataURI(), sofaMime);
- } else if (aSrcCasView.getSofaDataArray() != null) {
- targetView.setSofaDataArray(copyFs(aSrcCasView.getSofaDataArray()), sofaMime);
- }
- }
-
- // now copy indexed FS, but keep track so we don't index anything more than once
- Set indexedFs = new HashSet();
- Iterator indexes = aSrcCasView.getIndexRepository().getIndexes();
- while (indexes.hasNext()) {
- FSIndex index = (FSIndex) indexes.next();
- Iterator iter = index.iterator();
- while (iter.hasNext()) {
- FeatureStructure fs = (FeatureStructure) iter.next();
- if (!indexedFs.contains(fs)) {
- FeatureStructure copyOfFs = copyFs(fs);
- //check for annotations with null Sofa reference - this can happen
- //if the annotations were created with the Low Level CAS API. If the
- //Sofa reference isn't set, attempting to add the FS to the indexes
- //will fail.
- if (fs instanceof AnnotationFS) {
- FeatureStructure sofa =((AnnotationFS)copyOfFs).getFeatureValue(mDestSofaFeature);
- if (sofa == null) {
- copyOfFs.setFeatureValue(mDestSofaFeature, targetView.getSofa());
- }
- }
- // also don't index the DocumentAnnotation (it's indexed by default)
- if (!isDocumentAnnotation(copyOfFs)) {
- targetView.addFsToIndexes(copyOfFs);
- }
- indexedFs.add(fs);
- }
- }
- }
- }
-
-
- /**
- * Copies an FS from the source CAS to the destination CAS. Also copies any referenced FS, except
- * that previously copied FS will not be copied again.
- *
- * @param aFS
- * the FS to copy. Must be contained within the source CAS.
- * @return the copy of <code>aFS</code> in the target CAS.
- */
- public FeatureStructure copyFs(FeatureStructure aFS) {
- //FS must be in the source CAS
- assert ((CASImpl)aFS.getCAS()).getBaseCAS() == ((CASImpl)mSrcCas).getBaseCAS();
-
- // check if we already copied this FS
- FeatureStructure copy = (FeatureStructure) mFsMap.get(aFS);
- if (copy != null)
- return copy;
-
- // get the type of the FS
- Type srcType = aFS.getType();
-
- // Certain types need to be handled specially
-
- // Sofa - cannot be created by normal methods. Instead, we return the Sofa with the
- // same Sofa ID in the target CAS. If it does not exist it will be created.
- if (aFS instanceof SofaFS) {
- String sofaId = ((SofaFS)aFS).getSofaID();
- return getOrCreateView(mDestCas, sofaId).getSofa();
- }
-
- // DocumentAnnotation - instead of creating a new instance, reuse the automatically created
- // instance in the destination view.
- if (isDocumentAnnotation(aFS)) {
- String viewName = ((AnnotationFS)aFS).getView().getViewName();
- CAS destView = mDestCas.getView(viewName);
- FeatureStructure destDocAnnot = destView.getDocumentAnnotation();
- if (destDocAnnot != null) {
- copyFeatures(aFS, destDocAnnot);
- }
- return destDocAnnot;
- }
-
- // Arrays - need to be created a populated differently than "normal" FS
- if (aFS.getType().isArray()) {
- copy = copyArray(aFS);
- mFsMap.put(aFS, copy);
- return copy;
- }
-
- // create a new FS of the same type in the target CAS
- // TODO: could optimize type lookup if type systems are identical
- Type destType = mDestCas.getTypeSystem().getType(srcType.getName());
- if (destType == null) {
- throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
- new Object[] { srcType.getName() });
- }
- //We need to use the LowLevel CAS interface to create the FS, because the usual
- //CAS.createFS() call doesn't allow us to create subtypes of AnnotationBase from
- //a base CAS. In any case we don't need the Sofa reference to be automatically
- //set because we'll set it manually when in the copyFeatures method.
- int typeCode = mLowLevelDestCas.ll_getTypeSystem().ll_getCodeForType(destType);
- int destFsAddr = mLowLevelDestCas.ll_createFS(typeCode);
- FeatureStructure destFs = mDestCas.getLowLevelCAS().ll_getFSForRef(destFsAddr);
-
- // add to map so we don't try to copy this more than once
- mFsMap.put(aFS, destFs);
-
- copyFeatures(aFS, destFs);
- return destFs;
- }
-
- /**
- * Copy feature values from one FS to another. For reference-valued features, this does a deep
- * copy.
- *
- * @param aSrcFS
- * FeatureStructure to copy from
- * @param aDestFS
- * FeatureStructure to copy to
- */
- private void copyFeatures(FeatureStructure aSrcFS, FeatureStructure aDestFS) {
- // set feature values
- Type srcType = aSrcFS.getType();
- Type destType = aDestFS.getType();
- Iterator srcFeatIter = srcType.getFeatures().iterator();
- while (srcFeatIter.hasNext()) {
- Feature srcFeat = (Feature) srcFeatIter.next();
- // TODO: could optimize type lookup if type systems are identical
- Feature destFeat;
- if (destType == aSrcFS.getType()) {
- // sharing same type system, so destFeat == srcFeat
- destFeat = srcFeat;
- } else {
- // not sharing same type system, so do a name loop up in destination type system
- destFeat = destType.getFeatureByBaseName(srcFeat.getShortName());
- if (destFeat == null) {
- throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
- new Object[] { srcFeat.getName() });
- }
- }
-
- // copy primitive values using their string representation
- // TODO: could be optimized but this code would be very messy if we have to
- // enumerate all possible primitive types. Maybe LowLevel CAS API could help?
- if (srcFeat.getRange().isPrimitive()) {
- aDestFS.setFeatureValueFromString(destFeat, aSrcFS.getFeatureValueAsString(srcFeat));
- } else {
- // recursive copy
- FeatureStructure refFS = aSrcFS.getFeatureValue(srcFeat);
- if (refFS != null) {
- FeatureStructure copyRefFs = copyFs(refFS);
- aDestFS.setFeatureValue(destFeat, copyRefFs);
- }
- }
- }
- }
-
- /**
- * Returns whether the given FS has already been copied using this CasCopier.
- *
- * @param aFS
- * @return
- */
- public boolean alreadyCopied(FeatureStructure aFS) {
- return mFsMap.containsKey(aFS);
- }
-
- /**
- * @param arrayFS
- * @return
- */
- private FeatureStructure copyArray(FeatureStructure aSrcFs) {
- // TODO: there should be a way to do this without enumerating all the array types!
- if (aSrcFs instanceof StringArrayFS) {
- StringArrayFS arrayFs = (StringArrayFS) aSrcFs;
- int len = arrayFs.size();
- StringArrayFS destFS = mDestCas.createStringArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof IntArrayFS) {
- IntArrayFS arrayFs = (IntArrayFS) aSrcFs;
- int len = arrayFs.size();
- IntArrayFS destFS = mDestCas.createIntArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof ByteArrayFS) {
- ByteArrayFS arrayFs = (ByteArrayFS) aSrcFs;
- int len = arrayFs.size();
- ByteArrayFS destFS = mDestCas.createByteArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof ShortArrayFS) {
- ShortArrayFS arrayFs = (ShortArrayFS) aSrcFs;
- int len = arrayFs.size();
- ShortArrayFS destFS = mDestCas.createShortArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof LongArrayFS) {
- LongArrayFS arrayFs = (LongArrayFS) aSrcFs;
- int len = arrayFs.size();
- LongArrayFS destFS = mDestCas.createLongArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof FloatArrayFS) {
- FloatArrayFS arrayFs = (FloatArrayFS) aSrcFs;
- int len = arrayFs.size();
- FloatArrayFS destFS = mDestCas.createFloatArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof DoubleArrayFS) {
- DoubleArrayFS arrayFs = (DoubleArrayFS) aSrcFs;
- int len = arrayFs.size();
- DoubleArrayFS destFS = mDestCas.createDoubleArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof BooleanArrayFS) {
- BooleanArrayFS arrayFs = (BooleanArrayFS) aSrcFs;
- int len = arrayFs.size();
- BooleanArrayFS destFS = mDestCas.createBooleanArrayFS(len);
- for (int i = 0; i < len; i++) {
- destFS.set(i, arrayFs.get(i));
- }
- return destFS;
- }
- if (aSrcFs instanceof ArrayFS) {
- ArrayFS arrayFs = (ArrayFS) aSrcFs;
- int len = arrayFs.size();
- ArrayFS destFS = mDestCas.createArrayFS(len);
- for (int i = 0; i < len; i++) {
- FeatureStructure srcElem = arrayFs.get(i);
- if (srcElem != null) {
- FeatureStructure copyElem = copyFs(arrayFs.get(i));
- destFS.set(i, copyElem);
- }
- }
- return destFS;
- }
- assert false; // the set of array types should be exhaustive, so we should never get here
- return null;
- }
-
- /**
- * Gets the named view; if the view doesn't exist it will be created.
- */
- private static CAS getOrCreateView(CAS aCas, String aViewName) {
- //TODO: there should be some way to do this without the try...catch
- try {
- return aCas.getView(aViewName);
- }
- catch(CASRuntimeException e) {
- //create the view
- return aCas.createView(aViewName);
- }
- }
-
- /**
- * Determines whether the given FS is the DocumentAnnotation for its view.
- * This is more than just a type check; we actually check if it is the one "special"
- * DocumentAnnotation that CAS.getDocumentAnnotation() would return.
- */
- private static boolean isDocumentAnnotation(FeatureStructure aFS) {
- return (aFS instanceof AnnotationFS) &&
- aFS.equals(((AnnotationFS)aFS).getView().getDocumentAnnotation());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.uima.UIMARuntimeException;
+import org.apache.uima.cas.ArrayFS;
+import org.apache.uima.cas.BooleanArrayFS;
+import org.apache.uima.cas.ByteArrayFS;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASRuntimeException;
+import org.apache.uima.cas.DoubleArrayFS;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.FloatArrayFS;
+import org.apache.uima.cas.IntArrayFS;
+import org.apache.uima.cas.LongArrayFS;
+import org.apache.uima.cas.ShortArrayFS;
+import org.apache.uima.cas.SofaFS;
+import org.apache.uima.cas.StringArrayFS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.LowLevelCAS;
+import org.apache.uima.cas.text.AnnotationFS;
+
+/**
+ * Utility class for doing deep copies of FeatureStructures from one CAS to another. To handle cases
+ * where the source CAS has multiple references to the same FS, you can create one instance of
+ * CasCopier and use it to copy multiple FeatureStructures. The CasCopier will remember previously
+ * copied FeatureStructures, so if you later copy another FS that has a reference to a previously
+ * copied FS, it will not duplicate the multiply-referenced FS.
+ */
+public class CasCopier {
+ private CAS mSrcCas;
+ private CAS mDestCas;
+ private LowLevelCAS mLowLevelDestCas;
+ private Feature mDestSofaFeature;
+
+ private Map mFsMap = new HashMap();
+
+ /**
+ * Creates a new CasCopier that can be used to copy FeatureStructures from one CAS to another.
+ * Note that if you are merging data from multiple CASes, you must create a new CasCopier
+ * for each source CAS.
+ *
+ * @param aSrcCas
+ * the CAS to copy from.
+ * @param aDestCas
+ * the CAS to copy into.
+ */
+ public CasCopier(CAS aSrcCas, CAS aDestCas) {
+ mSrcCas = aSrcCas;
+ mDestCas = aDestCas;
+ mLowLevelDestCas = aDestCas.getLowLevelCAS();
+ mDestSofaFeature = aDestCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA);
+ }
+
+ /**
+ * Does a complete deep copy of one CAS into another CAS. The contents of each view
+ * in the source CAS will be copied to the same-named view in the destination CAS. If
+ * the view does not already exist it will be created. All FeatureStructures that are
+ * indexed in a view in the source CAS will become indexed in the same-named view in the
+ * destination CAS.
+ *
+ * @param aSrcCas
+ * the CAS to copy from
+ * @param aDestCas
+ * the CAS to copy to
+ * @param aCopySofa
+ * if true, the sofa data and mimeType of each view will be copied. If false they will not.
+ */
+ public static void copyCas(CAS aSrcCas, CAS aDestCas, boolean aCopySofa) {
+ CasCopier copier = new CasCopier(aSrcCas, aDestCas);
+
+ Iterator sofaIter = aSrcCas.getSofaIterator();
+ while (sofaIter.hasNext()) {
+ SofaFS sofa = ((SofaFS)sofaIter.next());
+ CAS view = aSrcCas.getView(sofa);
+ copier.copyCasView(view, aCopySofa);
+ }
+ }
+
+ /**
+ * Does a deep copy of the contents of one CAS View into another CAS.
+ * If a view with the same name as <code>aSrcCasView</code> exists in the destination CAS,
+ * then it will be the target of the copy. Otherwise, a new view will be created with
+ * that name and will become the target of the copy. All FeatureStructures that are indexed
+ * in the source CAS view will become indexed in the target view.
+ *
+ * @param aSrcCasView
+ * the CAS to copy from
+ * @param aCopySofa
+ * if true, the sofa data and mimeType will be copied. If false they will not.
+ */
+ public void copyCasView(CAS aSrcCasView, boolean aCopySofa) {
+ //get or create the target view
+ CAS targetView = getOrCreateView(mDestCas, aSrcCasView.getViewName());
+
+ if (aCopySofa) {
+ // can't copy the SofaFS - just copy the sofa data and mime type
+ String sofaMime = aSrcCasView.getSofa().getSofaMime();
+ if (aSrcCasView.getDocumentText() != null) {
+ targetView.setSofaDataString(aSrcCasView.getDocumentText(), sofaMime);
+ } else if (aSrcCasView.getSofaDataURI() != null) {
+ targetView.setSofaDataURI(aSrcCasView.getSofaDataURI(), sofaMime);
+ } else if (aSrcCasView.getSofaDataArray() != null) {
+ targetView.setSofaDataArray(copyFs(aSrcCasView.getSofaDataArray()), sofaMime);
+ }
+ }
+
+ // now copy indexed FS, but keep track so we don't index anything more than once
+ Set indexedFs = new HashSet();
+ Iterator indexes = aSrcCasView.getIndexRepository().getIndexes();
+ while (indexes.hasNext()) {
+ FSIndex index = (FSIndex) indexes.next();
+ Iterator iter = index.iterator();
+ while (iter.hasNext()) {
+ FeatureStructure fs = (FeatureStructure) iter.next();
+ if (!indexedFs.contains(fs)) {
+ FeatureStructure copyOfFs = copyFs(fs);
+ //check for annotations with null Sofa reference - this can happen
+ //if the annotations were created with the Low Level CAS API. If the
+ //Sofa reference isn't set, attempting to add the FS to the indexes
+ //will fail.
+ if (fs instanceof AnnotationFS) {
+ FeatureStructure sofa =((AnnotationFS)copyOfFs).getFeatureValue(mDestSofaFeature);
+ if (sofa == null) {
+ copyOfFs.setFeatureValue(mDestSofaFeature, targetView.getSofa());
+ }
+ }
+ // also don't index the DocumentAnnotation (it's indexed by default)
+ if (!isDocumentAnnotation(copyOfFs)) {
+ targetView.addFsToIndexes(copyOfFs);
+ }
+ indexedFs.add(fs);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Copies an FS from the source CAS to the destination CAS. Also copies any referenced FS, except
+ * that previously copied FS will not be copied again.
+ *
+ * @param aFS
+ * the FS to copy. Must be contained within the source CAS.
+ * @return the copy of <code>aFS</code> in the target CAS.
+ */
+ public FeatureStructure copyFs(FeatureStructure aFS) {
+ //FS must be in the source CAS
+ assert ((CASImpl)aFS.getCAS()).getBaseCAS() == ((CASImpl)mSrcCas).getBaseCAS();
+
+ // check if we already copied this FS
+ FeatureStructure copy = (FeatureStructure) mFsMap.get(aFS);
+ if (copy != null)
+ return copy;
+
+ // get the type of the FS
+ Type srcType = aFS.getType();
+
+ // Certain types need to be handled specially
+
+ // Sofa - cannot be created by normal methods. Instead, we return the Sofa with the
+ // same Sofa ID in the target CAS. If it does not exist it will be created.
+ if (aFS instanceof SofaFS) {
+ String sofaId = ((SofaFS)aFS).getSofaID();
+ return getOrCreateView(mDestCas, sofaId).getSofa();
+ }
+
+ // DocumentAnnotation - instead of creating a new instance, reuse the automatically created
+ // instance in the destination view.
+ if (isDocumentAnnotation(aFS)) {
+ String viewName = ((AnnotationFS)aFS).getView().getViewName();
+ CAS destView = mDestCas.getView(viewName);
+ FeatureStructure destDocAnnot = destView.getDocumentAnnotation();
+ if (destDocAnnot != null) {
+ copyFeatures(aFS, destDocAnnot);
+ }
+ return destDocAnnot;
+ }
+
+ // Arrays - need to be created a populated differently than "normal" FS
+ if (aFS.getType().isArray()) {
+ copy = copyArray(aFS);
+ mFsMap.put(aFS, copy);
+ return copy;
+ }
+
+ // create a new FS of the same type in the target CAS
+ // TODO: could optimize type lookup if type systems are identical
+ Type destType = mDestCas.getTypeSystem().getType(srcType.getName());
+ if (destType == null) {
+ throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
+ new Object[] { srcType.getName() });
+ }
+ //We need to use the LowLevel CAS interface to create the FS, because the usual
+ //CAS.createFS() call doesn't allow us to create subtypes of AnnotationBase from
+ //a base CAS. In any case we don't need the Sofa reference to be automatically
+ //set because we'll set it manually when in the copyFeatures method.
+ int typeCode = mLowLevelDestCas.ll_getTypeSystem().ll_getCodeForType(destType);
+ int destFsAddr = mLowLevelDestCas.ll_createFS(typeCode);
+ FeatureStructure destFs = mDestCas.getLowLevelCAS().ll_getFSForRef(destFsAddr);
+
+ // add to map so we don't try to copy this more than once
+ mFsMap.put(aFS, destFs);
+
+ copyFeatures(aFS, destFs);
+ return destFs;
+ }
+
+ /**
+ * Copy feature values from one FS to another. For reference-valued features, this does a deep
+ * copy.
+ *
+ * @param aSrcFS
+ * FeatureStructure to copy from
+ * @param aDestFS
+ * FeatureStructure to copy to
+ */
+ private void copyFeatures(FeatureStructure aSrcFS, FeatureStructure aDestFS) {
+ // set feature values
+ Type srcType = aSrcFS.getType();
+ Type destType = aDestFS.getType();
+ Iterator srcFeatIter = srcType.getFeatures().iterator();
+ while (srcFeatIter.hasNext()) {
+ Feature srcFeat = (Feature) srcFeatIter.next();
+ // TODO: could optimize type lookup if type systems are identical
+ Feature destFeat;
+ if (destType == aSrcFS.getType()) {
+ // sharing same type system, so destFeat == srcFeat
+ destFeat = srcFeat;
+ } else {
+ // not sharing same type system, so do a name loop up in destination type system
+ destFeat = destType.getFeatureByBaseName(srcFeat.getShortName());
+ if (destFeat == null) {
+ throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
+ new Object[] { srcFeat.getName() });
+ }
+ }
+
+ // copy primitive values using their string representation
+ // TODO: could be optimized but this code would be very messy if we have to
+ // enumerate all possible primitive types. Maybe LowLevel CAS API could help?
+ if (srcFeat.getRange().isPrimitive()) {
+ aDestFS.setFeatureValueFromString(destFeat, aSrcFS.getFeatureValueAsString(srcFeat));
+ } else {
+ // recursive copy
+ FeatureStructure refFS = aSrcFS.getFeatureValue(srcFeat);
+ if (refFS != null) {
+ FeatureStructure copyRefFs = copyFs(refFS);
+ aDestFS.setFeatureValue(destFeat, copyRefFs);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns whether the given FS has already been copied using this CasCopier.
+ *
+ * @param aFS
+ * @return
+ */
+ public boolean alreadyCopied(FeatureStructure aFS) {
+ return mFsMap.containsKey(aFS);
+ }
+
+ /**
+ * @param arrayFS
+ * @return
+ */
+ private FeatureStructure copyArray(FeatureStructure aSrcFs) {
+ // TODO: there should be a way to do this without enumerating all the array types!
+ if (aSrcFs instanceof StringArrayFS) {
+ StringArrayFS arrayFs = (StringArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ StringArrayFS destFS = mDestCas.createStringArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof IntArrayFS) {
+ IntArrayFS arrayFs = (IntArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ IntArrayFS destFS = mDestCas.createIntArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof ByteArrayFS) {
+ ByteArrayFS arrayFs = (ByteArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ ByteArrayFS destFS = mDestCas.createByteArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof ShortArrayFS) {
+ ShortArrayFS arrayFs = (ShortArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ ShortArrayFS destFS = mDestCas.createShortArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof LongArrayFS) {
+ LongArrayFS arrayFs = (LongArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ LongArrayFS destFS = mDestCas.createLongArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof FloatArrayFS) {
+ FloatArrayFS arrayFs = (FloatArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ FloatArrayFS destFS = mDestCas.createFloatArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof DoubleArrayFS) {
+ DoubleArrayFS arrayFs = (DoubleArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ DoubleArrayFS destFS = mDestCas.createDoubleArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof BooleanArrayFS) {
+ BooleanArrayFS arrayFs = (BooleanArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ BooleanArrayFS destFS = mDestCas.createBooleanArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ destFS.set(i, arrayFs.get(i));
+ }
+ return destFS;
+ }
+ if (aSrcFs instanceof ArrayFS) {
+ ArrayFS arrayFs = (ArrayFS) aSrcFs;
+ int len = arrayFs.size();
+ ArrayFS destFS = mDestCas.createArrayFS(len);
+ for (int i = 0; i < len; i++) {
+ FeatureStructure srcElem = arrayFs.get(i);
+ if (srcElem != null) {
+ FeatureStructure copyElem = copyFs(arrayFs.get(i));
+ destFS.set(i, copyElem);
+ }
+ }
+ return destFS;
+ }
+ assert false; // the set of array types should be exhaustive, so we should never get here
+ return null;
+ }
+
+ /**
+ * Gets the named view; if the view doesn't exist it will be created.
+ */
+ private static CAS getOrCreateView(CAS aCas, String aViewName) {
+ //TODO: there should be some way to do this without the try...catch
+ try {
+ return aCas.getView(aViewName);
+ }
+ catch(CASRuntimeException e) {
+ //create the view
+ return aCas.createView(aViewName);
+ }
+ }
+
+ /**
+ * Determines whether the given FS is the DocumentAnnotation for its view.
+ * This is more than just a type check; we actually check if it is the one "special"
+ * DocumentAnnotation that CAS.getDocumentAnnotation() would return.
+ */
+ private static boolean isDocumentAnnotation(FeatureStructure aFS) {
+ return (aFS instanceof AnnotationFS) &&
+ aFS.equals(((AnnotationFS)aFS).getView().getDocumentAnnotation());
+ }
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java?rev=690405&r1=690404&r2=690405&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java Fri Aug 29 15:10:52 2008
@@ -1,47 +1,47 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.uima.util;
-
-import org.apache.uima.resource.ManagementObject;
-
-
-/**
- * Management interface to a {@link CasPool}.
- */
-public interface CasPoolManagement extends ManagementObject {
-
- /**
- * Get the total size of the CAS Pool.
- * @return the pool size
- */
- public int getPoolSize();
-
- /**
- * Get the number of CAS instances currently available in the pool.
- * @return the number of available CAS instances
- */
- public int getAvailableInstances();
-
-// /**
-// * Get the average time, in milliseconds, that getCas() requests on
-// * the pool have to wait for a CAS to become available
-// * @return average wait time in milliseconds
-// */
-// public int getAverageWaitTime();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util;
+
+import org.apache.uima.resource.ManagementObject;
+
+
+/**
+ * Management interface to a {@link CasPool}.
+ */
+public interface CasPoolManagement extends ManagementObject {
+
+ /**
+ * Get the total size of the CAS Pool.
+ * @return the pool size
+ */
+ public int getPoolSize();
+
+ /**
+ * Get the number of CAS instances currently available in the pool.
+ * @return the number of available CAS instances
+ */
+ public int getAvailableInstances();
+
+// /**
+// * Get the average time, in milliseconds, that getCas() requests on
+// * the pool have to wait for a CAS to become available
+// * @return average wait time in milliseconds
+// */
+// public int getAverageWaitTime();
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasToInlineXml.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/ConsumerCasUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/FileUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/InstrumentationFacility.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/InvalidXMLException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/JCasPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/Level.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/Logger.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/LoggerPrintStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/NameClassPair.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/ProcessTrace.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/ProcessTraceEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/Progress.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/ProgressImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/SaxDeserializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/SimpleResourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TCasFormatter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TCasToInlineXml.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/TypeSystemUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UimaTimer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLInputSource.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLInputSource.java?rev=690405&r1=690404&r2=690405&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLInputSource.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLInputSource.java Fri Aug 29 15:10:52 2008
@@ -1,163 +1,163 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.uima.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.uima.UIMARuntimeException;
-
-/**
- * An input source used by the {@link XMLParser} to read XML documents for parsing.
- * <p>
- * The application uses the {@link #XMLInputSource(File)} constructor to create an
- * <code>XMLInputSource</code> from a descriptor <code>File</code>. Alternatively, if the
- * source of the XML is not a file, the {@link #XMLInputSource(InputStream,File)} constructor may be
- * used to read the XML from an input stream. The second argument to this constructor is the
- * relative path base, to be used if the descriptor contains imports with relative paths. It is
- * acceptable to set this to null if it is known that the descriptor does not contain any such
- * imports.
- */
-public class XMLInputSource {
-
- /**
- * InputStream from which the XML document is read.
- */
- private InputStream mInputStream;
-
- /**
- * URL that we're parsing from
- */
- private URL mURL;
-
- /**
- * Creates an <code>XMLInputSource</code> from a descriptor file.
- *
- * @param aFile
- * file to read from
- *
- * @throws IOException
- * if an I/O error occurs
- */
- public XMLInputSource(File aFile) throws IOException {
- this(aFile.toURL());
- }
-
- /**
- * Creates an <code>XMLInputSource</code> from a descriptor file.
- *
- * @param aUrlOrFileName
- * a URL or a file name to read from
- *
- * @throws IOException
- * if an I/O error occurs
- */
- public XMLInputSource(String aUrlOrFileName) throws IOException {
- //try as URL first, then as file name
- try {
- mURL = new URL(aUrlOrFileName);
- }
- catch (MalformedURLException e) {
- mURL = new File(aUrlOrFileName).toURL();
- }
- mInputStream = mURL.openStream();
- }
-
- /**
- * Creates an XMLInputSource from an existing InputStream.
- *
- * @param aInputStream
- * input stream from which to read
- * @param aRelativePathBase
- * base for resolving relative paths. This must be a directory.
- */
- public XMLInputSource(InputStream aInputStream, File aRelativePathBase) {
- mInputStream = aInputStream;
- try {
- mURL = aRelativePathBase == null ? null : aRelativePathBase.toURL();
- } catch (MalformedURLException e) {
- throw new UIMARuntimeException(e);
- }
- }
-
- /**
- * Creates an <code>XMLInputSource</code> from a URL.
- *
- * @param aURL
- * URL to read from
- *
- * @throws IOException
- * if an I/O error occurs
- */
- public XMLInputSource(URL aURL) throws IOException {
- mURL = aURL;
- mInputStream = aURL.openStream();
- }
-
- /**
- * Gets the InputStream from which to read an XML document.
- *
- * @return an InputStream from which an XML document may be read
- */
- public InputStream getInputStream() {
- return mInputStream;
- }
-
- /**
- * Gets the base for resolving relative paths. This must be a directory.
- *
- * @return the base for resolving relative paths, <code>null</code> if none has been specified.
- *
- * @deprecated Use {@link #getURL()} instead.
- */
- public File getRelativePathBase() {
- // use the parent directory as the base for relative path resolution
- String path = mURL.getPath();
- return new File(path).getParentFile();
- }
-
- /**
- * Gets the base for resolving relative paths. This must be a directory.
- *
- * @return the base for resolving relative paths, <code>null</code> if none has been specified.
- */
- public URL getURL() {
- return mURL;
- }
-
- /**
- * Closes the underlying <code>InputStream</code>.
- *
- * @throws IOException if an I/O error occurs.
- */
- public void close()
- throws IOException
- {
- if (mInputStream != null)
- {
- mInputStream.close();
- }
-
- mURL = null;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.uima.UIMARuntimeException;
+
+/**
+ * An input source used by the {@link XMLParser} to read XML documents for parsing.
+ * <p>
+ * The application uses the {@link #XMLInputSource(File)} constructor to create an
+ * <code>XMLInputSource</code> from a descriptor <code>File</code>. Alternatively, if the
+ * source of the XML is not a file, the {@link #XMLInputSource(InputStream,File)} constructor may be
+ * used to read the XML from an input stream. The second argument to this constructor is the
+ * relative path base, to be used if the descriptor contains imports with relative paths. It is
+ * acceptable to set this to null if it is known that the descriptor does not contain any such
+ * imports.
+ */
+public class XMLInputSource {
+
+ /**
+ * InputStream from which the XML document is read.
+ */
+ private InputStream mInputStream;
+
+ /**
+ * URL that we're parsing from
+ */
+ private URL mURL;
+
+ /**
+ * Creates an <code>XMLInputSource</code> from a descriptor file.
+ *
+ * @param aFile
+ * file to read from
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public XMLInputSource(File aFile) throws IOException {
+ this(aFile.toURL());
+ }
+
+ /**
+ * Creates an <code>XMLInputSource</code> from a descriptor file.
+ *
+ * @param aUrlOrFileName
+ * a URL or a file name to read from
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public XMLInputSource(String aUrlOrFileName) throws IOException {
+ //try as URL first, then as file name
+ try {
+ mURL = new URL(aUrlOrFileName);
+ }
+ catch (MalformedURLException e) {
+ mURL = new File(aUrlOrFileName).toURL();
+ }
+ mInputStream = mURL.openStream();
+ }
+
+ /**
+ * Creates an XMLInputSource from an existing InputStream.
+ *
+ * @param aInputStream
+ * input stream from which to read
+ * @param aRelativePathBase
+ * base for resolving relative paths. This must be a directory.
+ */
+ public XMLInputSource(InputStream aInputStream, File aRelativePathBase) {
+ mInputStream = aInputStream;
+ try {
+ mURL = aRelativePathBase == null ? null : aRelativePathBase.toURL();
+ } catch (MalformedURLException e) {
+ throw new UIMARuntimeException(e);
+ }
+ }
+
+ /**
+ * Creates an <code>XMLInputSource</code> from a URL.
+ *
+ * @param aURL
+ * URL to read from
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public XMLInputSource(URL aURL) throws IOException {
+ mURL = aURL;
+ mInputStream = aURL.openStream();
+ }
+
+ /**
+ * Gets the InputStream from which to read an XML document.
+ *
+ * @return an InputStream from which an XML document may be read
+ */
+ public InputStream getInputStream() {
+ return mInputStream;
+ }
+
+ /**
+ * Gets the base for resolving relative paths. This must be a directory.
+ *
+ * @return the base for resolving relative paths, <code>null</code> if none has been specified.
+ *
+ * @deprecated Use {@link #getURL()} instead.
+ */
+ public File getRelativePathBase() {
+ // use the parent directory as the base for relative path resolution
+ String path = mURL.getPath();
+ return new File(path).getParentFile();
+ }
+
+ /**
+ * Gets the base for resolving relative paths. This must be a directory.
+ *
+ * @return the base for resolving relative paths, <code>null</code> if none has been specified.
+ */
+ public URL getURL() {
+ return mURL;
+ }
+
+ /**
+ * Closes the underlying <code>InputStream</code>.
+ *
+ * @throws IOException if an I/O error occurs.
+ */
+ public void close()
+ throws IOException
+ {
+ if (mInputStream != null)
+ {
+ mInputStream.close();
+ }
+
+ mURL = null;
+ }
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLInputSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XMLizable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XmlCasDeserializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/XmlCasSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java?rev=690405&r1=690404&r2=690405&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java Fri Aug 29 15:10:52 2008
@@ -1,77 +1,77 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.uima.util.impl;
-
-import java.lang.ref.WeakReference;
-
-import org.apache.uima.util.CasPool;
-import org.apache.uima.util.CasPoolManagement;
-
-/**
- * Implements Monitoring/Management interface to a CasPool.
- */
-public class CasPoolManagementImpl implements CasPoolManagement, CasPoolManagementImplMBean {
-
- private WeakReference<CasPool> mCasPoolRef;
- private String mUniqueMBeanName;
-
- public CasPoolManagementImpl(CasPool aCasPool, String aUniqueMBeanName) {
- mCasPoolRef = new WeakReference<CasPool>(aCasPool);
- mUniqueMBeanName = aUniqueMBeanName;
- }
-
- /* (non-Javadoc)
- * @see org.apache.uima.util.CasPoolManagement#getAvailableInstances()
- */
- public int getAvailableInstances() {
- CasPool casPool = mCasPoolRef.get();
- if (casPool != null) {
- return casPool.getNumAvailable();
- } else {
- return -1;
- }
- }
-
-// /* (non-Javadoc)
-// * @see org.apache.uima.util.CasPoolManagement#getAverageWaitTime()
-// */
-// public int getAverageWaitTime() {
-// // TODO Auto-generated method stub
-// return 0;
-// }
-
- /* (non-Javadoc)
- * @see org.apache.uima.util.CasPoolManagement#getPoolSize()
- */
- public int getPoolSize() {
- CasPool casPool = mCasPoolRef.get();
- if (casPool != null) {
- return casPool.getSize();
- } else {
- return -1;
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.uima.resource.impl.ManagementObject_ImplBase#getUniqueMBeanName()
- */
- public String getUniqueMBeanName() {
- return mUniqueMBeanName;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util.impl;
+
+import java.lang.ref.WeakReference;
+
+import org.apache.uima.util.CasPool;
+import org.apache.uima.util.CasPoolManagement;
+
+/**
+ * Implements Monitoring/Management interface to a CasPool.
+ */
+public class CasPoolManagementImpl implements CasPoolManagement, CasPoolManagementImplMBean {
+
+ private WeakReference<CasPool> mCasPoolRef;
+ private String mUniqueMBeanName;
+
+ public CasPoolManagementImpl(CasPool aCasPool, String aUniqueMBeanName) {
+ mCasPoolRef = new WeakReference<CasPool>(aCasPool);
+ mUniqueMBeanName = aUniqueMBeanName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.util.CasPoolManagement#getAvailableInstances()
+ */
+ public int getAvailableInstances() {
+ CasPool casPool = mCasPoolRef.get();
+ if (casPool != null) {
+ return casPool.getNumAvailable();
+ } else {
+ return -1;
+ }
+ }
+
+// /* (non-Javadoc)
+// * @see org.apache.uima.util.CasPoolManagement#getAverageWaitTime()
+// */
+// public int getAverageWaitTime() {
+// // TODO Auto-generated method stub
+// return 0;
+// }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.util.CasPoolManagement#getPoolSize()
+ */
+ public int getPoolSize() {
+ CasPool casPool = mCasPoolRef.get();
+ if (casPool != null) {
+ return casPool.getSize();
+ } else {
+ return -1;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.resource.impl.ManagementObject_ImplBase#getUniqueMBeanName()
+ */
+ public String getUniqueMBeanName() {
+ return mUniqueMBeanName;
+ }
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java?rev=690405&r1=690404&r2=690405&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java Fri Aug 29 15:10:52 2008
@@ -1,43 +1,43 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.uima.util.impl;
-
-/**
- * JMX MBean interface for monitoring CASPool state.
- */
-public interface CasPoolManagementImplMBean {
- /**
- * Get the total size of the CAS Pool.
- * @return the pool size
- */
- public int getPoolSize();
-
- /**
- * Get the number of CAS instances currently available in the pool.
- * @return the number of available CAS instances
- */
- public int getAvailableInstances();
-
-// /**
-// * Get the average time, in milliseconds, that getCas() requests on
-// * the pool have to wait for a CAS to become available
-// * @return average wait time in milliseconds
-// */
-// public int getAverageWaitTime();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util.impl;
+
+/**
+ * JMX MBean interface for monitoring CASPool state.
+ */
+public interface CasPoolManagementImplMBean {
+ /**
+ * Get the total size of the CAS Pool.
+ * @return the pool size
+ */
+ public int getPoolSize();
+
+ /**
+ * Get the number of CAS instances currently available in the pool.
+ * @return the number of available CAS instances
+ */
+ public int getAvailableInstances();
+
+// /**
+// * Get the average time, in milliseconds, that getCas() requests on
+// * the pool have to wait for a CAS to become available
+// * @return average wait time in milliseconds
+// */
+// public int getAverageWaitTime();
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/JSR47Logger_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/Log4jLogger_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/Logger_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/ProcessTraceEvent_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/ProcessTrace_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SaxDeserializer_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/XMLParser_impl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/package.html
------------------------------------------------------------------------------
svn:eol-style = native