com.sun.tools.internal.xjc.reader.internalizer.DOMForest Java Examples

The following examples show how to use com.sun.tools.internal.xjc.reader.internalizer.DOMForest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #2
Source File: ModelLoader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #3
Source File: ModelLoader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #4
Source File: ModelLoader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #5
Source File: ModelLoader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #6
Source File: ModelLoader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #7
Source File: ModelLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #8
Source File: ModelLoader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #9
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #10
Source File: ModelLoader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #11
Source File: ModelLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #12
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #13
Source File: ModelLoader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #14
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #15
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #16
Source File: ModelLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #17
Source File: ModelLoader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #18
Source File: ModelLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a set of XML Schema files into an annotated grammar.
 */
public XSSchemaSet loadXMLSchema() throws SAXException {

    if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
        // schema error. error should have been reported
        return null;
    }

    if(opt.getBindFiles().length==0) {
        // no external binding. try the speculative no DOMForest execution,
        // which is faster if the speculation succeeds.
        try {
            return createXSOMSpeculative();
        } catch( SpeculationFailure e) {
            // failed. go the slow way
        }
    }

    // the default slower way is to parse everything into DOM first.
    // so that we can take external annotations into account.
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
    return createXSOM(forest, scdBasedBindingSet);
}
 
Example #19
Source File: ModelLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #20
Source File: ModelLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a {@link DOMForest} into a {@link XSSchemaSet}.
 *
 * @return
 *      null if the parsing failed.
 */
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
    // set up other parameters to XSOMParser
    XSOMParser reader = createXSOMParser(forest);

    // re-parse the transformed schemas
    for (String systemId : forest.getRootDocuments()) {
        errorReceiver.pollAbort();
        Document dom = forest.get(systemId);
        if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
            reader.parse(systemId);
        }
    }

    XSSchemaSet result = reader.getResult();

    if(result!=null)
        scdBasedBindingSet.apply(result,errorReceiver);

    return result;
}
 
Example #21
Source File: ModelLoader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #22
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public XSOMParser createXSOMParser(final DOMForest forest) {
    XSOMParser p = createXSOMParser(forest.createParser());
    p.setEntityResolver(new EntityResolver() {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            // DOMForest only parses documents that are reachable through systemIds,
            // and it won't pick up references like <xs:import namespace="..." /> without
            // @schemaLocation. So we still need to use an entity resolver here to resolve
            // these references, yet we don't want to just run them blindly, since if we do that
            // DOMForestParser always get the translated system ID when catalog is used
            // (where DOMForest records trees with their original system IDs.)
            if(systemId!=null && forest.get(systemId)!=null)
                return new InputSource(systemId);
            if(opt.entityResolver!=null)
                return opt.entityResolver.resolveEntity(publicId,systemId);

            return null;
        }
    });
    return p;
}
 
Example #23
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a set of schemas inside a WSDL file.
 *
 * A WSDL file may contain multiple &lt;xsd:schema> elements.
 */
private XSSchemaSet loadWSDL()
    throws SAXException {


    // build DOMForest just like we handle XML Schema
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );

    DOMForestScanner scanner = new DOMForestScanner(forest);

    XSOMParser xsomParser = createXSOMParser( forest );

    // find <xsd:schema>s and parse them individually
    for( InputSource grammar : opt.getGrammars() ) {
        Document wsdlDom = forest.get( grammar.getSystemId() );
        if (wsdlDom == null) {
            String systemId = Options.normalizeSystemId(grammar.getSystemId());
            if (forest.get(systemId) != null) {
                grammar.setSystemId(systemId);
                wsdlDom = forest.get( grammar.getSystemId() );
            }
        }

        NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
        for( int i=0; i<schemas.getLength(); i++ )
            scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
    }
    return xsomParser.getResult();
}
 
Example #24
Source File: ModelLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a RELAX NG grammar into an annotated grammar.
 */
private Model loadRELAXNG() throws SAXException {

    // build DOM forest
    final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );

    // use JAXP masquerading to validate the input document.
    // DOMForest -> ExtensionBindingChecker -> RNGOM

    XMLReaderCreator xrc = new XMLReaderCreator() {
        public XMLReader createXMLReader() {

            // foreset parser cannot change the receivers while it's working,
            // so we need to have one XMLFilter that works as a buffer
            XMLFilter buffer = new XMLFilterImpl() {
                @Override
                public void parse(InputSource source) throws IOException, SAXException {
                    forest.createParser().parse( source, this, this, this );
                }
            };

            XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
            f.setParent(buffer);

            f.setEntityResolver(opt.entityResolver);

            return f;
        }
    };

    Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );

    return loadRELAXNG(p);

}
 
Example #25
Source File: ModelLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a RELAX NG grammar into an annotated grammar.
 */
