Search in sources :

Example 1 with XSOMParser

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

the class DomToSchemaProcessor method parseSchema.

private XSSchemaSet parseSchema(Element schema) throws SchemaException {
    // Make sure that the schema parser sees all the namespace declarations
    DOMUtil.fixNamespaceDeclarations(schema);
    XSSchemaSet xss = null;
    try {
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(schema);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(out);
        trans.transform(source, result);
        XSOMParser parser = createSchemaParser();
        InputSource inSource = new InputSource(new ByteArrayInputStream(out.toByteArray()));
        // XXX: hack: it's here to make entity resolver work...
        inSource.setSystemId("SystemId");
        // XXX: end hack
        inSource.setEncoding("utf-8");
        parser.parse(inSource);
        xss = parser.getResult();
    } catch (SAXException e) {
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + "(embedded exception " + e.getException() + ") in " + shortDescription, e);
    } catch (TransformerException e) {
        throw new SchemaException("XML transformer error during XSD schema parsing: " + e.getMessage() + "(locator: " + e.getLocator() + ", embedded exception:" + e.getException() + ") in " + shortDescription, e);
    } catch (RuntimeException e) {
        // This sometimes happens, e.g. NPEs in Saxon
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unexpected error {} during parsing of schema:\n{}", e.getMessage(), DOMUtil.serializeDOMToString(schema));
        }
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + " in " + shortDescription, e);
    }
    return xss;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) TransformerException(javax.xml.transform.TransformerException)

Example 2 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 3 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 4 with XSOMParser

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

the class AtlasXmlSchemaSetParser method createXSOMParser.

private XSOMParser createXSOMParser() {
    XSOMParser parser = new XSOMParser(this.saxParserFactory);
    parser.setEntityResolver(new XSOMClasspathEntityResolver(this.classLoader));
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setErrorHandler(new XSOMErrorHandler());
    return parser;
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 5 with XSOMParser

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

the class AtlasXmlSchemaSetParser method parse.

/**
 * Parse single XML Schema or SchemaSet which contains multiple XML Schema and
 * build a XSOM {@link XSSchemaSet}.
 * @param doc DOM {@link Document} instance of XML Schema
 * @return parsed {@link XSSchemaSet}
 * @throws AtlasException If it fails to parse
 */
public XSSchemaSet parse(Document doc) throws AtlasException {
    XSOMParser xsomParser = createXSOMParser();
    parseInternal(doc, n -> {
        try {
            xsomParser.parse(toInputStream(n));
        } catch (Exception e) {
            throw new AtlasException(e);
        }
    });
    try {
        return xsomParser.getResult();
    } catch (Exception e) {
        throw new AtlasException(e);
    }
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) AtlasException(io.atlasmap.api.AtlasException) AtlasException(io.atlasmap.api.AtlasException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Aggregations

XSOMParser (com.sun.xml.xsom.parser.XSOMParser)12 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)5 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)5 SAXException (org.xml.sax.SAXException)5 File (java.io.File)3 XSSchema (com.sun.xml.xsom.XSSchema)2 Transformer (javax.xml.transform.Transformer)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 XSComplexType (com.sun.xml.xsom.XSComplexType)1 XSElementDecl (com.sun.xml.xsom.XSElementDecl)1 XSModelGroupDecl (com.sun.xml.xsom.XSModelGroupDecl)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 XSType (com.sun.xml.xsom.XSType)1 SchemaTreeTraverser (com.sun.xml.xsom.impl.util.SchemaTreeTraverser)1 SchemaWriter (com.sun.xml.xsom.impl.util.SchemaWriter)1 ComponentNameFunction (com.sun.xml.xsom.util.ComponentNameFunction)1 AtlasException (io.atlasmap.api.AtlasException)1 Fields (io.atlasmap.v2.Fields)1 XmlDocument (io.atlasmap.xml.v2.XmlDocument)1 XmlFields (io.atlasmap.xml.v2.XmlFields)1