public void entityProcessComplete()

in SimpleUimaAsService/src/main/java/org/apache/uima/simpleserver/as/UimaAsSerive.java [238:303]


      public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
        System.out.println("Received Completed Analysis");
        if (aStatus != null && aStatus.isException()) {
          List exceptions = aStatus.getExceptions();
          for (int i = 0; i < exceptions.size(); i++) {
            ((Throwable) exceptions.get(i)).printStackTrace();
          }
          if (!ignoreErrors) {
            System.err.println("Terminating Client...");
            // uimaEEEngine.stop();  TODO: Does not seem to work
            // return;
            System.exit(1);
          }
        }
        
        //if output dir specified, dump CAS to XMI
        if (outputDir != null) {
          // try to retreive the filename of the input file from the CAS
          File outFile = null;
          Type srcDocInfoType = aCas.getTypeSystem().getType("org.apache.uima.examples.SourceDocumentInformation");
          if (srcDocInfoType != null) {
            FSIterator it = aCas.getIndexRepository().getAllIndexedFS(srcDocInfoType);
            if (it.hasNext()) {
              FeatureStructure srcDocInfoFs = it.get();
              Feature uriFeat = srcDocInfoType.getFeatureByBaseName("uri");
              Feature offsetInSourceFeat = srcDocInfoType.getFeatureByBaseName("offsetInSource");
              String uri = srcDocInfoFs.getStringValue(uriFeat);
              int offsetInSource = srcDocInfoFs.getIntValue(offsetInSourceFeat);
              File inFile;
              try {
                inFile = new File(new URL(uri).getPath());
                String outFileName = inFile.getName();
                if (offsetInSource > 0) {
                  outFileName += ("_" + offsetInSource);
                }
                outFileName += ".xmi";
                outFile = new File(outputDir, outFileName);
              } catch (MalformedURLException e1) {
              // invalid URI, use default processing below
              }
            }
          }
          if (outFile == null) {
            outFile = new File(outputDir, "doc" + entityCount);
          }
          try {
            FileOutputStream outStream = new FileOutputStream(outFile);
            try {
              XmiCasSerializer.serialize(aCas, outStream);
            }
            finally {
              outStream.close();
            }
          } catch (Exception e) {
            System.err.println("Could not save CAS to XMI file");
            e.printStackTrace();
          }
        }
        
        //update stats
        entityCount++;
        String docText = aCas.getDocumentText();
        if (docText != null) {
          size += docText.length();
        }      
      }