public CEVDocument()

in uimaj-ep-cev/src/main/java/org/apache/uima/cev/data/CEVDocument.java [58:114]


  public CEVDocument(IFile descriptorFile, IFile casFile) throws IllegalArgumentException,
          IOException, InvalidXMLException, SAXException, ResourceInitializationException {

    casData = new ArrayList<CEVData>();

    descriptor = UIMAFramework.getXMLParser().parse(
            new XMLInputSource(descriptorFile.getLocation().toFile()));

    mainCAS = null;

    if (descriptor instanceof AnalysisEngineDescription) {
      mainCAS = CasCreationUtils.createCas((AnalysisEngineDescription) descriptor);
    } else if (descriptor instanceof TypeSystemDescription) {
      TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
      ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
      IProject project = descriptorFile.getProject();
      IFolder folder = project.getFolder("descriptor");
      resMgr.setDataPath(folder.getLocation().toPortableString());
      tsDesc.resolveImports(resMgr);
      mainCAS = CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]);
    } else {
      throw new IllegalArgumentException("Invalid Type System Descriptor");
    }

    FileInputStream inputStream = null;
    try {
      inputStream = new FileInputStream(casFile.getLocation().toFile());
      XmiCasDeserializer.deserialize(inputStream, mainCAS, true);
    } finally {
      if (inputStream != null)
        inputStream.close();
    }

    try {
      String desc = descriptorFile.getFullPath().removeFileExtension().lastSegment();
      if (desc.toLowerCase().endsWith("typesystem")) {
        desc = desc.substring(0, desc.length() - 10);
      }
      String styleMap = desc.toLowerCase() + "stylemap.xml";

      for (IResource r : descriptorFile.getParent().members())
        if (r.getType() == IResource.FILE && r.getFullPath().lastSegment().startsWith(desc)
                && r.getFullPath().lastSegment().toLowerCase().equals(styleMap)) {

          style = StyleMapReader.parseStyleMapDOM(r.getLocation().toOSString());
          break;
        }

    } catch (CoreException e) {
      CEVPlugin.error(e);
    }

    Iterator viewIter = mainCAS.getViewIterator();

    while (viewIter.hasNext())
      casData.add(new CEVData((CAS) viewIter.next(), getStyleMap()));
  }