Search in sources :

Example 16 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project narayana by jbosstm.

the class NBFSchemaParser method parse.

public boolean parse(String fname) {
    boolean rc = false;
    try {
        flds.clear();
        XSOMParser parser = new XSOMParser();
        parser.parse(fname);
        XSSchemaSet xsSchema = parser.getResult();
        XSSchema schema = xsSchema.getSchema(1);
        File file = new File(fname);
        XSElementDecl element = schema.getElementDecl(file.getName().replace(".xsd", ""));
        if (element != null) {
            log.debug("element is " + element.getName());
            bufferName = element.getName();
            XSType xtype = element.getType();
            if (xtype.isComplexType()) {
                findElementType(xtype.asComplexType());
                rc = true;
            }
        }
    } catch (Exception e) {
        log.error("parse " + fname + " failed with " + e.getMessage(), e);
    }
    return rc;
}
Also used : XSType(com.sun.xml.xsom.XSType) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) XSElementDecl(com.sun.xml.xsom.XSElementDecl) File(java.io.File) XSSchema(com.sun.xml.xsom.XSSchema)

Example 17 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project BIMserver by opensourceBIM.

the class XSDSchemaReader method start.

@SuppressWarnings("deprecation")
private void start() {
    ePackage = ecoreFactory.createEPackage();
    ePackage.setName("ifc2x3");
    ePackage.setNsPrefix("iai");
    ePackage.setNsURI("http:///buildingsmart.ifc.ecore");
    XSOMParser parser = new XSOMParser();
    try {
        parser.parse(getClass().getResource("IFC2X3.xsd"));
        XSSchemaSet schemas = parser.getResult();
        for (XSSchema schema : schemas.getSchemas()) {
            if (schema.getTargetNamespace().equals("http://www.iai-tech.org/ifcXML/IFC2x3/FINAL")) {
                for (XSComplexType type : schema.getComplexTypes().values()) {
                    createComplexType(type);
                }
                for (XSSimpleType simpleType : schema.getSimpleTypes().values()) {
                    createSimpleType(simpleType);
                }
            }
        }
        for (XSSchema schema : schemas.getSchemas()) {
            if (schema.getTargetNamespace().equals("http://www.iai-tech.org/ifcXML/IFC2x3/FINAL")) {
                for (XSComplexType type : schema.getComplexTypes().values()) {
                    fillComplexType(type);
                }
                for (XSModelGroupDecl modelGroupDecl : schema.getModelGroupDecls().values()) {
                    createGroup(modelGroupDecl);
                }
            }
        }
        writeEMF("test.ecore");
    } catch (SAXException e) {
        e.printStackTrace();
    }
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSComplexType(com.sun.xml.xsom.XSComplexType) XSModelGroupDecl(com.sun.xml.xsom.XSModelGroupDecl) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) XSSchema(com.sun.xml.xsom.XSSchema) SAXException(org.xml.sax.SAXException)

Example 18 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project esb0 by karalus.

the class XSDArtifact method getXSSchemaSet.

@Override
public XSSchemaSet getXSSchemaSet() throws SAXException {
    if (_schemaSet == null) {
        XSOMParser xsomParser = new XSOMParser(XMLProcessorFactory.getSAXParserFactory());
        xsomParser.setEntityResolver(getResolver());
        InputSource is = new InputSource(getContentAsStream());
        is.setSystemId(getURI());
        xsomParser.parse(is);
        _schemaSet = xsomParser.getResult();
    }
    return _schemaSet;
}
Also used : InputSource(org.xml.sax.InputSource) XSOMParser(com.sun.xml.xsom.parser.XSOMParser)

Example 19 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project esb0 by karalus.

the class JsonSchemaGenerator method createJsonSchemaGenerator.

public static JsonSchemaGenerator createJsonSchemaGenerator(String systemId, String namespace) throws SAXException {
    XSOMParser xsomParser = new XSOMParser(XMLProcessorFactory.getSAXParserFactory());
    xsomParser.parse(systemId);
    // System.out.println("Number of parsed docs: " + xsomParser.getDocuments().size());
    Map<String, String> prefixMap = new HashMap<String, String>();
    prefixMap.put("", namespace);
    return new JsonSchemaGenerator(xsomParser.getResult(), prefixMap);
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) HashMap(java.util.HashMap)

Example 20 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project atlasmap by atlasmap.

the class Dumper method main.

public static void main(String[] args) throws Exception {
    XSOMParser reader = new XSOMParser();
    // set an error handler so that you can receive error messages
    reader.setErrorHandler(new ErrorReporter(System.out));
    // DomAnnotationParserFactory is a convenient default to use
    reader.setAnnotationParser(new DomAnnotationParserFactory());
    try {
        // the parse method can by called many times
        for (int i = 0; i < args.length; i++) reader.parse(new File(args[i]));
        XSSchemaSet xss = reader.getResult();
        if (xss == null)
            System.out.println("error");
        else
            new SchemaWriter(new OutputStreamWriter(System.out)).visit(xss);
        dump(reader.getDocuments());
    } catch (SAXException e) {
        if (e.getException() != null)
            e.getException().printStackTrace();
        else
            e.printStackTrace();
        throw e;
    }
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) SchemaWriter(com.sun.xml.xsom.impl.util.SchemaWriter) SAXException(org.xml.sax.SAXException)

Aggregations

XSOMParser (com.sun.xml.xsom.parser.XSOMParser)38 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)15 SAXException (org.xml.sax.SAXException)14 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)10 File (java.io.File)9 InputSource (org.xml.sax.InputSource)7 IOException (java.io.IOException)5 XSSchema (com.sun.xml.xsom.XSSchema)4 OutputStreamWriter (java.io.OutputStreamWriter)4 URL (java.net.URL)4 SAXParserFactory (javax.xml.parsers.SAXParserFactory)4 Transformer (javax.xml.transform.Transformer)4 Document (org.w3c.dom.Document)4 SchemaTreeTraverser (com.sun.xml.xsom.impl.util.SchemaTreeTraverser)3 SchemaWriter (com.sun.xml.xsom.impl.util.SchemaWriter)3 ComponentNameFunction (com.sun.xml.xsom.util.ComponentNameFunction)3 TreeModel (javax.swing.tree.TreeModel)3 DOMSource (javax.xml.transform.dom.DOMSource)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Value (jolie.runtime.Value)3