You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/03 17:54:11 UTC

svn commit: r503248 [6/8] - /incubator/uima/uimacpp/trunk/src/cas/

Added: incubator/uima/uimacpp/trunk/src/cas/lowlevel_typesystem.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/lowlevel_typesystem.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/lowlevel_typesystem.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/lowlevel_typesystem.cpp Sat Feb  3 08:54:09 2007
@@ -0,0 +1,971 @@
+/** \file lowlevel_typesystem.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+//#define DEBUG_VERBOSE
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+#include "uima/macros.h"
+
+#include "uima/macros.h"
+
+#include <algorithm>
+#include "uima/lowlevel_typesystem.hpp"
+// for definition of string constants for public built-in types
+#include "uima/cas.hpp"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/msg.h"
+#include "uima/stltools.hpp"
+#include "uima/typesystem.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+    icu::UnicodeString const TypeSystem::ustrCREATOR_ID_SYSTEM("System");
+
+    TypeSystem::StTypeInfo gs_arBuiltinTypes[] = {
+          {
+            CAS::TYPE_NAME_INTEGER,      CAS::TYPE_NAME_TOP,      "integer type"
+          },
+          { CAS::TYPE_NAME_FLOAT,        CAS::TYPE_NAME_TOP,      "float type"},
+          { CAS::TYPE_NAME_STRING,       CAS::TYPE_NAME_TOP,      "string type"},
+          { CAS::TYPE_NAME_ARRAY_BASE,   CAS::TYPE_NAME_TOP,      "array base type"},
+          { CAS::TYPE_NAME_FS_ARRAY,      CAS::TYPE_NAME_ARRAY_BASE,"fs array"},
+          { CAS::TYPE_NAME_FLOAT_ARRAY,   CAS::TYPE_NAME_ARRAY_BASE,"float array"},
+          { CAS::TYPE_NAME_INTEGER_ARRAY,     CAS::TYPE_NAME_ARRAY_BASE,"int array"},
+          { CAS::TYPE_NAME_STRING_ARRAY,  CAS::TYPE_NAME_ARRAY_BASE,"string array"},
+          { CAS::TYPE_NAME_LIST_BASE,    CAS::TYPE_NAME_TOP,      "list base type"},
+          { CAS::TYPE_NAME_FS_LIST,       CAS::TYPE_NAME_LIST_BASE,"fs list"},
+          { CAS::TYPE_NAME_EMPTY_FS_LIST,       CAS::TYPE_NAME_FS_LIST,   "e_fs list"},
+          { CAS::TYPE_NAME_NON_EMPTY_FS_LIST,      CAS::TYPE_NAME_FS_LIST,   "ne fs list"},
+          { CAS::TYPE_NAME_FLOAT_LIST,    CAS::TYPE_NAME_LIST_BASE,"list of floats"},
+          { CAS::TYPE_NAME_EMPTY_FLOAT_LIST,  CAS::TYPE_NAME_FLOAT_LIST,"empty list of floats"},
+          { CAS::TYPE_NAME_NON_EMPTY_FLOAT_LIST, CAS::TYPE_NAME_FLOAT_LIST,"non empty list of floats"},
+          { CAS::TYPE_NAME_INTEGER_LIST,      CAS::TYPE_NAME_LIST_BASE,"list of integers"},
+          { CAS::TYPE_NAME_EMPTY_INTEGER_LIST,    CAS::TYPE_NAME_INTEGER_LIST,  "empty list of integers"},
+          { CAS::TYPE_NAME_NON_EMPTY_INTEGER_LIST,   CAS::TYPE_NAME_INTEGER_LIST,  "non empty list of integers"},
+          { CAS::TYPE_NAME_STRING_LIST,   CAS::TYPE_NAME_LIST_BASE,"list of strings"},
+          { CAS::TYPE_NAME_EMPTY_STRING_LIST, CAS::TYPE_NAME_STRING_LIST,"empty list of strings"},
+          { CAS::TYPE_NAME_NON_EMPTY_STRING_LIST,CAS::TYPE_NAME_STRING_LIST,"non empty list of strings"},
+          { CAS::TYPE_NAME_BOOLEAN,        CAS::TYPE_NAME_TOP,   "boolean  type"},
+          { CAS::TYPE_NAME_BYTE,           CAS::TYPE_NAME_TOP,      "8Bit  type"},
+          { CAS::TYPE_NAME_SHORT,          CAS::TYPE_NAME_TOP,      "16Bit type"},
+          { CAS::TYPE_NAME_LONG,           CAS::TYPE_NAME_TOP,      "64Bit type"},
+          { CAS::TYPE_NAME_DOUBLE,         CAS::TYPE_NAME_TOP,      "long double  type"},
+          { CAS::TYPE_NAME_BOOLEAN_ARRAY,   CAS::TYPE_NAME_ARRAY_BASE,      "boolean array  type"},
+          { CAS::TYPE_NAME_BYTE_ARRAY,      CAS::TYPE_NAME_ARRAY_BASE,      "8Bit array  type"},
+          { CAS::TYPE_NAME_SHORT_ARRAY,     CAS::TYPE_NAME_ARRAY_BASE,      "16Bit array type"},
+          { CAS::TYPE_NAME_LONG_ARRAY,      CAS::TYPE_NAME_ARRAY_BASE,      "64Bit array type"},
+          { CAS::TYPE_NAME_DOUBLE_ARRAY,    CAS::TYPE_NAME_ARRAY_BASE,      "long double array  type"},
+
+        };
+
+    TypeSystem::StFeatureInfo gs_arBuiltinFeatures[] = {
+          {
+            CAS::FEATURE_BASE_NAME_HEAD, CAS::TYPE_NAME_NON_EMPTY_FS_LIST, CAS::TYPE_NAME_TOP,               "head"
+          },
+          { CAS::FEATURE_BASE_NAME_TAIL, CAS::TYPE_NAME_NON_EMPTY_FS_LIST, CAS::TYPE_NAME_FS_LIST,               "tail"},
+          { CAS::FEATURE_BASE_NAME_HEAD, CAS::TYPE_NAME_NON_EMPTY_FLOAT_LIST, CAS::TYPE_NAME_FLOAT, "head of float list"},
+          { CAS::FEATURE_BASE_NAME_TAIL, CAS::TYPE_NAME_NON_EMPTY_FLOAT_LIST, CAS::TYPE_NAME_FLOAT_LIST, "tail of float list"},
+          { CAS::FEATURE_BASE_NAME_HEAD, CAS::TYPE_NAME_NON_EMPTY_INTEGER_LIST, CAS::TYPE_NAME_INTEGER, "head of integer list"},
+          { CAS::FEATURE_BASE_NAME_TAIL, CAS::TYPE_NAME_NON_EMPTY_INTEGER_LIST, CAS::TYPE_NAME_INTEGER_LIST, "tail of integer list"},
+          { CAS::FEATURE_BASE_NAME_HEAD, CAS::TYPE_NAME_NON_EMPTY_STRING_LIST, CAS::TYPE_NAME_STRING, "head of string list"},
+          { CAS::FEATURE_BASE_NAME_TAIL, CAS::TYPE_NAME_NON_EMPTY_STRING_LIST, CAS::TYPE_NAME_STRING_LIST, "tail of string list"}
+        };
+
+    char const * TYPE_NAME_INVALID               = "INVALID_TYPE";
+    char const * FEATURE_NAME_INVALID            = "INVALIDFEATURE";
+  }
+}
+
+
+
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+    UIMA_EXC_CLASSIMPLEMENT(FeatureIntroductionFailedException, CASException);
+    UIMA_EXC_CLASSIMPLEMENT(TypeCreationFailedException, CASException);
+
+    ////////////////////////////////////////////////////////////////////
+
+    TypeSystem::TypeSystem()
+        : iv_bIsCommitted(false),
+        iv_bBuiltinTypesCreated(false),
+        iv_tyTop(1) {
+      reset();
+    }
+
+    const TyFSType TypeSystem::INVALID_TYPE = 0;
+    const TyFSFeature TypeSystem::INVALID_FEATURE = 0;
+
+
+    void TypeSystem::createPredefinedCASTypes() {
+      assert( !iv_bIsCommitted );
+      assert( !iv_bBuiltinTypesCreated );
+
+      iv_tyTop = 1;
+      iv_vecTree.clear();
+      iv_vecTree.resize(2); // reserve space for top, leave first slot empty
+      iv_vecIntroducedFeatures.clear();
+      iv_vecIntroducedFeatures.resize(2);
+      iv_vecTypeNames.resize(2);
+      iv_vecTypeNames[1] = CAS::TYPE_NAME_TOP;
+      iv_vecTypeNames[0] = TYPE_NAME_INVALID;
+      iv_vecParents.resize(2);
+      iv_vecParents[0] = TypeSystem::INVALID_TYPE;
+      iv_vecParents[1] = iv_tyTop;
+      iv_vecFeatureBaseNames.resize(1);
+      iv_vecFeatureBaseNames[0] = FEATURE_NAME_INVALID;
+      iv_vecFeatureCreatorIDs.resize(1);
+      iv_vecFeatureCreatorIDs[0] = FEATURE_NAME_INVALID;
+      iv_vecRangeTypes.resize(1);
+
+
+      size_t uiType;
+      for (uiType =  0; uiType < NUMBEROF(gs_arBuiltinTypes) ; ++uiType) {
+        createType( gs_arBuiltinTypes[uiType], ustrCREATOR_ID_SYSTEM );
+      }
+
+      size_t uiFeature;
+      for (uiFeature = 0; uiFeature <  NUMBEROF(gs_arBuiltinFeatures) ; ++uiFeature) {
+        createFeature( gs_arBuiltinFeatures[uiFeature], ustrCREATOR_ID_SYSTEM );
+      }
+
+      iv_bBuiltinTypesCreated = true;
+    }
+
+    TypeSystem::~TypeSystem() {}
+
+
+    TyFSType TypeSystem::createType(TyFSType tyParent, icu::UnicodeString const & crusName, icu::UnicodeString const & crusCreatorID) {
+      assert( !iv_bIsCommitted);
+      assert( (tyParent > 0) && (tyParent < iv_vecTree.size()) );
+
+      if (iv_bBuiltinTypesCreated && ! isAllowedToAddSubTypes(tyParent)) {
+        ErrorMessage errMessage(UIMA_MSG_ID_EXCON_CREATING_TYPE, crusName);
+        errMessage.addParam(getTypeName(tyParent) );
+
+        UIMA_EXC_THROW_NEW(TypeCreationFailedException,
+                           UIMA_ERR_TYPE_CREATION_FAILED,
+                           UIMA_MSG_ID_EXC_TYPE_CREATION_FAILED_FINAL_TYPE,
+                           errMessage,
+                           ErrorInfo::recoverable);
+      }
+      return createTypeNoChecks(tyParent, crusName, crusCreatorID);
+    }
+
+    TyFSType TypeSystem::createTypeNoChecks(TyFSType tyParent, icu::UnicodeString const & crusName, icu::UnicodeString const & crusCreatorID) {
+      assert( debugIsTreeConsistent() );
+
+      if ( find(iv_vecTypeNames.begin(), iv_vecTypeNames.end(), crusName) != iv_vecTypeNames.end() ) {
+        // typename already exists
+        ErrorMessage errMessage(UIMA_MSG_ID_EXCON_CREATING_TYPE, crusName);
+        errMessage.addParam(getTypeName(tyParent) );
+        UIMA_EXC_THROW_NEW(TypeCreationFailedException,
+                           UIMA_ERR_TYPE_CREATION_FAILED,
+                           UIMA_MSG_ID_EXC_TYPE_ALREADY_EXISTS,
+                           errMessage,
+                           ErrorInfo::recoverable);
+      }
+
+      // add new type slots
+      TyFSType newType = iv_vecTree.size();
+      iv_vecTree.resize(newType + 1);
+      iv_vecParents.resize(newType + 1);
+      iv_vecIntroducedFeatures.resize(iv_vecTree.size());
+      iv_vecTypeNames.resize(iv_vecTree.size());
+      iv_vecTypeCreatorIDs.resize(iv_vecTree.size());
+
+      // add all type specific data
+      iv_vecParents[newType] = tyParent;
+      vector<TyFSType>& children = iv_vecTree[tyParent];
+      children.push_back( newType );
+      iv_vecTypeNames[newType] = crusName;
+      iv_vecTypeCreatorIDs[newType] = crusCreatorID;
+
+      assert( debugIsTreeConsistent() );
+      return newType;
+    }
+
+
+    TyFSFeature TypeSystem::createFeature(TyFSType tyIntro, TyFSType tyRange, icu::UnicodeString const & crusName, icu::UnicodeString const & crusCreatorID) {
+      UIMA_TPRINT("Creating feature " << crusName);
+      assert( !iv_bIsCommitted);
+      assert( (tyIntro > 0) && (tyIntro < iv_vecTree.size()) );
+      assert( (tyRange > 0) && (tyRange < iv_vecTree.size()) );
+      assert( isValidType(tyIntro) );
+      assert( isValidType(tyRange) );
+
+      if (iv_bBuiltinTypesCreated && ! isAllowedToCreateFeatures(tyIntro) ) {
+        // throw exception
+        ErrorMessage errMessage(UIMA_MSG_ID_EXCON_CREATING_FEATURE, crusName);
+        errMessage.addParam(getTypeName(tyIntro) );
+
+        UIMA_EXC_THROW_NEW(FeatureIntroductionFailedException,
+                           UIMA_ERR_FEATURE_INTRO_FAILED,
+                           UIMA_MSG_ID_EXC_FEATURE_INTRO_FAILED_FINAL_TYPE,
+                           errMessage,
+                           ErrorInfo::recoverable);
+      }
+
+      assert( debugIsTreeConsistent() );
+
+      if ( getFeatureByBaseName( tyIntro, crusName ) != INVALID_FEATURE ) {
+        // throw exception
+        ErrorMessage errMessage(UIMA_MSG_ID_EXCON_CREATING_FEATURE, crusName);
+        errMessage.addParam(getTypeName(tyIntro) );
+        UIMA_EXC_THROW_NEW(FeatureIntroductionFailedException,
+                           UIMA_ERR_FEATURE_INTRO_FAILED,
+                           UIMA_MSG_ID_EXC_FEATURE_ALREADY_EXISTS,
+                           errMessage,
+                           ErrorInfo::recoverable);
+      }
+
+      // add feature specific data
+      TyFSFeature newFeature = iv_vecFeatureBaseNames.size();
+      iv_vecFeatureBaseNames.push_back(crusName);
+      iv_vecRangeTypes.push_back(tyRange);
+      iv_vecIntroducedFeatures[tyIntro].push_back(newFeature);
+      iv_vecFeatureCreatorIDs.push_back(crusName);
+
+      assert( debugIsTreeConsistent() );
+      return newFeature;
+    }
+
+    TyFSType TypeSystem::createType( StTypeInfo const & crTypeInfo, icu::UnicodeString const & crusCreatorID) {
+      UIMA_TPRINT("Adding type " << crTypeInfo.iv_cpszName << " as son of " << crTypeInfo.iv_cpszParentName);
+      assert( !iv_bIsCommitted);
+      TyFSType tyParent = getTypeByName(icu::UnicodeString( crTypeInfo.iv_cpszParentName) );
+      assert( tyParent != INVALID_TYPE );
+      TyFSType tyNewType = createType( tyParent, crTypeInfo.iv_cpszName, crusCreatorID);
+      assert( tyNewType != INVALID_TYPE );
+      return tyNewType;
+    }
+
+    TyFSType TypeSystem::createStringSubtype(icu::UnicodeString const & crName,
+        vector<icu::UnicodeString> const & crStrings,
+        icu::UnicodeString const & crusCreatorID) {
+      size_t uiNewEntry = iv_enumStrings.size();
+      iv_enumStrings.push_back(crStrings);
+
+      TyFSType stringType = getTypeByName(CAS::TYPE_NAME_STRING);
+      TyFSType result = createTypeNoChecks(stringType, crName, crusCreatorID);
+      iv_stringSubtypeToStringSet[result] = uiNewEntry;
+      return result;
+    }
+
+
+    TyFSFeature TypeSystem::createFeature( StFeatureInfo const & crFeatureInfo, icu::UnicodeString const & crusCreatorID) {
+      UIMA_TPRINT("Adding feature " << crFeatureInfo.iv_cpszName << " on intro " << crFeatureInfo.iv_cpszIntroTypeName << " with range " << crFeatureInfo.iv_cpszRangeTypeName );
+      assert( !iv_bIsCommitted);
+      TyFSType tyIntroType = getTypeByName(icu::UnicodeString(crFeatureInfo.iv_cpszIntroTypeName) );
+      assert( tyIntroType != INVALID_TYPE );
+      TyFSType tyRangeType = getTypeByName(icu::UnicodeString( crFeatureInfo.iv_cpszRangeTypeName) );
+      assert( tyRangeType != INVALID_TYPE );
+      TyFSFeature tyNewFeature = createFeature( tyIntroType, tyRangeType, crFeatureInfo.iv_cpszName, crusCreatorID );
+      assert( tyNewFeature != INVALID_FEATURE );
+      return tyNewFeature;
+    }
+
+    /**
+     * return true iff there is an edge which has node as the end point.
+     */
+    template <class T>
+    bool hasPredecessor(vector< pair<T, T> > const & rAdjList, T const & node) {
+      size_t i;
+      for (i=0; i<rAdjList.size(); ++i) {
+        if (rAdjList[i].second == node) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+    /**
+     * Delete all edges where the start or end node is node.
+     */
+    template <class T>
+    void deleteAllEdges(vector< pair<T, T> > & rAdjList, T const & node) {
+      vector< pair<T, T> > result;
+      size_t i;
+      for (i=0; i<rAdjList.size(); ++i) {
+        assert(rAdjList[i].second != node);
+        if (rAdjList[i].first != node) {
+          result.push_back( rAdjList[i] );
+        }
+      }
+      rAdjList = result;
+    }
+
+    /**
+     * find a node in a graph with no predecessors and delete it.
+     * return true if such a node exists. result is the output parameter
+     * indiacting the node which could be deleted.
+     */
+    template <class T>
+    bool deleteNodeWithoutPredecessor(vector<T> & rNodes, vector< pair<T, T> > & rAdjList, T& result) {
+      typename vector<T>::iterator it;
+      for (it = rNodes.begin(); it != rNodes.end(); ++it) {
+        if (! hasPredecessor(rAdjList, *it)) {
+#ifndef NDEBUG
+          size_t oldAdjListLength = rAdjList.size();
+#endif
+          deleteAllEdges(rAdjList, *it);
+          assert( rAdjList.size() <= oldAdjListLength );
+          result = *it;
+          rNodes.erase(it);
+          return true;
+        }
+      }
+      return false;
+    }
+
+    // sorts the graph given by nodes and adjList topologically. The output maps
+    // elements to its number in the sort order.
+    // The algorithm works as follows:
+    // 1. select some node v without a predecessor,
+    //    if no such node can be found and the graph is not empty->fail
+    // 2. delete the v from the graph
+    // 3. v is the next node in the topological ordering
+    // 4. repeat 1,2,3 until graph is empty
+    //
+    // Note: the nodes and adjacency list are passed by-value because the algorithm
+    //       is destructive on these data structures.
+    template <class T>
+    bool topologicalSort(vector<T> nodes, vector< pair<T, T> > adjList, map<T, size_t> & rTotalOrder) {
+#ifndef NDEBUG
+      vector<pair<T,T> > adjListCheck = adjList;
+#endif
+      rTotalOrder.clear();
+      size_t i = 0;
+      T node;
+      while (1) {
+        bool bNodeCouldBeSelected = deleteNodeWithoutPredecessor(nodes, adjList, node);
+        if (!bNodeCouldBeSelected) {
+          bool bIsSortable = nodes.empty();
+#ifndef NDEBUG
+          // check order
+          if (bIsSortable) {
+            size_t j;
+            for (j=0; j<adjListCheck.size(); ++j) {
+              assert( (*rTotalOrder.find(adjListCheck[j].first)).second <
+                      (*rTotalOrder.find(adjListCheck[j].second)).second );
+//                     assert( rTotalOrder[ adjListCheck[j].first ] < rTotalOrder[ adjListCheck[j].second ] );
+            }
+          }
+#endif
+          return bIsSortable;
+        }
+        rTotalOrder[node] = i;
+        ++i;
+      }
+      assert(false);
+      return false;
+    }
+
+    // checks if the graph consisting of nodes rNodes and the edges coded as an
+    // adjacency list has a cycle.
+    template< class T>
+    bool hasCycle(vector<T> const & rNodes, vector< pair<T, T> > const & rAdjList) {
+      map<T, size_t> order;
+      bool bResult = topologicalSort(rNodes, rAdjList, order);
+#ifdef DEBUG_VERBOSE
+      UIMA_TPRINT("topological order:");
+      map<T, size_t>::const_iterator cit;
+      for (cit = order.begin(); cit != order.end() ;++ cit) {
+        UIMA_TPRINT(" type: " << (*cit).first << ", number: " << (*cit).second);
+      }
+#endif
+      return ! bResult;
+    }
+
+
+    bool TypeSystem::addTypePriority(TyFSType t1, TyFSType t2) {
+      assert( isValidType(t1) );
+      assert( isValidType(t2) );
+      iv_customTypePrioritySet = true;
+      // copy type priority pairs
+      vector< pair<TyFSType, TyFSType> > typePriorities = iv_typePriorityList;
+      typePriorities.push_back( pair<TyFSType, TyFSType>(t1, t2) );
+
+#ifdef DEBUG_VERBOSE
+      UIMA_TPRINT("Adding type priority between type " << getTypeName(t1) << " and " << getTypeName(t2) );
+      size_t i;
+      for (i=0; i<typePriorities.size(); ++i) {
+        UIMA_TPRINT("   " << getTypeName(typePriorities[i].first) << " < " << getTypeName(typePriorities[i].second) );
+      }
+#endif
+
+      vector<TyFSType> allTypes;
+      getAllTypes(allTypes);
+
+      // if type priorities are not cyclic
+      // hasCycle() does a lot of work but this is done at initialization time only.
+      // Furthermore, this has the big benefit that this method leaves a consistent state.
+      if (! hasCycle(allTypes, typePriorities) ) {
+        iv_typePriorityList.push_back( pair<TyFSType, TyFSType>(t1, t2) );
+        return true;
+      }
+      return false;
+    }
+
+    size_t TypeSystem::getTypePriorityNumber(TyFSType t) const {
+      assert( isValidType(t) );
+      assert( iv_mapTypePriority.find(t) != iv_mapTypePriority.end() );
+      return (*iv_mapTypePriority.find(t)).second;
+    }
+
+
+    bool TypeSystem::findInTree(TyFSType tyType, TyFSType tyTypeToBeFound) const {
+      assert( isValidType(tyType) );
+      assert( isValidType(tyTypeToBeFound) );
+      if (tyType == tyTypeToBeFound) {
+        return true;
+      }
+      size_t i;
+      for (i=0; i < iv_vecTree[tyType].size(); ++i) {
+        if (findInTree(iv_vecTree[tyType][i], tyTypeToBeFound)) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+
+    bool TypeSystem::subsumes(TyFSType tyT1, TyFSType tyT2) const {
+//         return findInTree(tyT1, tyT2);
+      if (tyT1 == tyT2)
+        return true;
+      if (tyT2 >= iv_vecTree.size() || tyT2 < 1)
+        return false;
+      if (iv_tyTop == iv_vecParents[tyT2]) {
+        if (tyT1 == iv_tyTop)
+          return true;
+        else
+          return false;
+      }
+      return subsumes(tyT1, iv_vecParents[tyT2]);
+    }
+
+
+    void TypeSystem::computeApprop(TyFSType tyType) {
+      assert( debugIsTreeConsistent() );
+      assert( isValidType(tyType) );
+      size_t i;
+      for (i=0; i<iv_vecTree[tyType].size(); ++i) {
+        TyFSType childType = iv_vecTree[tyType][i];
+
+        size_t j;
+        // add inherited features
+        //   appropriateness
+        for (j=0; j<iv_vecFeatureBaseNames.size(); ++j) {
+          iv_vecApprop[ childType ][j] = iv_vecApprop[tyType][j];
+        }
+        //   feature numbers
+        iv_vecFeatureNumber[ childType ] += iv_vecFeatureNumber[tyType];
+
+        // compute offsets and numbers for new features
+        UIMA_TPRINT("Checking introduced feature of type " << getTypeName( childType) );
+        assert( childType < iv_vecIntroducedFeatures.size() );
+        for (j=0; j<iv_vecIntroducedFeatures[ childType ].size(); ++j) {
+          UIMA_TPRINT("Adding introduced feature of type " << childType);
+          assert( j < iv_vecIntroducedFeatures[childType].size() );
+          TyFSFeature introFeature = iv_vecIntroducedFeatures[ childType ][j];
+          ++(iv_vecFeatureNumber[ childType ]);
+          iv_vecFeatureOffset[ introFeature ] = iv_vecFeatureNumber[ childType ];
+          assert( introFeature < iv_vecApprop[ childType ].size() );
+          iv_vecApprop[ childType ][ introFeature ] = true;
+        }
+        UIMA_TPRINT("   Checking done");
+        computeApprop(childType);
+      }
+      assert( debugIsTreeConsistent() );
+    }
+
+    void TypeSystem::computeTypeFeatureOffsetMapping() {
+      assert( iv_vecApprop.size() > 0 );
+      iv_vecTypeFeatureOffsetMapping.resize( iv_vecTypeNames.size() );
+      size_t t,f;
+      for (t=1; t<iv_vecTypeNames.size(); ++t) {
+        assert( t < iv_vecApprop.size() );
+        vector<TyFSFeature> & rOffsetFeatureMapping = iv_vecTypeFeatureOffsetMapping[t];
+        for (f=1; f<iv_vecFeatureBaseNames.size(); ++f) {
+          assert( f< iv_vecApprop[t].size() );
+          if (iv_vecApprop[t][f]) {
+            TyFeatureOffset tyOffset = iv_vecFeatureOffset[f];
+            if (tyOffset >= rOffsetFeatureMapping.size()) {
+              rOffsetFeatureMapping.resize(tyOffset + 1, INVALID_FEATURE);
+            }
+            rOffsetFeatureMapping[tyOffset] = f;
+          }
+        }
+      }
+    }
+
+
+    void computePreOrder(vector<vector<TyFSType> > const & tree, size_t root, vector<TyFSType> & result) {
+      // visit node
+      result.push_back(root);
+
+      // go through all children
+      assert( root < tree.size() );
+      vector<TyFSType> const & children = tree[root];
+      size_t i;
+      for (i=0; i<children.size(); ++i) {
+        computePreOrder(tree, children[i], result);
+      }
+    }
+
+    class TypePriorityCompare {
+      map<TyFSType, size_t> iv_map;
+    public:
+      TypePriorityCompare(vector< pair<TyFSType, TyFSType> > const & priorityList,
+                          vector< TyFSType> const & allTypes) {
+        bool bIsSortable = topologicalSort(allTypes, priorityList, iv_map);
+        assert( bIsSortable );
+      }
+
+      bool operator()(TyFSType t1, TyFSType t2) const {
+        size_t p1 = (*iv_map.find(t1)).second;
+        size_t p2 = (*iv_map.find(t2)).second;
+        return p1 < p2;
+      }
+    };
+
+    // the algorithm to combine the user defined type priorities with the Talent
+    // view works as follows:
+    //   1. take the type tree and sort all siblings w.r.t. the user defined priorities
+    //   2. compute a pre order of this tree (this is a total order)
+    //   3. try to insert the pairs of the total order into the type priority
+    // if type priorities are only defined between siblings, this gives the Talent behaviour
+    // if 3. fails, only the user defined ordering counts!
+    void TypeSystem::combineUserDefinedPrioritiesWithSiblingPriority() {
+      // copy tree
+      vector< vector<TyFSType> > typeTree = iv_vecTree;
+
+      // sort siblings in tree
+      vector<TyFSType> allTypes;
+      getAllTypes(allTypes);
+      TypePriorityCompare compare( iv_typePriorityList, allTypes);
+      size_t i;
+      for (i=1; i<typeTree.size(); ++i) {
+        vector<TyFSType> & siblings = typeTree[i];
+        sort(siblings.begin(), siblings.end(), compare);
+      }
+
+      // determine tree pre order
+      vector<TyFSType> typePreOrder;
+      computePreOrder( typeTree, getTopType(), typePreOrder );
+      assert( typePreOrder.size() == getNumberOfTypes() );
+
+      vector< pair<TyFSType, TyFSType> > priorityListBackup = iv_typePriorityList;
+      bool bOrdersAreCompatible = true;
+      // try to insert w.r.t. pre order
+      for (i=0; i<typePreOrder.size()-1; ++i) {
+        if (! addTypePriority(typePreOrder[i], typePreOrder[i+1] )) {
+          bOrdersAreCompatible = false;
+          break;
+        }
+      }
+      // restore old priorities if the user defined order is incompatible with Talent's
+      if (!bOrdersAreCompatible) {
+        iv_typePriorityList = priorityListBackup;
+      }
+
+    }
+
+
+    void TypeSystem::computeTypePriorityClosure() {
+      // prepare iv_typePriorityList
+
+      // this routine does not scale well with a large type system ...
+      // ... so skip it if possible
+      if (iv_customTypePrioritySet) {
+        combineUserDefinedPrioritiesWithSiblingPriority();
+      }
+
+      // compute actual type priority
+      vector<TyFSType> allTypes;
+      getAllTypes(allTypes);
+      bool bIsSortable = topologicalSort(allTypes, iv_typePriorityList, iv_mapTypePriority);
+      assert( bIsSortable );
+    }
+
+
+    void TypeSystem::commit() {
+      assert( ! iv_bIsCommitted );
+      iv_vecFeatureNumber.clear();
+      iv_vecFeatureOffset.clear();
+      iv_vecApprop.clear();
+
+      // compute featureNumbers and offsets
+      size_t featureNum = iv_vecFeatureBaseNames.size();
+      size_t typeNum = iv_vecTypeNames.size();
+
+      iv_vecFeatureNumber.resize(typeNum, 0);
+      iv_vecFeatureOffset.resize(featureNum, 0);
+      iv_vecApprop.resize(typeNum);
+
+      size_t i;
+      for (i=0; i<iv_vecApprop.size() ;++i) {
+        iv_vecApprop[i].resize(featureNum, false);
+      }
+
+      UIMA_TPRINT("Computing Approp");
+      computeApprop(iv_tyTop);
+      UIMA_TPRINT("  Approp computed");
+
+      computeTypeFeatureOffsetMapping();
+      computeTypePriorityClosure();
+
+      assert( debugIsConsistent() );
+      iv_bIsCommitted = true;
+
+      UIMA_TPRINT("TypeSystem::init() finished");
+    }
+
+
+    void TypeSystem::getSubsumedTypes(TyFSType tyType, vector<TyFSType>& rvecResult) const {
+      assert( isValidType(tyType) );
+      rvecResult.push_back(tyType);
+      size_t i;
+      for (i=0; i < iv_vecTree[tyType].size(); ++i) {
+        getSubsumedTypes(iv_vecTree[tyType][i], rvecResult);
+      }
+    }
+
+
+
+    TyFSType TypeSystem::getMostSpecificCommonSupertype(TyFSType t1, TyFSType t2) const {
+      assert( isValidType(t1) );
+      assert( isValidType(t2) );
+      if (subsumes(t1, t2)) {
+        return t1;
+      }
+      if (subsumes(t2, t1)) {
+        return t2;
+      }
+      t1 = getParentType(t1);
+      return getMostSpecificCommonSupertype(t1, t2);
+    }
+
+
+    TyFSType TypeSystem::getIntroType(TyFSFeature tyFeature) const {
+      TyFSType t;
+      for (t=1; t<iv_vecIntroducedFeatures.size(); ++t) {
+        vector<TyFSFeature> const & rFeatures = iv_vecIntroducedFeatures[t];
+        size_t i;
+        for (i=0; i<rFeatures.size(); ++i) {
+          if (rFeatures[i] == tyFeature) {
+            return t;
+          }
+        }
+      }
+      assert(false);
+      return INVALID_TYPE;
+    }
+
+    TyFSType TypeSystem::getParentType(TyFSType tyType) const {
+      assert( isValidType(tyType) );
+      TyFSType t;
+      for (t=1; t<iv_vecTree.size(); ++t) {
+        vector<TyFSType> const & rDaughters = iv_vecTree[t];
+        size_t i;
+        for (i=0; i<rDaughters.size(); ++i) {
+          if (rDaughters[i] == tyType) {
+            return t;
+          }
+        }
+      }
+      return INVALID_TYPE;
+    }
+
+
+    void TypeSystem::getAppropriateFeatures(TyFSType tyType, vector<TyFSFeature>& rResult) const {
+      assert( iv_bIsCommitted );
+      rResult.clear();
+      assert( isValidType(tyType) );
+      size_t i;
+      for (i=1; i< iv_vecApprop[tyType].size(); ++i) {
+        bool bIsApprop = iv_vecApprop[tyType][i];
+        if (bIsApprop) {
+          rResult.push_back( i );
+        }
+      }
+    }
+
+    void TypeSystem::getDirectSubTypes(TyFSType tyType, vector<TyFSType> & rResult) const {
+      assert( isValidType(tyType) );
+      rResult = iv_vecTree[tyType];
+    }
+
+
+    TyFSType TypeSystem::getTypeByName(icu::UnicodeString const & crusTypeName) const {
+      int i = findIndex(iv_vecTypeNames, crusTypeName);
+      assert( i != 0 );
+      if (i < 1) {
+        return INVALID_TYPE;
+      }
+      return i;
+    }
+
+
+    TyFSFeature TypeSystem::getFeatureByBaseName(TyFSType tyType, icu::UnicodeString const & crusFeatureName) const {
+      // cannot call getAppropriateFeatures(tyType, vecFeatures)
+      //  because type system may not be committed
+      if ( !isValidType(tyType) ) {
+        return INVALID_FEATURE;
+      }
+      while (tyType != iv_tyTop) {
+        size_t i;
+        assert( isValidType( tyType ) );
+        vector<TyFSFeature> const & crFeatures = iv_vecIntroducedFeatures[tyType];
+        for (i=0; i<crFeatures.size(); ++i) {
+          TyFSFeature tyFeat = crFeatures[i];
+          if (iv_vecFeatureBaseNames[ tyFeat ] == crusFeatureName ) {
+            return tyFeat;
+          }
+        }
+        tyType = getParentType(tyType);
+      }
+      return INVALID_FEATURE;
+    }
+
+    TyFSFeature TypeSystem::getFeatureByBaseName(icu::UnicodeString const & crusTypeName, icu::UnicodeString const & crusFeatureName) const {
+      TyFSType tyType = getTypeByName(crusTypeName);
+      if ( !isValidType(tyType) ) {
+        return INVALID_FEATURE;
+      }
+      return getFeatureByBaseName( tyType, crusFeatureName );
+    }
+
+
+    TyFSFeature TypeSystem::getFeatureByFullName(icu::UnicodeString const & crusFeatureName) const {
+      UChar sepChar( uima::TypeSystem::FEATURE_SEPARATOR );
+      int32_t  iIndex = crusFeatureName.indexOf(sepChar);
+      // if there is no or more than one separator
+      if ( (iIndex == -1) || (iIndex != crusFeatureName.lastIndexOf(sepChar)) ) {
+        return INVALID_FEATURE;
+      }
+
+      icu::UnicodeString featureBaseName;
+      icu::UnicodeString typeName;
+
+      crusFeatureName.extractBetween(0, iIndex, typeName);
+      crusFeatureName.extractBetween(iIndex + 1, crusFeatureName.length(), featureBaseName);
+      return getFeatureByBaseName( typeName, featureBaseName );
+    }
+
+
+    icu::UnicodeString TypeSystem::getFeatureName(TyFSFeature tyFeature) const {
+
+      icu::UnicodeString const & crBaseName = getFeatureBaseName(tyFeature);
+      icu::UnicodeString const & crTypeName = getTypeName( getIntroType(tyFeature) );
+      icu::UnicodeString result( crTypeName );
+      result.append((UChar) uima::TypeSystem::FEATURE_SEPARATOR);
+      result.append(crBaseName);
+      return result;
+    }
+
+
+    vector<icu::UnicodeString> const & TypeSystem::getStringsForStringSubtype(TyFSType type) const {
+      assert( subsumes( getTypeByName(CAS::TYPE_NAME_STRING), type) );
+      map<TyFSType, TyFeatureOffset>::const_iterator cit = iv_stringSubtypeToStringSet.find(type);
+      assert( cit != iv_stringSubtypeToStringSet.end() );
+      TyFeatureOffset uiEntry = (*cit).second;
+      assert( uiEntry < iv_enumStrings.size() );
+      return iv_enumStrings[uiEntry];
+    }
+
+
+    void TypeSystem::reset() {
+      iv_bIsCommitted = false;
+      iv_bBuiltinTypesCreated = false;
+      iv_customTypePrioritySet = false;
+      createPredefinedCASTypes();
+      iv_mapTypePriority.clear();
+      iv_typePriorityList.clear();
+    }
+
+
+
+    /**************************************************************************/
+
+#ifndef NDEBUG
+
+#define ASSERT_OR_RETURN_FALSE(x) assert(x)
+//#define ASSERT_OR_RETURN_FALSE(x) if (!(x)) return false
+
+    bool TypeSystem::debugIsTreeConsistent() const {
+      ASSERT_OR_RETURN_FALSE(iv_vecTree.size() == iv_vecIntroducedFeatures.size() );
+      ASSERT_OR_RETURN_FALSE(iv_vecTree.size() == iv_vecTypeNames.size() );
+      ASSERT_OR_RETURN_FALSE(iv_vecRangeTypes.size() == iv_vecFeatureBaseNames.size());
+
+      size_t n = iv_vecTree.size();
+      size_t i,j;
+      for (i=0; i<n; ++i) {
+        for (j=0; j<iv_vecTree[i].size(); ++j) {
+          ASSERT_OR_RETURN_FALSE( !( (iv_vecTree[i][j] < 1) || (iv_vecTree[i][j] >= n) ) );
+        }
+      }
+
+      for (i=1; i<iv_vecTypeNames.size(); ++i) {
+        icu::UnicodeString const & name = iv_vecTypeNames[i];
+        for (j=i+1; j<iv_vecTypeNames.size(); ++j) {
+          ASSERT_OR_RETURN_FALSE(name != iv_vecTypeNames[j]);
+        }
+      }
+
+      for (i=1; i<iv_vecFeatureBaseNames.size(); ++i) {
+        ASSERT_OR_RETURN_FALSE( (0<iv_vecRangeTypes[i]) && (iv_vecRangeTypes[i]<iv_vecTree.size()) );
+        // don't check for feature name uniqueness here
+        // feature names are no longer unique
+      }
+
+      return true;
+    }
+
+    bool TypeSystem::debugIsConsistent() const {
+      ASSERT_OR_RETURN_FALSE( debugIsTreeConsistent() );
+      ASSERT_OR_RETURN_FALSE( iv_vecFeatureBaseNames.size() == iv_vecFeatureOffset.size() );
+      ASSERT_OR_RETURN_FALSE( iv_vecFeatureNumber.size() == iv_vecTypeNames.size() );
+      return true;
+    }
+
+
+
+    void TypeSystem::printTree(int tab, TyFSType type, ostream& os) const {
+      int i,j;
+      for (i=0; i<tab; ++i) os << " ";
+
+      os << iv_vecTypeNames[type] << " (" << (int) type << ")" << endl;
+
+      vector<TyFSFeature> const & features = iv_vecIntroducedFeatures[type];
+      for (j=0; j<(int)features.size(); ++j) {
+        for (i=0; i<tab; ++i) os << " ";
+        os << " [" << iv_vecFeatureBaseNames[features[j]] << " (" << features[j] << "): " << iv_vecTypeNames[ iv_vecRangeTypes[features[j]] ] << "]" << endl;
+      }
+
+      for (j=0; j<(int)iv_vecTree[type].size(); ++j) {
+        printTree(tab+4, iv_vecTree[type][j], os);
+      }
+
+    }
+
+    void TypeSystem::print(ostream& os) const {
+      os << "===============================================" << endl;
+      os << "TREE: " << endl;
+      assert( debugIsTreeConsistent() );
+      printTree(0, iv_tyTop, os);
+      os << "---------------------------------------------" << endl;
+      size_t i,j;
+
+      os << "FEATURE_NAMES" << endl;
+
+      for (i=0; i<iv_vecFeatureBaseNames.size(); ++i) {
+        os << "   " << i << ": " << iv_vecFeatureBaseNames[i] << endl;
+      }
+
+      os << "TYPE_NAMES:" << endl;
+      for (i=0; i<iv_vecTypeNames.size(); ++i) {
+        os << "   " << i << ": " << iv_vecTypeNames[i] << endl;
+      }
+
+      os << "FEATURENUMBER:" << endl;
+      for (i=0; i<iv_vecFeatureNumber.size(); ++i) {
+        os << "   " << i << ": " << iv_vecFeatureNumber[i] << "  (" << iv_vecTypeNames[i] << ")" << endl;
+      }
+
+      os << "FEATUREOFFSET: " << endl;
+      for (i=0; i<iv_vecFeatureOffset.size(); ++i) {
+        os << "   " << i << ": " << iv_vecFeatureOffset[i] << "  (" << iv_vecFeatureBaseNames[i] << ")" << endl;
+      }
+
+      os << "APPROP:" << endl;
+      os << "   ";
+      for (i=0; i<iv_vecFeatureBaseNames.size(); ++i) {
+        os << i << "  ";
+      }
+      os << endl;
+      for (i=0; i<iv_vecApprop.size(); ++i) {
+        os << i << ": ";
+        for (j=0; j<iv_vecApprop[i].size(); ++j) {
+          os << iv_vecApprop[i][j] << "  ";
+        }
+        os << endl;
+      }
+
+      os << "TYPEFEATUREOFFSET:" << endl;
+      for (i=0; i<iv_vecTypeFeatureOffsetMapping.size(); ++i) {
+        os << i << ": ";
+        for (j=0; j<iv_vecTypeFeatureOffsetMapping[i].size(); ++j) {
+          os << iv_vecTypeFeatureOffsetMapping[i][j] << " ";
+        }
+        os << endl;
+      }
+
+    }
+
+#else
+    bool TypeSystem::debugIsConsistent() const {
+      cerr << "WARNING: uima::lowlevel::TypeSystem::debugIsConsistent is unavailable in release builds" << endl;
+      return true;
+    }
+    void TypeSystem::print(ostream& os) const {
+      os << endl << "WARNING: Can only print the TypeSystem with a debug uima library" << endl;
+      ;
+    }
+#endif
+
+  }
+}
+/* ----------------------------------------------------------------------- */
+
+
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/lowlevel_typesystem.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/sofastream.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/sofastream.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/sofastream.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/sofastream.cpp Sat Feb  3 08:54:09 2007
@@ -0,0 +1,536 @@
+
+/** @name sofastream.cpp
+-----------------------------------------------------------------------------
+
+ * 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.
+
+-----------------------------------------------------------------------------
+
+   Description: This file contains class {\tt SofaDataSteram}.
+
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Interface dependencies                                            */
+/* ----------------------------------------------------------------------- */
+//#define DEBUG_VERBOSE
+
+#include "uima/pragmas.hpp" //must be included first to disable warnings
+#include "uima/err_ids.h"
+#include "uima/msg.h"
+#include "uima/assertmsg.h"
+#include "uima/trace.hpp"
+#include "uima/resmgr.hpp"
+#include "uima/sofastream.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+#include "uima/arrayfs.hpp"
+#include "uima/casexception.hpp"
+#include "uima/endian.h"
+#include "uima/sofastreamhandler.hpp"
+namespace uima {
+
+
+
+// ----------------------------------------------------------- */
+//       RemoteSofaDataStream implementation                   */
+// ----------------------------------------------------------- */
+  //Constructor
+  RemoteSofaDataStream::RemoteSofaDataStream(SofaFS& aSofaFS) : iv_psofafs(NULL),
+      iv_pHandler(NULL), iv_pHandlerDll(NULL) {
+    iv_psofafs =  (SofaFS*) new FeatureStructure(aSofaFS.iv_tyFS,aSofaFS.getCAS());
+    assert(iv_psofafs->isValid());
+    assert(iv_psofafs->getType().getName().compare( UnicodeStringRef(CAS::TYPE_NAME_SOFA)) == 0 );
+  }
+
+  //Destructor
+  RemoteSofaDataStream::~RemoteSofaDataStream() {
+
+    if (iv_pHandlerDll != NULL) {
+      delete iv_pHandlerDll;
+      iv_pHandlerDll=NULL;
+    }
+    if (iv_psofafs != NULL) {
+      delete iv_psofafs;
+    }
+  }
+
+
+
+  //open - minbufsize optional
+  int RemoteSofaDataStream::open(size_t minbufsize) {
+    std::string sofauri;
+    std::string urischeme;
+    util::Filename const * pDllFile=NULL;
+
+    //get the sofa uri as UTF-8 string
+    iv_psofafs->getSofaURI().extract(0,
+                                     iv_psofafs->getSofaURI().length(),
+                                     sofauri,
+                                     CCSID::getDefaultSBCSInputCCSID() );
+    //get the uri scheme
+    int32_t pos = sofauri.find(":");
+    if (pos != -1) {
+      //get the uri scheme
+      urischeme = sofauri.substr(0,pos);
+    } else {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_INVALID_SOFAURI);
+      errMsg.addParam(sofauri);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    //look up sofa stream handler for uri scheme
+    if (urischeme.size() >  0)  {
+      pDllFile = uima::ResourceManager::getInstance().getStreamHandlerForURIScheme(urischeme);
+      if (pDllFile == NULL) {
+        ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SCHEMEHANDLER_NOT_REGISTERED);
+        errMsg.addParam(urischeme);
+        errMsg.addParam(sofauri);
+        UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                           UIMA_ERR_SOFADATASTREAM,
+                           errMsg,
+                           UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                           ErrorInfo::unrecoverable);
+      }
+    } else {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_INVALID_SOFAURI);
+      errMsg.addParam(sofauri);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    //load the handler
+    iv_pHandlerDll  = new util::DllProcLoaderFile(*pDllFile);
+    //assert(EXISTS(iv_pHandlerDll));
+    if (iv_pHandlerDll == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SCHEMEHANDLER_LOAD);
+      errMsg.addParam(pDllFile->getName());
+      errMsg.addParam(sofauri);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    uima::TyMakeStreamHandler procMaker = (TyMakeStreamHandler) iv_pHandlerDll->getProcedure(UIMA_SOFASTREAM_MAKE_HANDLER);
+    assert(EXISTS(procMaker));
+    if (NOTEXISTS(procMaker)) {
+      ResourceManager::getInstance().getLogger().logError("RemoteSofaDataStream::open() Could not get procedure makeHandler() ");
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SCHEMEHANDLER_GETPROC);
+      errMsg.addParam(pDllFile->getName());
+      errMsg.addParam(sofauri);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    /* first we need to create the handler */
+    iv_pHandler = (procMaker) ();
+
+    if (NOTEXISTS(iv_pHandler)) {
+      ResourceManager::getInstance().getLogger().logError("RemoteSofaDataStream::open() Could not instantiate stream handler. ");
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SCHEMEHANDLER_GETPROC);
+      errMsg.addParam(pDllFile->getName());
+      errMsg.addParam(sofauri);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    /* open the stream */
+    if (minbufsize > 0) {
+      iv_pHandler->openStream(sofauri.data(), minbufsize);
+    } else {
+      iv_pHandler->openStream(sofauri.data());
+    }
+
+    return 0;
+  }
+
+  // Have a lot of near-identical error code ... Could we make it simpler with a single error routine?  BLL
+
+  //getTotalStreamSize
+  INT64 RemoteSofaDataStream::getTotalStreamSizeInBytes() {
+    if (iv_pHandler == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_NOTOPEN);
+      errMsg.addParam("getTotalStreamSize");
+      errMsg.addParam(iv_psofafs->getSofaURI());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    return (iv_pHandler->getTotalStreamSize());
+  }
+
+  //howManyBytesAvailable
+  INT64 RemoteSofaDataStream::howManyBytesAvailable() {
+    if (iv_pHandler == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_NOTOPEN);
+      errMsg.addParam("HowManyBytesAvailable");
+      errMsg.addParam(iv_psofafs->getSofaURI());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    return ( iv_pHandler->howManyAvailable());
+  }
+
+  //read
+  int RemoteSofaDataStream::read( void * pbuffer, int elementSize, size_t numElements) {
+
+    if (iv_pHandler == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_NOTOPEN);
+      errMsg.addParam("read");
+      errMsg.addParam(iv_psofafs->getSofaURI());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    INT64 numbytesread = elementSize*numElements;
+
+    //read bytes
+    numbytesread = iv_pHandler->getNext(numbytesread,pbuffer);
+
+    //swap bytes if needed (data read is assumed to be BE)
+    if (numbytesread > 0) {
+      if ( elementSize==2 || elementSize==4 || elementSize == 8) {
+        // Convert BE data to host byte order
+        UIMA_HIBYTEFIRST(pbuffer, elementSize, numbytesread/elementSize);
+        return numbytesread/elementSize;        // return number of elements read
+      }
+    }
+    return numbytesread;                            // assume elementSize = 1
+  }
+
+  //seek
+  int RemoteSofaDataStream::seek(INT64 offset, int origin) {
+    if (iv_pHandler == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_NOTOPEN);
+      errMsg.addParam("seek");
+      errMsg.addParam(iv_psofafs->getSofaURI());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    return (iv_pHandler->seek(offset,origin));
+  }
+
+  //close
+  void RemoteSofaDataStream::close() {
+    if (iv_pHandler != NULL) {
+      iv_pHandler->closeStream();
+    }
+  }
+
+  //getDataPointer
+  const TySofaDataPointer RemoteSofaDataStream::getDataPointer() {
+
+    if (iv_pHandler == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_NOTOPEN);
+      errMsg.addParam("getDataPointer");
+      errMsg.addParam(iv_psofafs->getSofaURI());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    return (iv_pHandler->getDataPointer());
+
+  }
+
+  // ----------------------------------------------------------- */
+  //       LocalSofaDataStream implementation                    */
+  // ----------------------------------------------------------- */
+
+  //Constructor
+  LocalSofaDataStream::LocalSofaDataStream(SofaFS& aSofaFS) : iv_psofafs(NULL),
+      iv_psofadata(NULL), iv_pstringsofadata(NULL), iv_size(0),
+      iv_isstring(false), iv_isintarray(false),
+      iv_isfloatarray(false), iv_isbooleanarray(false),
+      iv_isbytearray(false),iv_isshortarray(false),
+      iv_islongarray(false),iv_isdoublearray(false),
+      iv_curpos(0) {
+    iv_psofafs =  (SofaFS*) new FeatureStructure(aSofaFS.iv_tyFS,aSofaFS.getCAS());
+    assert(iv_psofafs->isValid());
+    assert(iv_psofafs->getType().getName().compare( UnicodeStringRef(CAS::TYPE_NAME_SOFA)) == 0 );
+  }
+
+  //Destructor
+  LocalSofaDataStream::~LocalSofaDataStream() {
+    close();
+    if (iv_psofafs != NULL)
+      delete iv_psofafs;
+  }
+
+  //open - minbufsize ignored
+  int LocalSofaDataStream::open(size_t minbufsize) {
+
+    Type type = iv_psofafs->getType();
+    Feature stringfeat = type.getFeatureByBaseName(CAS::FEATURE_BASE_NAME_SOFASTRING);
+    Feature arrayfeat = type.getFeatureByBaseName(CAS::FEATURE_BASE_NAME_SOFAARRAY);
+
+    iv_curpos=0;
+    if  ( !iv_psofafs->isUntouchedFSValue(stringfeat) ) {     //local sofa - data in string
+      //convert string to UTF-8
+      UErrorCode errorcode = U_ZERO_ERROR ;
+      iv_size=0;
+      int32_t len;
+      iv_psofadata = u_strToUTF8(NULL, 0,
+                                 &len,
+                                 iv_psofafs->getStringValue(stringfeat).getBuffer(),
+                                 iv_psofafs->getStringValue(stringfeat).length(),
+                                 &errorcode);
+      if (!U_SUCCESS(errorcode)  && errorcode != U_BUFFER_OVERFLOW_ERROR ) {
+        ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_UNSUPPORTED_TYPE);
+        errMsg.addParam(stringfeat.getName());
+        UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                           UIMA_ERR_SOFADATASTREAM,
+                           errMsg,
+                           UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                           ErrorInfo::unrecoverable);
+      }
+      iv_pstringsofadata = new char[len];
+      iv_size = len;
+      errorcode = U_ZERO_ERROR ;
+      iv_psofadata = u_strToUTF8(iv_pstringsofadata, iv_size,
+                                 &len,
+                                 iv_psofafs->getStringValue(stringfeat).getBuffer(),
+                                 iv_psofafs->getStringValue(stringfeat).length(),
+                                 &errorcode);
+      if (!U_SUCCESS(errorcode)  ) {
+        ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_UNSUPPORTED_TYPE);
+        errMsg.addParam(stringfeat.getName());
+        UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                           UIMA_ERR_SOFADATASTREAM,
+                           errMsg,
+                           UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                           ErrorInfo::unrecoverable);
+      }
+      iv_isstring=true;
+    } else if ( !iv_psofafs->isUntouchedFSValue(arrayfeat) ) {  //local sofa - data in fs array
+
+      FeatureStructure arrayFS = iv_psofafs->getFSValue(arrayfeat);
+      Type rangeType = arrayFS.getType();
+      UnicodeStringRef rangeTypeName = rangeType.getName();
+
+      if (rangeTypeName.compare(CAS::TYPE_NAME_INTEGER_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->getCArrayFromFS(arrayFS.iv_tyFS);
+        iv_size = iv_psofafs->getIntArrayFSValue(arrayfeat).size()*sizeof(int);
+        iv_isintarray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_FLOAT_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->getCArrayFromFS(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getFloatArrayFSValue(arrayfeat).size()*sizeof(float);
+        iv_isfloatarray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_BOOLEAN_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->get8BitArray(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getBooleanArrayFSValue(arrayfeat).size()*sizeof(char);
+        iv_isbooleanarray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_BYTE_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->get8BitArray(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getByteArrayFSValue(arrayfeat).size()*sizeof(char);
+        iv_isbytearray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_SHORT_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->get16BitArray(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getShortArrayFSValue(arrayfeat).size()*sizeof(short);
+        iv_isshortarray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_LONG_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->get64BitArray(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getLongArrayFSValue(arrayfeat).size()*sizeof(INT64);
+        iv_islongarray = true;
+      } else if (rangeTypeName.compare( CAS::TYPE_NAME_DOUBLE_ARRAY) ==0) {
+        iv_psofadata =  (char*) iv_psofafs->getCAS().getHeap()->get64BitArray(arrayFS.iv_tyFS);
+        iv_size= iv_psofafs->getDoubleArrayFSValue(arrayfeat).size()*sizeof(INT64);
+        iv_isdoublearray = true;
+      } else {
+        ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_UNSUPPORTED_TYPE);
+        errMsg.addParam(rangeTypeName);
+        UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                           UIMA_ERR_SOFADATASTREAM,
+                           errMsg,
+                           UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                           ErrorInfo::unrecoverable);
+      }
+    } else {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_NOTSET);
+      errMsg.addParam(type.getName());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    return 0;
+  }
+
+  //getTotalStreamSize
+  INT64 LocalSofaDataStream::getTotalStreamSizeInBytes() {
+    if (iv_size==0) {
+      return SOFASTREAMHANDLER_EOF;
+    } else return iv_size;
+  }
+
+  //howManyBytesAvailable
+  INT64 LocalSofaDataStream::howManyBytesAvailable() {
+    return (getTotalStreamSizeInBytes()-iv_curpos);
+  }
+
+
+  //read
+  int LocalSofaDataStream::read( void * pbuffer, int elementSize, size_t numElements) {
+    //check valid sofa data
+    if (iv_psofadata == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_NOTSET);
+      errMsg.addParam(iv_psofafs->getType().getName());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    //check for eof
+    if (iv_curpos == iv_size) {
+      return SOFASTREAMHANDLER_EOF;
+    }
+
+    //validate element size vis-a-vis datatype of sofa data
+    if (iv_isstring && elementSize != 1) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_ELEMENTSIZE);
+      errMsg.addParam(elementSize);
+      errMsg.addParam(CAS::TYPE_NAME_STRING);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    } else if (iv_isintarray && elementSize != sizeof(int)) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_ELEMENTSIZE);
+      errMsg.addParam(elementSize);
+      errMsg.addParam(CAS::TYPE_NAME_INTEGER_ARRAY);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    } else if (iv_isfloatarray && elementSize != sizeof(float) ) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_ELEMENTSIZE);
+      errMsg.addParam(elementSize);
+      errMsg.addParam(CAS::TYPE_NAME_FLOAT_ARRAY);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    INT64 numbytesread=elementSize*numElements;
+    if (numbytesread > howManyBytesAvailable() ) {
+      numbytesread= howManyBytesAvailable();
+    }
+
+    //read bytes
+    memcpy(pbuffer,iv_psofadata+iv_curpos,numbytesread);
+
+    //move current read position
+    iv_curpos += numbytesread;
+
+    return numbytesread;
+  }
+
+  //seek
+  int LocalSofaDataStream::seek(INT64 offset, int origin) {
+    if (iv_psofadata == NULL) {
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_LOCAL_SOFADATA_NOTSET);
+      errMsg.addParam(iv_psofafs->getType().getName());
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+
+    switch (origin) {
+    case SEEK_SET:
+      iv_curpos = offset;
+      break ;
+    case SEEK_CUR:
+      iv_curpos += offset;
+      break ;
+    case SEEK_END:
+      iv_curpos = getTotalStreamSizeInBytes() - offset;
+      break ;
+    default:
+      ErrorMessage errMsg = ErrorMessage(UIMA_MSG_ID_EXC_SOFADATASTREAM_INVALID_SEEK_ORIGIN);
+      errMsg.addParam(origin);
+      UIMA_EXC_THROW_NEW(SofaDataStreamException,
+                         UIMA_ERR_SOFADATASTREAM,
+                         errMsg,
+                         UIMA_MSG_ID_EXCON_SOFADATASTREAM,
+                         ErrorInfo::unrecoverable);
+    }
+    return 0;
+  }
+
+  //close
+  void LocalSofaDataStream::close() {
+    if (iv_pstringsofadata != NULL)
+      delete iv_pstringsofadata;
+    iv_pstringsofadata = NULL;
+    iv_curpos=0;
+    iv_psofadata = NULL;
+    iv_size=0;
+    iv_isstring=false;
+    iv_isintarray=false;
+    iv_isfloatarray=false;
+  }
+
+  //getDataPointer
+  const TySofaDataPointer LocalSofaDataStream::getDataPointer() {
+    TySofaDataPointer dataptr=NULL;
+    if (iv_psofadata != NULL) {
+      dataptr = (TySofaDataPointer) iv_psofadata;
+    }
+    return dataptr;
+  }
+
+
+} //namespace uima

