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:59:26 UTC

svn commit: r503252 - in /incubator/uima/uimacpp/trunk/src/jni: ./ jni.cpp jni_string.cpp jni_utils.cpp

Author: eae
Date: Sat Feb  3 08:59:25 2007
New Revision: 503252

URL: http://svn.apache.org/viewvc?view=rev&rev=503252
Log:
Initial entry

Added:
    incubator/uima/uimacpp/trunk/src/jni/
    incubator/uima/uimacpp/trunk/src/jni/jni.cpp   (with props)
    incubator/uima/uimacpp/trunk/src/jni/jni_string.cpp   (with props)
    incubator/uima/uimacpp/trunk/src/jni/jni_utils.cpp   (with props)

Added: incubator/uima/uimacpp/trunk/src/jni/jni.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/jni/jni.cpp?view=auto&rev=503252
==============================================================================
--- incubator/uima/uimacpp/trunk/src/jni/jni.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/jni/jni.cpp Sat Feb  3 08:59:25 2007
@@ -0,0 +1,1138 @@
+/** @name jni.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: The C++ functions for the Java - C++ interface
+
+-----------------------------------------------------------------------------
+
+
+   08/04/2000  Initial creation
+
+-------------------------------------------------------------------------- */
+
+//#define DEBUG_VERBOSE 1
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+// this is included ONCE for the main source file of each binary
+//#include "uima/configure.h"
+
+#include "uima/pragmas.hpp"
+
+#include "uima/macros.h"
+#include "uima/location.hpp"
+#include "uima/filename.hpp"
+
+#include "uima/api.hpp"
+#include "uima/jni.hpp"
+
+#include "uima/sofaid.hpp"
+#include "uima/internal_casimpl.hpp"
+#include "uima/cas.hpp"
+#include "uima/internal_engine_base.hpp"
+#include "uima/internal_casdeserializer.hpp"
+#include "uima/result_specification.hpp"
+#include "uima/org_apache_uima_uimacpp_UimacppEngine.h"
+#include "uima/jni_utils.hpp"
+#include "uima/casiterator.hpp"
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+
+#define UIMA_JNI_CONCAT(x,y) x##y
+#define JAVA_PREFIX(FUNC) UIMA_JNI_CONCAT(Java_org_apache_uima_uimacpp_UimacppEngine_, FUNC )
+#define CONST_PREFIX(CONST) UIMA_JNI_CONCAT(org_apache_uima_uimacpp_UimacppEngine_, CONST )
+
+
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+static jobject getSerializedCasData (JNIEnv* jeEnv, jobject joJTaf, jint jiWhichData, uima::internal::SerializedCAS & crSerializedCAS);
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+/********************************************************************
+ ***** JNI Functions
+ ********************************************************************/
+
+/*********************************************************************
+ * static method to get this UIMACPP JNI version
+ */
+JNIEXPORT jstring JNICALL JAVA_PREFIX(getVersionJNI) (JNIEnv* jeEnv, jclass) {
+  try {
+    jstring jsVersion = jeEnv->NewStringUTF(UIMA_JNI_VERSION);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    return jsVersion;
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return NULL;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return NULL;
+  }
+}
+
+/*******************************************************************
+ * create UIMACPP resource manager
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(createResourceManagerJNI) (JNIEnv* jeEnv, jclass) {
+  try {
+    UIMA_TPRINT("createResourceManagerJNI() entered");
+
+    (void) uima::ResourceManager::createInstance("Main", UIMA_STRINGIFY(UIMA_PREFIX));
+
+    UIMA_TPRINT("createResourceManagerJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString());
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+
+}
+
+
+/********************************************************************
+ * configure UIMACPP resource manager
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(configureResourceManagerJNI) (JNIEnv* jeEnv,
+    jclass,
+    jstring jsWorkDirectory,
+    jstring jsDataDirectory) {
+  try {
+    UIMA_TPRINT("configureResourceManagerJNI entered");
+
+    uima::ResourceManager& rResourceManager = uima::ResourceManager::getInstance();
+
+    JNIUString workDir(jeEnv, jsWorkDirectory);
+    string strWorkDirectory;
+    workDir.convertToSystemCodePage(strWorkDirectory);
+
+    JNIUString dataDir(jeEnv, jsDataDirectory);
+    string strDataDirectory;
+    dataDir.convertToSystemCodePage(strDataDirectory);
+
+    UIMA_TPRINT(" configuring resource manager with");
+    UIMA_TPRINT("   working directory: " << strWorkDirectory);
+    UIMA_TPRINT("   data    directory: " << strDataDirectory);
+
+    // Since UIMA_DATAPATH is a list of paths and UIMACPP wants just one,
+    // we'll take the first by pretending to search for a empty file.
+    // Will find the first path that exists, or the last if none exist.
+    // No longer check that the data path exists.
+
+    uima::util::Filename dataPath("");
+    dataPath.determinePath( strDataDirectory.c_str());
+    uima::util::Location dataLocation(dataPath.getAsCString());
+
+    uima::util::Location workLocation(strWorkDirectory.c_str());
+    if (! workLocation.isExistent() ) {
+      uima::ErrorInfo errInfo(uima::ErrorMessage(UIMA_MSG_ID_RESMGR_WORKDIR_DOES_NOT_EXIST, strWorkDirectory.c_str()),
+                              UIMA_ERR_RESMGR_WORK_DIR_DOES_NOT_EXIST,
+                              uima::ErrorInfo::recoverable);
+      JNIUtils::throwNewInternalException(jeEnv, errInfo);
+      return;
+    }
+
+    rResourceManager.setNewLocationWork(workLocation);
+    rResourceManager.setNewLocationData(dataLocation);
+
+    rResourceManager.setupJavaLogging(jeEnv);
+
+    UIMA_TPRINT("configureResourceManagerJNI finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+/**********************************************************************
+ * constructs a new UIMACPP engine and CASSerializer
+ * and sets the field in the Java object
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(constructorJNI) (JNIEnv* jeEnv,
+    jobject joJTaf) {
+  try {
+    UIMA_TPRINT("constructorJNI() entered");
+
+    uima::JNIInstance * pInstance = new uima::JNIInstance();
+    if (pInstance == NULL) {
+      uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_OUT_OF_MEMORY,
+                              UIMA_ERR_ENGINE_OUT_OF_MEMORY,
+                              uima::ErrorInfo::unrecoverable);
+      JNIUtils::throwNewInternalException(jeEnv, errInfo);
+      return;
+    }
+    // setting engine
+    JNIUtils::setCppInstance(jeEnv, joJTaf, pInstance);
+
+    UIMA_TPRINT("constructorJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+/*********************************************************************
+ * deletes the objects created by constructorJNI()
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(destructorJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("destructorJNI() entered");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    delete pInstance;
+
+    UIMA_TPRINT("destructorJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+/**********************************************************************
+ * initialize engine
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(initializeJNI) (JNIEnv* jeEnv,
+    jobject joJTaf,
+    jstring jsConfigFile
+                                                  ) {
+  try {
+    UIMA_TPRINT("entering initializeJNI()");
+
+    assert(jsConfigFile != NULL);
+
+    JNIUString configFile(jeEnv, jsConfigFile);
+
+    uima::UnicodeStringRef uref = configFile.toUStrPtrLenPair();
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    uima::ErrorInfo errInfo;
+
+    UIMA_TPRINT("creating engine");
+    UIMA_TPRINT(uref);
+    uima::ResourceManager::getInstance().enableSchemaValidation(false);
+    // initialize engine
+    uima::AnalysisEngine * pEngine = uima::Framework::createAnalysisEngine( (UChar*)uref.getBuffer(), 
+		uref.length(), errInfo);
+    if (errInfo.getErrorId() != UIMA_ERR_NONE) {
+      assert( pEngine == NULL );
+      UIMA_TPRINT("Error during initializing engine (code= " << errInfo.getErrorId() << ")" );
+      JNIUtils::throwNewInternalException(jeEnv, errInfo );
+      return;
+    }
+    pInstance->setEngine( pEngine );
+    UIMA_TPRINT("engine created and set");
+
+    UIMA_TPRINT("Creating CAS");
+    // create CAS
+    uima::CAS * pCAS = pEngine->newCAS();
+    assert( EXISTS(pCAS) );
+    pInstance->setCAS(pCAS);
+    UIMA_TPRINT("CAS created");
+
+    UIMA_TPRINT("initializeJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  }
+#ifdef NDEBUG
+  catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+#endif
+}
+
+
+/**********************************************************************
+ * initialize engine
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(typeSystemInitJNI) (JNIEnv* jeEnv,
+    jobject joJTaf,
+
+    jobjectArray typeNames,
+    jobjectArray featureNames,
+    jintArray typeInheritance,
+    jintArray featDecls,
+    jint topTypeCode,
+    jintArray featureOffsets,
+    jintArray typeOrder,
+
+    jintArray stringSubTypes,
+    jobjectArray stringSubTypeValues,
+    jintArray stringSubTypeValuePos,
+
+    jobjectArray indexNames,
+    jintArray nameToIndexMap,
+    jintArray indexingStrategy,
+    jintArray comparatorIndex,
+    jintArray comparators
+                                                      ) {
+  try {
+    UIMA_TPRINT("entering typeSystemInitJNI()");
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    assert( typeNames != NULL );
+    assert( featureNames != NULL );
+    assert( typeInheritance != NULL );
+    assert( featDecls != NULL );
+    assert( typeOrder != NULL );
+//      assert( featureOffsets != NULL );
+
+    assert( indexNames != NULL );
+    assert( nameToIndexMap != NULL );
+    assert( indexingStrategy != NULL );
+    assert( comparatorIndex != NULL );
+    assert( comparators != NULL);
+
+    vector<icu::UnicodeString> vecTypeNames, vecFeatureNames, vecIndexNames, vecSubStringValues;
+
+    // prepare deserialization
+    uima::internal::SerializedCAS rSerCAS;
+    UIMA_TPRINT("converting type inh vector");
+    JNIUtils::createIntVector(jeEnv, typeInheritance, rSerCAS.iv_vecTypeInheritanceTable );
+    UIMA_TPRINT("   converted");
+    JNIUtils::createIntVector(jeEnv, featDecls, rSerCAS.iv_vecFeatureDefinitionTable );
+    UIMA_TPRINT("converting type name vector");
+    JNIUtils::createStringVector(jeEnv, typeNames, rSerCAS.iv_vecTypeSymbolTable, vecTypeNames);
+    UIMA_TPRINT("   converted");
+    JNIUtils::createStringVector( jeEnv, featureNames,  rSerCAS.iv_vecFeatureSymbolTable, vecFeatureNames );
+    JNIUtils::createIntVector(jeEnv, typeOrder, rSerCAS.iv_vecTypePriorityTable );
+    //      JNIUtils::createIntVector(jeEnv, featureOffsets, rSerCAS.iv_vecFeatureOffsetTable );
+    rSerCAS.iv_vecFeatureOffsetTable.clear();
+
+    JNIUtils::createIntVector(jeEnv, stringSubTypes, rSerCAS.iv_stringSubTypes);
+    JNIUtils::createStringVector(jeEnv, stringSubTypeValues, rSerCAS.iv_stringSubTypeValues, vecSubStringValues);
+    JNIUtils::createIntVector(jeEnv, stringSubTypeValuePos, rSerCAS.iv_stringSubTypeValuePos);
+
+    JNIUtils::createStringVector(jeEnv, indexNames, rSerCAS.iv_vecIndexIDTable, vecIndexNames );
+    JNIUtils::createIntVector(jeEnv,comparators, rSerCAS.iv_vecComparatorDefinitionTable);
+    JNIUtils::createIntVector(jeEnv,comparatorIndex, rSerCAS.iv_vecComparatorStartTable);
+    JNIUtils::createIntVector(jeEnv, indexingStrategy, rSerCAS.iv_vecIndexKindTable );
+
+    uima::AnalysisEngine * pEngine =  pInstance->getEngine();
+    uima::internal::EngineBase & engineBase = uima::internal::EngineBase::promoteEngine(*pEngine);
+    uima::internal::CASDefinition & casDef = engineBase.getCASDefinition();
+
+    UIMA_TPRINT("deserializng definitions");
+    // deserialize CAS definitions (type system and index info)
+    uima::internal::CASDeserializer deSerializer;
+    deSerializer.deserializeDefinitions( rSerCAS, casDef );
+    UIMA_TPRINT("   done deserializing definitions");
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    engineBase.reinitTypeSystem();
+
+    uima::CAS * pCAS = pInstance->getCAS();
+    if (pCAS != NULL) {
+      delete pCAS;
+      pInstance->setCAS(NULL);
+    }
+
+    UIMA_TPRINT("recreate CAS");
+    pCAS = pEngine->newCAS();
+    assert( EXISTS(pCAS) );
+    pInstance->setCAS(pCAS);
+
+    UIMA_TPRINT("typeSystemInitJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  }
+#ifdef NDEBUG
+  catch (...) {
+    //cout << "typeSystemInitJNI: Unknown Exception " << endl;
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+#endif
+}
+
+
+/**********************************************************************
+ * fill CAS
+ */
+
+JNIEXPORT void JNICALL JAVA_PREFIX(fillCASJNI) (JNIEnv* jeEnv,
+    jobject joJTaf,
+    jintArray heapArray,
+    jintArray fsIndex,
+    jobjectArray stringTable,
+    jbyteArray byteHeapArray,
+    jshortArray shortHeapArray,
+    jlongArray longHeapArray ) {
+  try {
+    UIMA_TPRINT("fillCASJNI() started");
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::CAS * cas = pInstance->getCAS();
+    assert( EXISTS(cas) );
+    uima::internal::SerializedCAS serCAS;
+
+    vector<icu::UnicodeString> vecStringTable;
+
+    JNIUtils::createStringVector(jeEnv, stringTable, serCAS.iv_vecStringSymbolTable, vecStringTable );
+#ifdef DEBUG_VERBOSE
+    size_t iVerbose;
+    UIMA_TPRINT("STRINGHeap: ");
+    for (iVerbose=0; iVerbose<serCAS.iv_vecStringSymbolTable.size(); ++iVerbose) {
+      UIMA_TPRINT("   " << iVerbose << ": " << serCAS.iv_vecStringSymbolTable[iVerbose]);
+    }
+#endif
+
+    JNIUtils::createIntVector(jeEnv, heapArray, serCAS.iv_vecFSHeapArray);
+#ifdef DEBUG_VERBOSE
+    UIMA_TPRINT("HEAP: ");
+    for (iVerbose=0; iVerbose<serCAS.iv_vecFSHeapArray.size(); ++iVerbose) {
+      UIMA_TPRINT("   " << iVerbose << ": " << serCAS.iv_vecFSHeapArray[iVerbose]);
+    }
+#endif
+
+    JNIUtils::createIntVector(jeEnv, fsIndex, serCAS.iv_vecIndexedFSs);
+
+    JNIUtils::createByteVector(jeEnv,byteHeapArray, serCAS.iv_vecByteHeapArray);
+    JNIUtils::createShortVector(jeEnv,shortHeapArray, serCAS.iv_vecShortHeapArray);
+    JNIUtils::createLongVector(jeEnv,longHeapArray, serCAS.iv_vecLongHeapArray);
+    uima::internal::CASDeserializer casDeSerializer;
+    casDeSerializer.deserializeData( serCAS, *cas );
+    UIMA_TPRINT("fillCASJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+/*********************************************************************
+ * de initialize engine
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(destroyJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering destroyJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    uima::AnalysisEngine * pEngine =  pInstance->getEngine();
+
+    uima::TyErrorId tyErrorId = pEngine->destroy();
+    if (tyErrorId != UIMA_ERR_NONE) {
+      UIMA_TPRINT("Error during deInitializing engine (code= " << tyErrorId << ")" );
+      JNIUtils::throwNewInternalException(jeEnv, pEngine->getAnnotatorContext().getLogger().getLastError() );
+      return;
+    }
+
+    if (pEngine != NULL) {
+      delete pEngine;
+      pInstance->setEngine(NULL);
+    }
+
+    JNIUtils::setCppInstance(jeEnv, joJTaf, 0);
+
+    uima::CAS * pCAS = pInstance->getCAS();
+    if (pCAS != NULL) {
+      delete pCAS;
+      pInstance->setCAS(NULL);
+    }
+
+    delete pInstance;
+
+    UIMA_TPRINT("exiting destroy()");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+
+
+
+/************************************************************
+ * process the CAS.
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(processJNI) (JNIEnv* jeEnv,
+    jobject joJTaf,
+    jint isTCas,
+    jstring sofaName,
+    jintArray resultSpecTypes,
+    jintArray resultSpecFeatures) {
+  try {
+    //    cout << "processJNI" << endl;
+    UIMA_TPRINT("entering processDocument");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    uima::AnalysisEngine * pEngine = pInstance->getEngine();
+    assert( EXISTS(pEngine) );
+
+    uima::CAS & cas = *pInstance->getCAS();
+    uima::ResultSpecification rs;
+
+    vector<uima::internal::SerializedCAS::TyNum> rsTypes;
+    JNIUtils::createIntVector(jeEnv, resultSpecTypes, rsTypes);
+    vector<uima::internal::SerializedCAS::TyNum> rsFeatures;
+    JNIUtils::createIntVector(jeEnv, resultSpecFeatures, rsFeatures);
+    uima::internal::CASDeserializer::deserializeResultSpecification(rsTypes, rsFeatures, pInstance->getCASImpl().getCASDefinition(), rs);
+
+//      cerr << __FILE__ << __LINE__ << ": ";
+//      rs.print(cerr);
+
+    UIMA_TPRINT("CAS BEFORE process: ");
+#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
+    ///uima::internal::CASImpl const & crCASImpl = uima::internal::CASImpl::promoteCAS( *pInstance->getCAS() );
+    ///crCASImpl.getHeap().print(cerr);
+#endif
+#endif
+    //uima::TyErrorId tyErrorId;
+    uima::CAS* tcas;
+    if (isTCas) {
+      JNIUString usSofaName(jeEnv, sofaName);
+      UIMA_TPRINT("TCAS BEFORE process: " );
+      UIMA_TPRINT(sofaName );
+      uima::SofaID sofaid;
+      uima::UnicodeStringRef ref = usSofaName.toUStrPtrLenPair();
+      icu::UnicodeString usofa = icu::UnicodeString( ref.getBuffer(), ref.length() );
+      sofaid.setSofaId( UnicodeString(usofa) );
+      sofaid.setComponentSofaName(usofa);
+      tcas = cas.getView(cas.getSofa(sofaid));
+      ///tyErrorId = ((uima::AnalysisEngine*) pEngine)->process(*tcas);
+      uima::CASIterator iter  = ((uima::AnalysisEngine*) pEngine)->processAndOutputNewCASes(*tcas);
+    } else {
+      /////tyErrorId = ((uima::AnalysisEngine*) pEngine)->process(cas);
+      UIMA_TPRINT("CAS BEFORE process: " );
+      uima::CASIterator iter = ((uima::AnalysisEngine*) pEngine)->processAndOutputNewCASes(cas);
+    }
+    /****
+    if (tyErrorId != UIMA_ERR_NONE) {
+       UIMA_TPRINT("Error during processDocument() (code= " << tyErrorId << ")" );
+       uima::ErrorInfo const & lastError = pEngine->getAnnotatorContext(). getLogger().getLastError();
+       if ( lastError.getErrorId() == UIMA_ERR_NONE ) {
+          uima::ErrorInfo newError;
+          newError.setErrorId(tyErrorId);
+          JNIUtils::throwNewInternalException(jeEnv, newError);
+       }
+       else {
+          assert(lastError.getErrorId() == tyErrorId);
+          JNIUtils::throwNewInternalException(jeEnv, lastError);
+       }
+       return;
+    } ****/
+
+    UIMA_TPRINT("CAS AFTER process: ");
+#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
+    crCASImpl.getHeap().print(cerr);
+#endif
+#endif
+
+
+    UIMA_TPRINT("exiting processDocument");
+  } catch (uima::Exception & rException) {
+    cout << "processJNI: Exception " << rException.asString() << endl;
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  }
+#ifdef NDEBUG
+//#ifdef TEMP_DISABLED
+  catch (...) {
+    //cout << "processJNI: all other execptions" << endl;
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+#endif
+}
+
+
+/***********************************************************************
+ * delete the current document.
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(resetJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering resetDocument()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+    pInstance->getSerializedCAS().reset();
+
+    uima::TyErrorId tyErrorId = pInstance->getCAS()->reset();
+
+    //TODO: handle CAS multiplier - return new CASs to pool
+    //     end the segementation.
+
+    if (tyErrorId != UIMA_ERR_NONE) {
+      UIMA_TPRINT("Error during resetDocument() (code= " << tyErrorId << ")" );
+      uima::ErrorInfo errInfo(UIMA_MSG_ID_NO_MESSAGE_AVAILABLE,
+                              tyErrorId,
+                              uima::ErrorInfo::unrecoverable);
+      JNIUtils::throwNewInternalException(jeEnv, errInfo);
+      return;
+    }
+    UIMA_TPRINT("exiting resetDocument()");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+/***********************************************************************
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(serializeCASJNI) (JNIEnv* jeEnv, jobject joJTaf, jboolean jbSerializeData) {
+  try {
+    UIMA_TPRINT("entering serializeCASJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::internal::CASSerializer serializer(false);
+
+    // definitions should not be called from here any more (see initializeJNI() )
+    assert( jbSerializeData == JNI_TRUE );
+    serializer.serializeData( pInstance->getCASImpl(), pInstance->getSerializedCAS() );
+
+#ifdef UIMA_ENABLE_SERIALIZATION_TIMING
+    cout << __FILE__ << __LINE__ << ": CPP/JEDII JNI layer - Time for serialization of heap: " << serializer.getHeapTimer().timeString() << endl;
+    cout << __FILE__ << __LINE__ << ": CPP/JEDII JNI layer - Time for serialization of indexed FSs: " << serializer.getIndexTimer().timeString() << endl;
+#endif
+    UIMA_TPRINT("serializeCASJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+/***********************************************************************
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(serializeSegmentJNI) (JNIEnv* jeEnv, jobject joJTaf, jboolean jbSerializeData) {
+  try {
+    UIMA_TPRINT("entering serializeSegmentJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::internal::CASSerializer serializer(false);
+
+    // definitions should not be called from here any more (see initializeJNI() )
+    assert( jbSerializeData == JNI_TRUE );
+    uima::internal::CASImpl & casimpl = uima::internal::CASImpl::promoteCAS( *(pInstance->getSegment()) );
+    UIMA_TPRINT(casimpl.getDocumentText());
+    serializer.serializeData( casimpl, pInstance->getSerializedSegment() );
+
+#ifdef UIMA_ENABLE_SERIALIZATION_TIMING
+    cout << __FILE__ << __LINE__ << ": TAF/JEDII JNI layer - Time for serialization of heap: " << serializer.getHeapTimer().timeString() << endl;
+    cout << __FILE__ << __LINE__ << ": TAF/JEDII JNI layer - Time for serialization of indexed FSs: " << serializer.getIndexTimer().timeString() << endl;
+#endif
+    UIMA_TPRINT("serializeSegmentJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+
+class JavaIntegerObject : public JavaObject {
+private:
+  JavaIntegerObject(JavaIntegerObject const &);
+
+public:
+  JavaIntegerObject(JNIEnv * jeEnv, int iNum)
+      : JavaObject(jeEnv, "java/lang/Integer", "(I)V") {
+    assertWithMsg( (sizeof(jint) == sizeof(int)), "Port required");
+    jvalue args[1];
+    args[0].i = iNum;
+    createJObject(args);
+  }
+};
+
+
+JNIEXPORT jobject JNICALL JAVA_PREFIX(getSerializedDataJNI) (JNIEnv* jeEnv, jobject joJTaf, jint jiWhichData) {
+  jobject joResult = NULL;
+  try {
+    UIMA_TPRINT("getSerializedDataJNI() entered");
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+    uima::internal::SerializedCAS & crSerializedCAS = pInstance->getSerializedCAS();
+
+    {
+      jeEnv->PushLocalFrame( crSerializedCAS.getNumberOfJavaObjectsToBeCreatedData() );
+      CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+      joResult = getSerializedCasData(jeEnv, joJTaf, jiWhichData, crSerializedCAS);
+      jeEnv->PopLocalFrame(NULL);
+      CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    }
+    UIMA_TPRINT("getSerializedDataJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return NULL;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return NULL;
+  }
+  return joResult;
+}
+
+JNIEXPORT jobject JNICALL JAVA_PREFIX(getSerializedSegmentDataJNI) (JNIEnv* jeEnv, jobject joJTaf, jint jiWhichData) {
+  jobject joResult = NULL;
+  try {
+    UIMA_TPRINT("getSerializedSegmentDataJNI() entered");
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+    uima::internal::SerializedCAS & crSerializedCAS = pInstance->getSerializedSegment();
+
+    {
+      jeEnv->PushLocalFrame( crSerializedCAS.getNumberOfJavaObjectsToBeCreatedData() );
+      CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+      joResult = getSerializedCasData(jeEnv, joJTaf, jiWhichData, crSerializedCAS);
+      jeEnv->PopLocalFrame(NULL);
+      CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    }
+    UIMA_TPRINT("getSerializedDataJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return NULL;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return NULL;
+  }
+  UIMA_TPRINT("getSerializedSegmentDataJNI() done");
+  return joResult;
+}
+
+
+jobject getSerializedCasData (JNIEnv* jeEnv, jobject joJTaf, jint jiWhichData, uima::internal::SerializedCAS & crSerializedCAS) {
+  jobject joResult = NULL;
+  try {
+    UIMA_TPRINT("getSerializedDataJNI() entered");
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+    //////uima::internal::SerializedCAS const & crSerializedCAS = pInstance->getSerializedCAS();
+
+    {
+      ///////jeEnv->PushLocalFrame( crSerializedCAS.getNumberOfJavaObjectsToBeCreatedData() );
+      ///////CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+
+      // the C++ objects created for TOPTYPE and DOCUMENT are destroyed after the switch
+      // but the created Java object inside is still alive
+
+      switch (jiWhichData) {
+      case CONST_PREFIX( TYPE_INH ):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getTypeInheritanceTable());
+        break;
+      case CONST_PREFIX(FEATURE_DEF):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getFeatureDefinitionTable());
+        break;
+      case CONST_PREFIX(FEATURE_OFFSET):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getFeatureOffsetTable());
+        break;
+      case CONST_PREFIX(TYPE_SYMBOLS):
+              joResult = JNIUtils::createStringArray(jeEnv, crSerializedCAS.getTypeSymbolTable());
+        break;
+      case CONST_PREFIX(FEATURE_SYMBOLS):
+              joResult = JNIUtils::createStringArray(jeEnv, crSerializedCAS.getFeatureSymbolTable());
+        break;
+      case CONST_PREFIX( TYPE_PRIORITIES):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getTypePriorityTable() );
+        break;
+      case CONST_PREFIX(TOPTYPE): {
+        assert( sizeof(uima::lowlevel::TyFSType) == sizeof(jint) );
+        uima::lowlevel::TyFSType tyTop = pInstance->getCASImpl().getHeap().getTypeSystem().getTopType();
+        assert(pInstance->getCASImpl().getHeap().getTypeSystem().isValidType(tyTop));
+        JavaIntegerObject javaInt(jeEnv, (int) tyTop );
+        joResult = javaInt.getJObject();
+      }
+      break;
+      case CONST_PREFIX(FSHEAP):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getFSHeapArray());
+        break;
+      case CONST_PREFIX(BYTEHEAP):
+              joResult = JNIUtils::createByteArray(jeEnv, crSerializedCAS.getByteHeapArray());
+        break;
+      case CONST_PREFIX(SHORTHEAP):
+              joResult = JNIUtils::createShortArray(jeEnv, crSerializedCAS.getShortHeapArray());
+        break;
+      case CONST_PREFIX(LONGHEAP):
+              joResult = JNIUtils::createLongArray(jeEnv, crSerializedCAS.getLongHeapArray());
+        break;
+      case CONST_PREFIX(STRINGSYMBOL):
+              joResult = JNIUtils::createStringArray(jeEnv, crSerializedCAS.getStringSymbolTable());
+        break;
+      case CONST_PREFIX(DOCUMENT): {
+//               uima::UnicodeStringRef ustrp = pInstance->getCAS()->getDocumentText();
+//            UIMA_TPRINT("Doc text: " << ustrp);
+//               JavaString javaStr(jeEnv, ustrp);
+//               joResult = javaStr.getJObject();
+        break;
+      }
+      case CONST_PREFIX(INDEXEDFSS):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getIndexedFSs());
+        break;
+      case CONST_PREFIX(INDEXID):
+              joResult = JNIUtils::createStringArray(jeEnv, crSerializedCAS.getIndexIDTable() );
+        break;
+      case CONST_PREFIX(INDEXKIND):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getIndexKindTable() );
+        break;
+      case CONST_PREFIX(COMPARATORDEF):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getComparatorDefinitionTable() );
+        break;
+      case CONST_PREFIX(COMPARATORSTART):
+              joResult = JNIUtils::createIntArray(jeEnv, crSerializedCAS.getComparatorStartTable() );
+        break;
+      default:
+        assert(false);
+      }
+      ///////jeEnv->PopLocalFrame(NULL);
+      /////////CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    }
+    UIMA_TPRINT("getSerializedDataJNI() finished");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return NULL;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return NULL;
+  }
+  return joResult;
+}
+
+
+/*********************************************************************
+ * static method to get the error message from an errorId.
+ */
+JNIEXPORT jstring JNICALL JAVA_PREFIX(getErrorMessageJNI) (JNIEnv* jeEnv,
+    jclass,
+    jlong jlErrorId) {
+  try {
+    const char* cpszErrorId = (const char*) uima::AnalysisEngine::getErrorIdAsCString( (long) jlErrorId);
+    jstring jsError = jeEnv->NewStringUTF(cpszErrorId);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    return jsError;
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return NULL;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, NULL);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return NULL;
+  }
+}
+
+/*********************************************************************
+ * batchProcessComplete
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(batchProcessCompleteJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering batchProcessCompleteJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    uima::AnalysisEngine * pEngine =  pInstance->getEngine();
+
+    uima::TyErrorId tyErrorId = pEngine->batchProcessComplete();
+    if (tyErrorId != UIMA_ERR_NONE) {
+      UIMA_TPRINT("Error during deInitializing engine (code= " << tyErrorId << ")" );
+      JNIUtils::throwNewInternalException(jeEnv, pEngine->getAnnotatorContext().getLogger().getLastError() );
+      return;
+    }
+
+    UIMA_TPRINT("exiting batchProcessComplete()");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+/*********************************************************************
+ * collectionProcessComplete
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(collectionProcessCompleteJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering collectionProcessCompleteJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::ResourceManager::getInstance().setupJavaLogging(jeEnv);
+
+    uima::AnalysisEngine * pEngine =  pInstance->getEngine();
+
+    uima::TyErrorId tyErrorId = pEngine->collectionProcessComplete();
+    if (tyErrorId != UIMA_ERR_NONE) {
+      UIMA_TPRINT("Error during deInitializing engine (code= " << tyErrorId << ")" );
+      JNIUtils::throwNewInternalException(jeEnv, pEngine->getAnnotatorContext().getLogger().getLastError() );
+      return;
+    }
+
+    UIMA_TPRINT("exiting collectionProcessComplete()");
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+/*********************************************************************
+ * hasNextSegmentJNI
+ */
+JNIEXPORT jboolean JNICALL JAVA_PREFIX(hasNextSegmentJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering hasNextSegmentJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    jboolean hasNext = pInstance->hasNext();
+
+    UIMA_TPRINT("exiting hasNextSegmentJNI()");
+
+    return hasNext;
+
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return false;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION_WITH_RETURN_VALUE(jeEnv, false);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return false;
+  }
+  return false;
+}
+
+
+/*********************************************************************
+ * nextSegmentJNI
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(nextSegmentJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering nextSegmentJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    //release the previous segment if necessary
+    UIMA_TPRINT("nextSegmentJNI() release previous segment ");
+    pInstance->releaseSegment();
+
+    pInstance->next();
+    ////pInstance->setSegment(pInstance->getCASIterator().next());
+
+    if (pInstance->getSegment() == NULL) {
+      UIMA_TPRINT("Error during engine.next() " );
+      JNIUtils::throwNewInternalException(jeEnv,  pInstance->getEngine()->getAnnotatorContext().getLogger().getLastError() );
+      return;
+    }
+
+    UIMA_TPRINT("exiting nextSegmentJNI()");
+    return;
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+/*********************************************************************
+ * releaseSegmentJNI
+ */
+JNIEXPORT void JNICALL JAVA_PREFIX(releaseSegmentJNI) (JNIEnv* jeEnv, jobject joJTaf) {
+  try {
+    UIMA_TPRINT("entering releaseSegmentJNI()");
+
+    uima::JNIInstance* pInstance = JNIUtils::getCppInstance(jeEnv, joJTaf);
+    assert( EXISTS(pInstance) );
+
+    uima::AnalysisEngine * pEngine =  pInstance->getEngine();
+
+    //release cas.
+    pInstance->releaseSegment();
+
+    UIMA_TPRINT("exiting releaseSegmentJNI()");
+    return;
+  } catch (uima::Exception & rException) {
+    UIMA_TPRINT("Exception: " << rException.asString() );
+    JNIUtils::throwNewInternalException(jeEnv, rException);
+    return;
+  } catch (...) {
+    UIMA_TPRINT("Unknown Exception" );
+    CHECK_FOR_JNI_EXCEPTION(jeEnv);
+    uima::ErrorInfo errInfo(UIMA_MSG_ID_EXC_UNEXPECTED_ERROR, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION, uima::ErrorInfo::unrecoverable);
+    JNIUtils::throwNewInternalException(jeEnv, errInfo);
+    return;
+  }
+}
+
+
+
+
+
+
+

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

Added: incubator/uima/uimacpp/trunk/src/jni/jni_string.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/jni/jni_string.cpp?view=auto&rev=503252
==============================================================================
--- incubator/uima/uimacpp/trunk/src/jni/jni_string.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/jni/jni_string.cpp Sat Feb  3 08:59:25 2007
@@ -0,0 +1,146 @@
+/** @name jni_string.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:
+
+-----------------------------------------------------------------------------
+
+
+   07/26/2000  Initial creation
+
+-------------------------------------------------------------------------- */
+
+/*@{*/                                                /* Doc++ Group */
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/jni_string.hpp"
+#include "uima/ccsid.hpp"
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/*
+ If UIMA_JNI_RELEASE_STRING_BUG is defined, the ReleaseString JNI calls
+ are done even if the GetString call did not copy the string.
+
+ See also
+ http://www-106.ibm.com/developerworks/java/library/j-jtctips/j-jtc0117d.html
+ */
+#define UIMA_JNI_RELEASE_STRING_BUG
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+//CosClCCSID::CosEnCCSID JNIUString::iv_enSystemCCSID = CosClCCSID::getSystemCCSID();
+
+JNIStringABase::JNIStringABase(JNIEnv* jeEnv, jstring jsString) :
+    iv_jeEnv(jeEnv),
+    iv_jbCopied(false),
+//    iv_cpjcData(NULL),
+    iv_ulLength(0),
+    iv_jsString(jsString) {
+  assert( EXISTS(jeEnv) );
+}
+
+
+JNIUString::JNIUString(JNIEnv* jeEnv, jstring jsString) :
+    JNIStringABase(jeEnv, jsString),
+    iv_cpjcData(NULL) {
+  iv_cpjcData = iv_jeEnv->GetStringChars(iv_jsString, &iv_jbCopied);
+  assert( iv_cpjcData != NULL );
+  iv_ulLength = iv_jeEnv->GetStringLength(iv_jsString);
+}
+
+JNIUString::~JNIUString() {
+#ifndef UIMA_JNI_RELEASE_STRING_BUG
+  if (iv_jbCopied == JNI_TRUE) {
+#endif
+    iv_jeEnv->ReleaseStringChars(iv_jsString, iv_cpjcData);
+#ifndef UIMA_JNI_RELEASE_STRING_BUG
+  }
+#endif
+}
+
+void JNIUString::convertToSystemCodePage(string& rsResult) {
+  // Convert to default encoding for platform
+  assertWithMsg(sizeof(UChar) == sizeof(jchar), "Port required");
+  uima::UnicodeStringRef usr((const UChar*)getData(), getLength());
+  usr.extract(rsResult);
+}
+
+
+//////////////////////////////////////////////////////////////
+
+JavaObject::JavaObject(JNIEnv* jeEnv)
+    : iv_jeEnv(jeEnv),
+    iv_jclass(NULL),
+    iv_jmidConstructor(NULL),
+    iv_jObject(NULL) {
+  assert( EXISTS(jeEnv) );
+}
+
+JavaObject::JavaObject(JNIEnv* jeEnv, char const * cpszClass, char const * cpszConstructorSignature)
+    : iv_jeEnv(jeEnv),
+    iv_jclass(NULL),
+    iv_jmidConstructor(NULL),
+    iv_jObject(NULL) {
+  assert( EXISTS(iv_jeEnv) );
+  iv_jclass = iv_jeEnv->FindClass(cpszClass);
+  ASSERT_NO_JNI_EXCEPTION(iv_jeEnv);
+  iv_jmidConstructor = iv_jeEnv->GetMethodID(iv_jclass, "<init>", cpszConstructorSignature);
+  ASSERT_NO_JNI_EXCEPTION(iv_jeEnv);
+}
+
+
+JavaString::JavaString(JNIEnv* jeEnv, uima::UnicodeStringRef const & rulString)
+    : JavaObject(jeEnv) {
+  assertWithMsg(sizeof(jchar) == sizeof(UChar), "Port required");
+  jchar const * cpjcData = (jchar const *) rulString.getBuffer();
+  iv_jObject = NULL;
+  if ( cpjcData != NULL ) {
+    assert( cpjcData != NULL );
+    jsize jsLength = (jsize) rulString.length();
+    iv_jObject = iv_jeEnv->NewString(cpjcData, jsLength);
+    ASSERT_NO_JNI_EXCEPTION(iv_jeEnv);
+  }
+}
+
+
+/* ----------------------------------------------------------------------- */
+/*@}*/                                                /* e-o-Doc++ Group */
+
+
+
+

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

Added: incubator/uima/uimacpp/trunk/src/jni/jni_utils.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/jni/jni_utils.cpp?view=auto&rev=503252
==============================================================================
--- incubator/uima/uimacpp/trunk/src/jni/jni_utils.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/jni/jni_utils.cpp Sat Feb  3 08:59:25 2007
@@ -0,0 +1,389 @@
+/** @name jni_utils.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:
+
+-----------------------------------------------------------------------------
+
+
+   07/26/2000  Initial creation
+
+-------------------------------------------------------------------------- */
+
+/*@{*/                                                /* Doc++ Group */
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+#include "uima/jni_utils.hpp"
+#include "uima/macros.h"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+#define JAVA_CLASS_INTERNALTAFEXCEPTION "org/apache/uima/uimacpp/InternalTafException"
+#define JUIMA_FIELD_CPPENGINEPOINTER "cppEnginePointer"
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+jfieldID JNIUtils::getFieldID(JNIEnv* jeEnv, jobject jo, char const * sig, char const * cpszFieldID) {
+  jclass clazz = jeEnv->GetObjectClass(jo);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  jfieldID jFID = jeEnv->GetFieldID(clazz, cpszFieldID, sig);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  return jFID;
+}
+
+
+long JNIUtils::getLongField(JNIEnv* jeEnv, jobject jo, char const * cpszFieldName) {
+  assertWithMsg(sizeof(long) == sizeof(jlong), "Port required");
+  jlong jValue = jeEnv->GetLongField(jo, getFieldID(jeEnv, jo, "J", cpszFieldName) );
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  return (long) jValue;
+}
+
+void JNIUtils::setLongField(JNIEnv* jeEnv, jobject jo, char const * cpszFieldName, long l) {
+  assertWithMsg(sizeof(long) == sizeof(jlong), "Port required");
+  jeEnv->SetLongField(jo, getFieldID(jeEnv, jo, "J", cpszFieldName), (jlong) l);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+}
+
+/*
+void JNIUtils::throwNewInternalException(JNIEnv* jeEnv,
+                                            icu::UnicodeString errorMessage) {
+   throwNewInternalException(jeEnv, errorMessage, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION);
+}
+*/
+
+void JNIUtils::throwNewInternalException(JNIEnv* jeEnv,
+    icu::UnicodeString errorMessage,
+    uima::TyErrorId errorId) {
+  jclass clazz = jeEnv->FindClass(JAVA_CLASS_INTERNALTAFEXCEPTION);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  // get the constructor which takes a message and an errorID
+  jmethodID jmExcConstructor = jeEnv->GetMethodID(clazz, "<init>", "(Ljava/lang/String;J)V");
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  assertWithMsg( sizeof(jchar) == sizeof(UChar), "Port required");
+  assertWithMsg( sizeof(uima::TyErrorId) <= sizeof(jlong), "Port required");
+  jstring jsErrorMessage = jeEnv->NewString( (const jchar*) errorMessage.getBuffer(), errorMessage.length());
+  jthrowable jtIkfInternalException = (jthrowable) jeEnv->NewObject(clazz, jmExcConstructor, jsErrorMessage, (jlong) errorId);
+  jeEnv->Throw(jtIkfInternalException);
+}
+
+
+void JNIUtils::throwNewInternalException(JNIEnv* jeEnv, uima::Exception & rException) {
+  string sExc = rException.asString();
+  icu::UnicodeString usExc(sExc.c_str(), sExc.length());
+  throwNewInternalException(jeEnv, usExc, rException.getErrorInfo().getErrorId());
+}
+
+void JNIUtils::throwNewInternalException(JNIEnv* jeEnv, uima::ErrorInfo const & errInfo) {
+  string sExc = errInfo.asString();
+  icu::UnicodeString usExc(sExc.c_str(), sExc.length());
+  throwNewInternalException(jeEnv, usExc, errInfo.getErrorId());
+}
+
+
+void JNIUtils::setCppInstance(JNIEnv* jeEnv,
+                              jobject joJTaf,
+                              uima::JNIInstance* pInstance) {
+  jclass clazz = jeEnv->GetObjectClass(joJTaf);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  // get the field of clazz named "cppEnginePointer" which is a long
+  jfieldID fid = jeEnv->GetFieldID(clazz, JUIMA_FIELD_CPPENGINEPOINTER, "J");
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  assertWithMsg( sizeof(void*) <= sizeof(jlong), "Port required");
+  jeEnv->SetLongField(joJTaf, fid, (jlong) pInstance);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+}
+
+uima::JNIInstance* JNIUtils::getCppInstance(JNIEnv* jeEnv,
+                                      jobject joJTaf) {
+  jclass clazz = jeEnv->GetObjectClass(joJTaf);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  jfieldID fid = jeEnv->GetFieldID(clazz, JUIMA_FIELD_CPPENGINEPOINTER, "J");
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  jlong jlPointer = jeEnv->GetLongField(joJTaf, fid);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  assertWithMsg( sizeof(void*) <= sizeof(jlong), "Port required");
+  return(uima::JNIInstance*) jlPointer;
+}
+
+
+jobjectArray JNIUtils::createStringArray(JNIEnv* jeEnv, vector<uima::UnicodeStringRef> const & crVec) {
+  jobjectArray joArr = NULL;
+  size_t uiLen = crVec.size();
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  jclass jcStringClass = jeEnv->FindClass("java/lang/String");
+  assert( jcStringClass != NULL );
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  joArr = jeEnv->NewObjectArray( uiLen, jcStringClass, NULL );
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    UIMA_TPRINT("Copying string " << i);
+    JavaString str(jeEnv, crVec[i]);
+    UIMA_TPRINT("Entering string " << i << " into array");
+    jeEnv->SetObjectArrayElement(joArr, (jsize) i, str.getJObject());
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+  }
+  return joArr;
+}
+
+jintArray JNIUtils::createIntArray(JNIEnv* jeEnv, vector<uima::internal::SerializedCAS::TyNum> const & crVec) {
+  jintArray jiArr = NULL;
+  assert( sizeof(uima::internal::SerializedCAS::TyNum) == sizeof(jint) );
+
+  size_t uiLength = crVec.size();
+//   assert( uiLength > 0);
+  jiArr = jeEnv->NewIntArray(uiLength);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+
+#ifdef TEMP_DISABLED
+  // call to SetIntArrayRegion() assumes that vector iterators
+  //   are implemented as pointers
+  // check at least that they have equal size by the following assert
+  assertWithMsg( sizeof(vector<uima::internal::CASSerializer::TyNum>::iterator) == sizeof(void*), "Port required!");
+  jeEnv->SetIntArrayRegion(jiArr, 0, uiLength, (jint*) crVec.begin());
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+#endif
+
+  if (uiLength > 0) {
+    // since the above code does not work for msc7,
+    // allocate a new array and copy it by hand
+    jint * pJIntArray = new jint[uiLength];
+    size_t i=0;
+    vector<uima::internal::SerializedCAS::TyNum>::const_iterator cit;
+    for (cit = crVec.begin(); cit != crVec.end(); ++cit) {
+      pJIntArray[i++] = (jint) *cit;
+    }
+    assert( i == uiLength );
+
+    jeEnv->SetIntArrayRegion(jiArr, 0, uiLength, pJIntArray);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    delete pJIntArray;
+  }
+
+  return jiArr;
+}
+
+
+void JNIUtils::createIntVector(JNIEnv* jeEnv, jintArray array, vector<uima::internal::SerializedCAS::TyNum> & rResult) {
+  size_t uiLen = jeEnv->GetArrayLength(array);
+  rResult.resize(uiLen);
+  jboolean jbCopy;
+  jint * pArray = jeEnv->GetIntArrayElements(array, & jbCopy);
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    rResult[i] = pArray[i];
+  }
+  // ReleaseIntArrayElements need not be called since nothing is modified
+}
+
+
+void JNIUtils::createStringVector(JNIEnv* jeEnv, jobjectArray joArray, vector<uima::UnicodeStringRef> & rResult, vector<icu::UnicodeString> & rStringPool) {
+  size_t uiLen = jeEnv->GetArrayLength(joArray);
+  rResult.resize(uiLen);
+  rStringPool.resize(uiLen);
+//   cout << __FILE__ << __LINE__ << ": len: " << uiLen << endl;
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    jobject jo = jeEnv->GetObjectArrayElement(joArray, i);
+
+    if (jo != 0) {
+      jstring js = (jstring) jo;
+      JNIUString uString(jeEnv, js);
+      uima::UnicodeStringRef ref = uString.toUStrPtrLenPair();
+//         cout << __FILE__ << __LINE__ << ":" << i << "  string " << uString.toUStrPtrLenPair() << endl;
+      rStringPool[i] = UnicodeString( ref.getBuffer(), ref.length() );
+      rResult[i] = uima::UnicodeStringRef(rStringPool[i]);
+    } else {
+      rResult[i] = uima::UnicodeStringRef();
+    }
+  }
+}
+
+jbyteArray JNIUtils::createByteArray(JNIEnv* jeEnv, vector<char> const & crVec) {
+  jbyteArray jiArr = NULL;
+
+  size_t uiLength = crVec.size();
+//   assert( uiLength > 0);
+  jiArr = jeEnv->NewByteArray(uiLength);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+
+#ifdef TEMP_DISABLED
+  // call to SetIntArrayRegion() assumes that vector iterators
+  //   are implemented as pointers
+  // check at least that they have equal size by the following assert
+  //assertWithMsg( sizeof(vector<uima::internal::CASSerializer::TyNum>::iterator) == sizeof(void*), "Port required!");
+  jeEnv->SetByteArrayRegion(jiArr, 0, uiLength, (jbyte*) crVec.begin());
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+#endif
+
+  if (uiLength > 0) {
+    // since the above code does not work for msc7,
+    // allocate a new array and copy it by hand
+    jbyte * pJByteArray = new jbyte[uiLength];
+    size_t i=0;
+    vector<char>::const_iterator cit;
+    for (cit = crVec.begin(); cit != crVec.end(); ++cit) {
+      pJByteArray[i++] = (jbyte) *cit;
+    }
+    assert( i == uiLength );
+
+    jeEnv->SetByteArrayRegion(jiArr, 0, uiLength, pJByteArray);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    delete pJByteArray;
+  }
+
+  return jiArr;
+}
+
+jshortArray JNIUtils::createShortArray(JNIEnv* jeEnv, vector<short> const & crVec) {
+  jshortArray jiArr = NULL;
+
+  size_t uiLength = crVec.size();
+//   assert( uiLength > 0);
+  jiArr = jeEnv->NewShortArray(uiLength);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+
+#ifdef TEMP_DISABLED
+  // call to SetIntArrayRegion() assumes that vector iterators
+  //   are implemented as pointers
+  // check at least that they have equal size by the following assert
+  //assertWithMsg( sizeof(vector<uima::internal::CASSerializer::TyNum>::iterator) == sizeof(void*), "Port required!");
+  jeEnv->SetShortArrayRegion(jiArr, 0, uiLength, (jshort*) crVec.begin());
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+#endif
+
+  if (uiLength > 0) {
+    // since the above code does not work for msc7,
+    // allocate a new array and copy it by hand
+    jshort * pJShortArray = new jshort[uiLength];
+    size_t i=0;
+    vector<short>::const_iterator cit;
+    for (cit = crVec.begin(); cit != crVec.end(); ++cit) {
+      pJShortArray[i++] = (jshort) *cit;
+    }
+    assert( i == uiLength );
+
+    jeEnv->SetShortArrayRegion(jiArr, 0, uiLength, pJShortArray);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    delete pJShortArray;
+  }
+
+  return jiArr;
+}
+
+
+jlongArray JNIUtils::createLongArray(JNIEnv* jeEnv, vector<INT64> const & crVec) {
+  jlongArray jiArr = NULL;
+
+  size_t uiLength = crVec.size();
+//   assert( uiLength > 0);
+  jiArr = jeEnv->NewLongArray(uiLength);
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+
+#ifdef TEMP_DISABLED
+  // call to SetIntArrayRegion() assumes that vector iterators
+  //   are implemented as pointers
+  // check at least that they have equal size by the following assert
+  //assertWithMsg( sizeof(vector<uima::internal::CASSerializer::TyNum>::iterator) == sizeof(void*), "Port required!");
+  jeEnv->SetLongArrayRegion(jiArr, 0, uiLength, (jlong*) crVec.begin());
+  ASSERT_NO_JNI_EXCEPTION(jeEnv);
+#endif
+
+  if (uiLength > 0) {
+    // since the above code does not work for msc7,
+    // allocate a new array and copy it by hand
+    jlong * pJLongArray = new jlong[uiLength];
+    size_t i=0;
+    vector<INT64>::const_iterator cit;
+    for (cit = crVec.begin(); cit != crVec.end(); ++cit) {
+      pJLongArray[i++] = (jlong) *cit;
+    }
+    assert( i == uiLength );
+
+    jeEnv->SetLongArrayRegion(jiArr, 0, uiLength, pJLongArray);
+    ASSERT_NO_JNI_EXCEPTION(jeEnv);
+    delete pJLongArray;
+  }
+
+  return jiArr;
+}
+
+void JNIUtils::createByteVector(JNIEnv* jeEnv, jbyteArray array, vector<char> & rResult) {
+  size_t uiLen = jeEnv->GetArrayLength(array);
+  rResult.resize(uiLen);
+  jboolean jbCopy;
+  jbyte * pArray = jeEnv->GetByteArrayElements(array, & jbCopy);
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    rResult[i] = pArray[i];
+  }
+  // ReleaseIntArrayElements need not be called since nothing is modified
+}
+
+void JNIUtils::createShortVector(JNIEnv* jeEnv, jshortArray array, vector<short> & rResult) {
+  size_t uiLen = jeEnv->GetArrayLength(array);
+  rResult.resize(uiLen);
+  jboolean jbCopy;
+  jshort * pArray = jeEnv->GetShortArrayElements(array, & jbCopy);
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    rResult[i] = pArray[i];
+  }
+  // ReleaseIntArrayElements need not be called since nothing is modified
+}
+
+void JNIUtils::createLongVector(JNIEnv* jeEnv, jlongArray array, vector<INT64> & rResult) {
+  size_t uiLen = jeEnv->GetArrayLength(array);
+  rResult.resize(uiLen);
+  jboolean jbCopy;
+  jlong * pArray = jeEnv->GetLongArrayElements(array, & jbCopy);
+  size_t i;
+  for (i=0; i<uiLen; ++i) {
+    rResult[i] = pArray[i];
+  }
+  // ReleaseIntArrayElements need not be called since nothing is modified
+}
+
+
+
+/* ----------------------------------------------------------------------- */
+/*@}*/                                                /* e-o-Doc++ Group */
+
+/* <EOF> */
+

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