protected BaseCASObject createBaseCASObjectFromFile()

in CasViewerEclipsePlugin/uimaj-ep-casviewer/src/main/java/org/apache/uima/casviewer/viewer/internal/GenericCasViewer.java [597:692]


    protected BaseCASObject createBaseCASObjectFromFile (String xcasOrxmiFileName)
    {
        BaseCASObject   casObject = null;
        String          typesystemFileName = null;

        // Create Visual CAS
        if (xcasOrxmiFileName != null && xcasOrxmiFileName.trim().length()>0 ) {
            
            String s = xcasOrxmiFileName.replace('\\', '/');
            int lastIndex = s.lastIndexOf('/');

            // Look for TypePriorities xml file
            String typePrioritiesFileName = null;
            if ( lastIndex != -1) {
                typePrioritiesFileName = s.substring(0, lastIndex+1) + DEFAULT_TYPE_PRIORITIES_FOR_XCAS;
            }
            if ( ! (new File(typePrioritiesFileName)).exists() ) {
                // No Type Priorities file
                // Trace.err("NO priority file: " + typePrioritiesFileName);
                typePrioritiesFileName = null;
            }
            
            // Which file format (XMI or XCAS) ?
            if (xcasOrxmiFileName.endsWith("xmi") || xcasOrxmiFileName.endsWith("xcas")) {
                // Look for Type System used with this Xcas
                // Prefix with the path from Xcas instance file. Make the file absolute
                String path = ".";
                if ( lastIndex != -1) {
                    path = s.substring(0, lastIndex);
                }
                File directory = new File(path);
                if ( directory.isDirectory() ) {
                    typesystemFileName = findTypesystemmFileInDirectory(directory, DEFAULT_TYPE_SYSTEM_FOR_XCAS);
                }

                if ( typesystemFileName == null ) {
                    typesystemFileName = findTypesystemmFileInNLPProject();
                    if ( typesystemFileName != null ) {
                        Trace.err("Get TS file from NLP project: " + typesystemFileName);
                    }
                }
                if ( typesystemFileName == null ) {
                    // No Type System file
                    int returnCode = PopupMessage.popOkCancel("No Type System", 
                          "Cannot find type system file (" + DEFAULT_TYPE_SYSTEM_FOR_XCAS 
                          + ") to be used with the selected XmiCas file.\n\n"
                          + "Do you wish to select the type system Xml descriptor ?", 
                            MessageDialog.QUESTION);
                    if ( returnCode != Window.CANCEL ) {
                        typesystemFileName =  selectTypesystemFile();
                    } else {
                        return null;
                    }
                    if (typesystemFileName == null) {
                        return null;
                    }
                }
                
                // Create TypeSystemDescription from UIMA descriptor
                TypeSystemDescription typeSystemDescription = null;
                try {
                    typeSystemDescription = createTypeSystemDescription(typesystemFileName, 
                                    createResourceManagerFromFileName(typesystemFileName));
                } catch (InvalidXMLException e1) {
                    e1.printStackTrace();
                } catch (ResourceInitializationException e1) {
                    e1.printStackTrace();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }        
                if (typeSystemDescription == null) {
                    return null;
                }
                
                try {
//                    List<String> excludedTypeNames = new ArrayList<String>();
//                    excludedTypeNames.add("com.ibm.hutt.GPE");
//                    casObject = XcasOrXmiUtil.createBaseCASObjectFromFile(typesystemFileName, 
//                                        xcasOrxmiFileName, typePrioritiesFileName);
//                                        excludedTypeNames);
                    casObject = XcasOrXmiUtil.createBaseCASObjectFromFile(new File(xcasOrxmiFileName), 
                            typeSystemDescription);
                    casObject.setXmiFileLocation(xcasOrxmiFileName);
                } catch (ResourceInitializationException e) {
                    ReportError.openExceptionError(e);
                } catch (IOException e) {
                    ReportError.openExceptionError(e);
                } catch (SAXException e) {
                    ReportError.openExceptionError(e);
                }
            } else {
                Trace.bug("Cannot open this unknown file: " + xcasOrxmiFileName);                
            }
        }        
        return casObject;
    } // createCASObjectFromFile