private Model loadRELAXNG() throws SAXException {

    // build DOM forest
    final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );

    // use JAXP masquerading to validate the input document.
    // DOMForest -> ExtensionBindingChecker -> RNGOM

    XMLReaderCreator xrc = new XMLReaderCreator() {
        public XMLReader createXMLReader() {

            // foreset parser cannot change the receivers while it's working,
            // so we need to have one XMLFilter that works as a buffer
            XMLFilter buffer = new XMLFilterImpl() {
                @Override
                public void parse(InputSource source) throws IOException, SAXException {
                    forest.createParser().parse( source, this, this, this );
                }
            };

            XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
            f.setParent(buffer);

            f.setEntityResolver(opt.entityResolver);

            return f;
        }
    };

    Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );

    return loadRELAXNG(p);

}
 
Example #26
Source File: ModelLoader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a set of schemas inside a WSDL file.
 *
 * A WSDL file may contain multiple {@code <xsd:schema>} elements.
 */
private XSSchemaSet loadWSDL()
    throws SAXException {


    // build DOMForest just like we handle XML Schema
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );

    DOMForestScanner scanner = new DOMForestScanner(forest);

    XSOMParser xsomParser = createXSOMParser( forest );

    // find <xsd:schema>s and parse them individually
    for( InputSource grammar : opt.getGrammars() ) {
        Document wsdlDom = forest.get( grammar.getSystemId() );
        if (wsdlDom == null) {
            String systemId = Options.normalizeSystemId(grammar.getSystemId());
            if (forest.get(systemId) != null) {
                grammar.setSystemId(systemId);
                wsdlDom = forest.get( grammar.getSystemId() );
            }
        }

        NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
        for( int i=0; i<schemas.getLength(); i++ )
            scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
    }
    return xsomParser.getResult();
}
 
Example #27
Source File: ModelLoader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a RELAX NG grammar into an annotated grammar.
 */
private Model loadRELAXNG() throws SAXException {

    // build DOM forest
    final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );

    // use JAXP masquerading to validate the input document.
    // DOMForest -> ExtensionBindingChecker -> RNGOM

    XMLReaderCreator xrc = new XMLReaderCreator() {
        public XMLReader createXMLReader() {

            // foreset parser cannot change the receivers while it's working,
            // so we need to have one XMLFilter that works as a buffer
            XMLFilter buffer = new XMLFilterImpl() {
                @Override
                public void parse(InputSource source) throws IOException, SAXException {
                    forest.createParser().parse( source, this, this, this );
                }
            };

            XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
            f.setParent(buffer);

            f.setEntityResolver(opt.entityResolver);

            return f;
        }
    };

    Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );

    return loadRELAXNG(p);

}
 
Example #28
Source File: ModelLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a RELAX NG grammar into an annotated grammar.
 */
private Model loadRELAXNG() throws SAXException {

    // build DOM forest
    final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );

    // use JAXP masquerading to validate the input document.
    // DOMForest -> ExtensionBindingChecker -> RNGOM

    XMLReaderCreator xrc = new XMLReaderCreator() {
        public XMLReader createXMLReader() {

            // foreset parser cannot change the receivers while it's working,
            // so we need to have one XMLFilter that works as a buffer
            XMLFilter buffer = new XMLFilterImpl() {
                @Override
                public void parse(InputSource source) throws IOException, SAXException {
                    forest.createParser().parse( source, this, this, this );
                }
            };

            XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
            f.setParent(buffer);

            f.setEntityResolver(opt.entityResolver);

            return f;
        }
    };

    Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );

    return loadRELAXNG(p);

}
 
Example #29
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a set of schemas inside a WSDL file.
 *
 * A WSDL file may contain multiple &lt;xsd:schema> elements.
 */
private XSSchemaSet loadWSDL()
    throws SAXException {


    // build DOMForest just like we handle XML Schema
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );

    DOMForestScanner scanner = new DOMForestScanner(forest);

    XSOMParser xsomParser = createXSOMParser( forest );

    // find <xsd:schema>s and parse them individually
    for( InputSource grammar : opt.getGrammars() ) {
        Document wsdlDom = forest.get( grammar.getSystemId() );
        if (wsdlDom == null) {
            String systemId = Options.normalizeSystemId(grammar.getSystemId());
            if (forest.get(systemId) != null) {
                grammar.setSystemId(systemId);
                wsdlDom = forest.get( grammar.getSystemId() );
            }
        }

        NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
        for( int i=0; i<schemas.getLength(); i++ )
            scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
    }
    return xsomParser.getResult();
}
 
Example #30
Source File: ModelLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a set of schemas inside a WSDL file.
 *
 * A WSDL file may contain multiple &lt;xsd:schema> elements.
 */
private XSSchemaSet loadWSDL()
    throws SAXException {


    // build DOMForest just like we handle XML Schema
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );

    DOMForestScanner scanner = new DOMForestScanner(forest);

    XSOMParser xsomParser = createXSOMParser( forest );

    // find <xsd:schema>s and parse them individually
    for( InputSource grammar : opt.getGrammars() ) {
        Document wsdlDom = forest.get( grammar.getSystemId() );
        if (wsdlDom == null) {
            String systemId = Options.normalizeSystemId(grammar.getSystemId());
            if (forest.get(systemId) != null) {
                grammar.setSystemId(systemId);
                wsdlDom = forest.get( grammar.getSystemId() );
            }
        }

        NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
        for( int i=0; i<schemas.getLength(); i++ )
            scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
    }
    return xsomParser.getResult();
}