Propchange: incubator/uima/uimacpp/trunk/src/cas/sofastream.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/typenamespace.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/typenamespace.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/typenamespace.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/typenamespace.cpp Sat Feb  3 08:54:09 2007
@@ -0,0 +1,151 @@
+/** \file typenamespace.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+
+#include "uima/typenamespace.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  TypeNameSpace::TypeNameSpace(uima::TypeSystem const & crTypeSystem, icu::UnicodeString const & crName)
+      : iv_usName(crName),
+      iv_cpTypeSystem( & crTypeSystem ) {}
+
+  Type TypeNameSpace::getType(icu::UnicodeString const & crTypeBaseName) const {
+    icu::UnicodeString typeName(iv_usName);
+    typeName.append((UChar) TYPENAMESPACE_SEP);
+    typeName.append(crTypeBaseName);
+    return iv_cpTypeSystem->getType(typeName);
+  }
+
+  icu::UnicodeString const & TypeNameSpace::getName() const {
+    return iv_usName;
+  }
+
+  void TypeNameSpace::getAllTypes(vector<Type> & rResult) const {
+    rResult.clear();
+    vector<Type> allTypes;
+    iv_cpTypeSystem->getAllTypes(allTypes);
+    size_t i;
+    for (i=0; i<allTypes.size(); ++i) {
+      Type t = allTypes[i];
+      uima::UnicodeStringRef us = t.getName();
+      int ix = us.lastIndexOf((UChar) TYPENAMESPACE_SEP);
+      if (ix != -1) {
+        icu::UnicodeString nameSpace;
+        us.extract(0, ix, nameSpace);
+        if (nameSpace == iv_usName) {
+          rResult.push_back(t);
+        }
+      }
+    }
+  }
+
+  TypeSystem const & TypeNameSpace::getTypeSystem() const {
+    assert( EXISTS(iv_cpTypeSystem) );
+    return *iv_cpTypeSystem;
+  }
+
+
+  ////////////////////////////////////////////////////////////
+
+
+  TypeNameSpaceImport::TypeNameSpaceImport( uima::TypeSystem const & crTypeSystem)
+      : iv_cpTypeSystem( & crTypeSystem) {}
+
+  void TypeNameSpaceImport::addNameSpace(TypeNameSpace const & crNamespace) {
+    iv_vecImports.push_back(crNamespace);
+  }
+
+  bool TypeNameSpaceImport::getType(icu::UnicodeString const & crRelativeTypeName, Type & rResult) const {
+    rResult = Type();
+    size_t i;
+    for (i=0; i<iv_vecImports.size(); ++i) {
+      TypeNameSpace nameSpace = iv_vecImports[i];
+
+      Type t = nameSpace.getType(crRelativeTypeName);
+      if (t.isValid()) {
+        // if the type was found previously
+        if (rResult.isValid()) {
+          rResult = Type();
+          return false;
+        }
+        rResult = t;
+      }
+    }
+    return true;
+  }
+
+  void TypeNameSpaceImport::getAllTypes(vector<Type> & rResult) const {
+    rResult.clear();
+    size_t i,j;
+    for (i=0; i<iv_vecImports.size(); ++i) {
+      TypeNameSpace nameSpace = iv_vecImports[i];
+      vector<Type> types;
+      nameSpace.getAllTypes(types);
+      for (j=0; j<types.size(); ++j) {
+        rResult.push_back(types[j]);
+      }
+    }
+  }
+
+
+  TypeSystem const & TypeNameSpaceImport::getTypeSystem() const {
+    assert( EXISTS(iv_cpTypeSystem) );
+    return *iv_cpTypeSystem;
+  }
+
+
+
+}
+
+/* ----------------------------------------------------------------------- */
+
+
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/typenamespace.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/typesystem.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/typesystem.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/typesystem.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/typesystem.cpp Sat Feb  3 08:54:09 2007
@@ -0,0 +1,328 @@
+/** \file typesystem.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/typesystem.hpp"
+#include "uima/lowlevel_typesystem.hpp"
+#include "uima/msg.h"
+#include "uima/internal_fspromoter.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+namespace uima {
+  UIMA_EXC_CLASSIMPLEMENT(InvalidFSTypeObjectException, CASException);
+  UIMA_EXC_CLASSIMPLEMENT(InvalidFSFeatureObjectException, CASException);
+  UIMA_EXC_CLASSIMPLEMENT(TypeSystemAlreadyCommittedException, CASException);
+
+  void Feature::checkValidity() const {
+    if (!isValid()) {
+      UIMA_EXC_THROW_NEW(InvalidFSFeatureObjectException,
+                         UIMA_ERR_INVALID_FSFEATURE_OBJECT,
+                         UIMA_MSG_ID_EXC_INVALID_FSFEATURE_OBJECT,
+                         ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
+                         ErrorInfo::recoverable
+                        );
+    }
+  }
+
+  void Feature::getRangeType(Type& result) const {
+    checkValidity();
+    lowlevel::TyFSType type = iv_typeSystem->getRangeType(iv_tyFeature);
+    Type res = internal::FSPromoter::promoteType(type, *iv_typeSystem);
+    result = res;
+  }
+
+  Type Feature::getRangeType() const {
+    checkValidity();
+    lowlevel::TyFSType type = iv_typeSystem->getRangeType(iv_tyFeature);
+    return internal::FSPromoter::promoteType(type, *iv_typeSystem);
+  }
+
+  Type Feature::getIntroType() const {
+    checkValidity();
+    lowlevel::TyFSType type = iv_typeSystem->getIntroType(iv_tyFeature);
+    return internal::FSPromoter::promoteType(type, *iv_typeSystem);
+  }
+
+  Feature::Feature(lowlevel::TyFSFeature aFeature, uima::lowlevel::TypeSystem & typeSystem)
+      : iv_tyFeature(aFeature),
+      iv_typeSystem( & typeSystem) {}
+
+  Feature::Feature()
+      : iv_tyFeature(0),
+      iv_typeSystem( NULL ) {}
+
+  bool Feature::isValid() const {
+    return(iv_tyFeature != 0) && (EXISTS(iv_typeSystem));
+  }
+
+  UnicodeStringRef Feature::getName() const {
+    checkValidity();
+    return UnicodeStringRef(iv_typeSystem->getFeatureBaseName(iv_tyFeature) );
+  }
+
+  UnicodeStringRef Feature::getCreatorID() const {
+    checkValidity();
+    return UnicodeStringRef( iv_typeSystem->getFeatureCreatorID(iv_tyFeature) );
+  }
+
+
+  bool Feature::operator==(Feature const & crOther) const {
+//      checkValidity();
+//      crOther.checkValidity();
+    return( (iv_tyFeature == crOther.iv_tyFeature) && (iv_typeSystem == crOther.iv_typeSystem) );
+  }
+
+  /* taph 07.06.2002: we need an explicit != because of template deduction problems */
+  bool Feature::operator!=(Feature const & crOther) const {
+    return( !( (*this) == crOther) );
+  }
+
+  void Feature::getIntroType(Type & rResult) const {
+    checkValidity();
+    uima::lowlevel::TyFSType tyIntroType = iv_typeSystem->getIntroType(iv_tyFeature);
+    rResult = uima::internal::FSPromoter::promoteType(tyIntroType, *iv_typeSystem);
+  }
+
+  uima::TypeSystem const & Feature::getTypeSystem() const {
+    checkValidity();
+    return *iv_typeSystem;
+  }
+
+
+/////////////////////////////////////////////////////
+// Type
+
+  void Type::checkValidity() const {
+    if (!isValid()) {
+      UIMA_EXC_THROW_NEW(InvalidFSTypeObjectException,
+                         UIMA_ERR_INVALID_FSTYPE_OBJECT,
+                         UIMA_MSG_ID_EXC_INVALID_FSTYPE_OBJECT,
+                         ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
+                         ErrorInfo::recoverable
+                        );
+    }
+  }
+
+  Type::Type(lowlevel::TyFSType aType, uima::lowlevel::TypeSystem & typeSystem)
+      : iv_tyType(aType),
+      iv_typeSystem( & typeSystem) {}
+
+  Type::Type()
+      : iv_tyType(lowlevel::TypeSystem::INVALID_TYPE),
+      iv_typeSystem(NULL) {}
+
+  bool Type::isValid() const {
+    return(iv_tyType != 0) && (EXISTS(iv_typeSystem));
+  }
+
+  UnicodeStringRef Type::getName() const {
+    checkValidity();
+    return UnicodeStringRef( iv_typeSystem->getTypeName(iv_tyType) );
+  }
+
+  UnicodeStringRef Type::getCreatorID() const {
+    checkValidity();
+    return UnicodeStringRef( iv_typeSystem->getTypeCreatorID(iv_tyType) );
+  }
+
+  void Type::getAppropriateFeatures(vector<uima::Feature> & rResult) const {
+    checkValidity();
+    rResult.clear();
+    vector<uima::lowlevel::TyFSFeature> lowlevelResult;
+    iv_typeSystem->getAppropriateFeatures( iv_tyType, lowlevelResult );
+    vector<uima::lowlevel::TyFSFeature>::const_iterator cit;
+    for (cit = lowlevelResult.begin(); cit != lowlevelResult.end(); ++cit) {
+      rResult.push_back( uima::internal::FSPromoter::promoteFeature( *cit, *iv_typeSystem ) );
+    }
+  }
+
+  bool Type::isAppropriateFeature(Feature const & f) const {
+    checkValidity();
+    return iv_typeSystem->isAppropriateFeature( iv_tyType, uima::internal::FSPromoter::demoteFeature(f) );
+  }
+
+  void Type::getDirectSubTypes(vector<uima::Type> & rResult) const {
+    checkValidity();
+    rResult.clear();
+    vector<uima::lowlevel::TyFSType> lowlevelResult;
+    iv_typeSystem->getDirectSubTypes(iv_tyType, lowlevelResult);
+    vector<uima::lowlevel::TyFSType>::const_iterator cit;
+    for (cit = lowlevelResult.begin(); cit != lowlevelResult.end(); ++cit) {
+      rResult.push_back( uima::internal::FSPromoter::promoteType( *cit, *iv_typeSystem ) );
+    }
+  }
+
+  void Type::getSubTypes(std::vector<Type> & rResult) const {
+    checkValidity();
+    rResult.clear();
+    vector<uima::lowlevel::TyFSType> lowlevelResult;
+    iv_typeSystem->getSubsumedTypes(iv_tyType, lowlevelResult);
+    vector<uima::lowlevel::TyFSType>::const_iterator cit;
+    for (cit = lowlevelResult.begin(); cit != lowlevelResult.end(); ++cit) {
+      rResult.push_back( uima::internal::FSPromoter::promoteType( *cit, *iv_typeSystem ) );
+    }
+  }
+
+  Feature Type::getFeatureByBaseName(icu::UnicodeString const & crBaseName) const {
+    checkValidity();
+    lowlevel::TyFSFeature tyFeature = iv_typeSystem->getFeatureByBaseName(iv_tyType, crBaseName);
+    return uima::internal::FSPromoter::promoteFeature(tyFeature, *iv_typeSystem);
+  }
+
+
+  bool Type::operator==(Type const & crOther) const {
+//      checkValidity();
+//      crOther.checkValidity();
+    return( (iv_tyType == crOther.iv_tyType) && (iv_typeSystem == crOther.iv_typeSystem) );
+  }
+
+  /* taph 07.06.2002: we need an explicit != because of template deduction problems */
+  bool Type::operator!=(Type const & crOther) const {
+    return( !( (*this) == crOther ) );
+  }
+
+  bool Type::operator<(Type const & other) const {
+    return iv_tyType < other.iv_tyType;
+  }
+
+  bool Type::subsumes(Type const & crType) const {
+    checkValidity();
+    crType.checkValidity();
+    return( iv_typeSystem->subsumes( iv_tyType, crType.iv_tyType) );
+  }
+
+  uima::TypeSystem const & Type::getTypeSystem() const {
+    checkValidity();
+    return *iv_typeSystem;
+  }
+
+  bool Type::isStringSubType() const {
+    return iv_typeSystem->isStringSubType(iv_tyType);
+  }
+
+  ////////////////////////////////////////////////////////////
+  // TypeSystem
+
+  const char TypeSystem::FEATURE_SEPARATOR = UIMA_TYPE_FEATURE_SEPARATOR_CHAR;
+  const char TypeSystem::NAMESPACE_SEPARATOR = UIMA_NAMESPACE_SEPARATOR_CHAR;
+
+  TypeSystem::TypeSystem() {}
+
+  TypeSystem::~TypeSystem() {}
+
+  Type TypeSystem::getTopType() const {
+    return uima::internal::FSPromoter::promoteType( getLowlevelTypeSystem().getTopType(), getLowlevelTypeSystem() );
+  }
+
+
+  Type TypeSystem::getType(icu::UnicodeString const & crTypeName) const {
+    return internal::FSPromoter::promoteType( getLowlevelTypeSystem().getTypeByName( crTypeName ), getLowlevelTypeSystem() );
+  }
+
+
+  Feature TypeSystem::getFeatureByFullName(icu::UnicodeString const & crFeatureName) const {
+    return internal::FSPromoter::promoteFeature( getLowlevelTypeSystem().getFeatureByFullName( crFeatureName ), getLowlevelTypeSystem() );
+  }
+
+  void TypeSystem::getAllTypes(vector<Type> & rResult) const {
+    vector<lowlevel::TyFSType> vecLOLTypes;
+    getLowlevelTypeSystem().getAllTypes(vecLOLTypes);
+    rResult.clear();
+    size_t i;
+    for (i=0; i<vecLOLTypes.size(); ++i) {
+      rResult.push_back( uima::internal::FSPromoter::promoteType(vecLOLTypes[i], getLowlevelTypeSystem()));
+    }
+  }
+
+  void TypeSystem::getAllFeatures(vector<Feature> & rResult) const {
+    vector<lowlevel::TyFSFeature> vecLOLFeatures;
+    getLowlevelTypeSystem().getAllFeatures(vecLOLFeatures);
+    rResult.clear();
+    size_t i;
+    for (i=0; i<vecLOLFeatures.size(); ++i) {
+      rResult.push_back( uima::internal::FSPromoter::promoteFeature(vecLOLFeatures[i], getLowlevelTypeSystem()));
+    }
+  }
+
+  bool TypeSystem::isPrimitive(lowlevel::TyFSType tyType) const {
+
+    //lowlevel::TyFSType tyType = uima::internal::FSPromoter::demoteType(type);
+    return (tyType == uima::internal::gs_tyIntegerType)
+           ||   (tyType == uima::internal::gs_tyFloatType)
+           ||   (tyType == uima::internal::gs_tyStringType)
+           ||   ( getLowlevelTypeSystem().subsumes(uima::internal::gs_tyStringType, tyType) )
+           ||   (tyType == uima::internal::gs_tyByteType)
+           ||   (tyType == uima::internal::gs_tyBooleanType)
+           ||   (tyType == uima::internal::gs_tyShortType)
+           ||   (tyType == uima::internal::gs_tyLongType)
+           ||   (tyType == uima::internal::gs_tyDoubleType)
+           ;
+  }
+
+  bool TypeSystem::isStringSubType(lowlevel::TyFSType tyType) const {
+    //lowlevel::TyFSType tyType = uima::internal::FSPromoter::demoteType(type);
+    return  ( getLowlevelTypeSystem().getParentType(tyType) == uima::internal::gs_tyStringType);
+  }
+
+  /*------------------------------ Static Methods -------------------------------*/
+
+  // Release contents of vector container allocated by some of the "get" methods
+  void TypeSystem::release(std::vector<uima::Type> & rResult) {
+    rResult.clear();
+  }
+
+  void TypeSystem::release(std::vector<uima::Feature> & rResult) {
+    rResult.clear();
+  }
+}
+/* ----------------------------------------------------------------------- */
+
+
+
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/typesystem.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/xcasdeserializer.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/xcasdeserializer.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/xcasdeserializer.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/xcasdeserializer.cpp Sat Feb  3 08:54:09 2007
@@ -0,0 +1,215 @@
+/** \file xcasdeserializer.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+#include <memory>
+
+#include <xercesc/sax2/XMLReaderFactory.hpp>
+#include <xercesc/sax2/SAX2XMLReader.hpp>
+#include <xercesc/sax2/DefaultHandler.hpp>
+
+
+#include "uima/xmlerror_handler.hpp"
+#include "uima/xcasdeserializer.hpp"
+#include "uima/xcasdeserializer_handler.hpp"
+
+#include "uima/arrayfs.hpp"
+#include "uima/lowlevel_indexrepository.hpp"
+#include "uima/lowlevel_indexiterator.hpp"
+#include "uima/internal_casimpl.hpp"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/fsindexrepository.hpp"
+#include "uima/annotator_context.hpp"
+
+#include "uima/msg.h"
+#include "uima/resmgr.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+  XCASDeserializer::XCASDeserializer() {}
+
+  XCASDeserializer::~XCASDeserializer() {}
+
+  void XCASDeserializer::deserialize(char const * xcasFilename, CAS & cas) {
+
+    LocalFileInputSource fileIS (XMLString::transcode(xcasFilename));
+    XCASDeserializer::deserialize(fileIS, cas);
+
+  }
+
+  void XCASDeserializer::deserialize(UnicodeString & xcasFilename, CAS & cas) {
+    char buff[1024];
+    xcasFilename.extract(0, xcasFilename.length(), buff);
+    LocalFileInputSource fileIS (XMLString::transcode(buff));
+    XCASDeserializer::deserialize(fileIS, cas);
+  }
+
+  void XCASDeserializer::deserialize(char const * xcasFilename, CAS & cas,  uima::AnnotatorContext  * const ctx) {
+
+    LocalFileInputSource fileIS (XMLString::transcode(xcasFilename));
+    XCASDeserializer::deserialize(fileIS, cas, ctx);
+
+  }
+
+  void XCASDeserializer::deserialize(InputSource const & crInputSource, CAS & cas) {
+    // Create a SAX2 parser object.
+    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
+
+    //register content handler
+    XCASDeserializerHandler * contentHandler = new XCASDeserializerHandler(cas, NULL);
+    parser->setContentHandler(contentHandler);
+
+    //register error handler
+    XMLErrorHandler* errorHandler = new XMLErrorHandler();
+    parser->setErrorHandler(errorHandler);
+
+    // Parse the XML document.
+    // Document content sent to registered ContentHandler instance.
+    try {
+      parser->parse(crInputSource);
+    } catch (const XMLException& e) {
+      char* message = XMLString::transcode(e.getMessage());
+      cerr << "XMLException message is: \n"
+      << message << "\n";
+
+      ErrorInfo errInfo;
+      errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
+      ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
+      assertWithMsg(sizeof(XMLCh) == sizeof(UChar), "Port required");
+      msg.addParam((UChar const *) e.getMessage() );
+      msg.addParam( 0 );
+      msg.addParam( 0 );
+      errInfo.setMessage(msg);
+      errInfo.setSeverity(ErrorInfo::unrecoverable);
+      ExcIllFormedInputError exc(errInfo);
+      throw exc;
+    }
+    catch (const SAXParseException& e) {
+      char* message = XMLString::transcode(e.getMessage());
+      cerr << "SaxParseException message is: \n"
+      << message << "\n";
+      ErrorInfo errInfo;
+      errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
+      ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
+      assertWithMsg(sizeof(XMLCh) == sizeof(UChar), "Port required");
+      msg.addParam((UChar const *) e.getMessage() );
+      msg.addParam( 0 );
+      msg.addParam( 0 );
+      errInfo.setMessage(msg);
+      errInfo.setSeverity(ErrorInfo::unrecoverable);
+      ExcIllFormedInputError exc(errInfo);
+      throw exc;
+    }
+
+    // Delete the parser instance and handlers
+    delete contentHandler;
+    delete errorHandler;
+    delete parser;
+  }
+
+  void XCASDeserializer::deserialize(InputSource const & crInputSource, CAS & cas, uima::AnnotatorContext  * const ctx) {
+    // Create a SAX2 parser object.
+    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
+
+    //register content handler
+    XCASDeserializerHandler * contentHandler = new XCASDeserializerHandler(cas, ctx);
+    parser->setContentHandler(contentHandler);
+
+    //register error handler
+    XMLErrorHandler* errorHandler = new XMLErrorHandler();
+    parser->setErrorHandler(errorHandler);
+
+    // Parse the XML document.
+    // Document content sent to registered ContentHandler instance.
+    try {
+      parser->parse(crInputSource);
+    } catch (const XMLException& e) {
+      char* message = XMLString::transcode(e.getMessage());
+      cerr << "XMLException message is: \n"
+      << message << "\n";
+
+      ErrorInfo errInfo;
+      errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
+      ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
+      assertWithMsg(sizeof(XMLCh) == sizeof(UChar), "Port required");
+      msg.addParam((UChar const *) e.getMessage() );
+      msg.addParam( 0 );
+      msg.addParam( 0 );
+      errInfo.setMessage(msg);
+      errInfo.setSeverity(ErrorInfo::unrecoverable);
+      ExcIllFormedInputError exc(errInfo);
+      throw exc;
+    }
+    catch (const SAXParseException& e) {
+      char* message = XMLString::transcode(e.getMessage());
+      cerr << "SaxParseException message is: \n"
+      << message << "\n";
+      ErrorInfo errInfo;
+      errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
+      ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
+      assertWithMsg(sizeof(XMLCh) == sizeof(UChar), "Port required");
+      msg.addParam((UChar const *) e.getMessage() );
+      msg.addParam( 0 );
+      msg.addParam( 0 );
+      errInfo.setMessage(msg);
+      errInfo.setSeverity(ErrorInfo::unrecoverable);
+      ExcIllFormedInputError exc(errInfo);
+      throw exc;
+    }
+
+    // Delete the parser instance and handlers
+    delete contentHandler;
+    delete errorHandler;
+    delete parser;
+  }
+
+
+}
+
+
+
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/xcasdeserializer.cpp
------------------------------------------------------------------------------
    svn:eol-style = native