Code example for InputSource

Methods: getSystemId

0
            throw new ToolException(e);
        } 
 
        String systemId = null;
        systemId = URIParserUtil.getAbsoluteURI(wsdlsource);
        InputSource is = new InputSource(systemId);
 
        return validate(is, schemas);
 
    } 
 
    private Schema createSchema(List<InputSource> xsdsInJar, String[] schemas)
        throws SAXException, IOException { 
 
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
 
        SchemaResourceResolver resourceResolver = new SchemaResourceResolver();
 
        sf.setResourceResolver(resourceResolver);
 
        List<Source> sources = new ArrayList<Source>();
 
        for (InputSource is : xsdsInJar) {
            Message msg = new Message("CREATE_SCHEMA_LOADED_FROM_JAR", LOG, is.getSystemId());
            LOG.log(Level.FINE, msg.toString());
            Document doc = docBuilder.parse(is.getByteStream());
            DOMSource stream = new DOMSource(doc, is.getSystemId());
            stream.setSystemId(is.getSystemId());
            sources.add(stream);
        } 
 
        if (schemas != null) {
            for (int i = 0; i < schemas.length; i++) {
                Document doc = docBuilder.parse(schemas[i]);
                DOMSource stream = new DOMSource(doc, schemas[i]);
                sources.add(stream);
            } 
        } 
        Source[] args = new Source[sources.size()];
        sources.toArray(args);
        return sf.newSchema(args);
 
    } 
 
    private Schema createSchema(String[] schemas) throws SAXException, IOException {
 
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
 
        SchemaResourceResolver resourceResolver = new SchemaResourceResolver();
 
        sf.setResourceResolver(resourceResolver);
 
        Source[] sources = new Source[schemas.length];
 
        for (int i = 0; i < schemas.length; i++) {
            // need to validate the schema file 
            Document doc = docBuilder.parse(schemas[i]);
 
            DOMSource stream = new DOMSource(doc, schemas[i]);
 
            sources[i] = stream;
        } 
        return sf.newSchema(sources);
 
    } 
 
    public boolean validate(InputSource wsdlsource, String[] schemas) throws ToolException {
        boolean isValid = false;
        Schema schema;
        try { 
            SAXParserFactory saxFactory = SAXParserFactory.newInstance();
            saxFactory.setFeature("http://xml.org/sax/features/namespaces", true);
            saxParser = saxFactory.newSAXParser();
 
            if (defaultSchemas != null) {
                schemas = addSchemas(defaultSchemas, schemas);
                schema = createSchema(schemas);
            } else { 
                schema = createSchema(schemaFromJar, schemas);
            } 
 
 
            Validator validator = schema.newValidator();
 
            NewStackTraceErrorHandler errHandler = new NewStackTraceErrorHandler();
            validator.setErrorHandler(errHandler);
            SAXSource saxSource = new SAXSource(saxParser.getXMLReader(), wsdlsource);
            validator.validate(saxSource);
 
 
            if (!errHandler.isValid()) {
                throw new ToolException(errHandler.getErrorMessages());
            } 
 
            isValid = true;
 
        } catch (IOException ioe) {
            throw new ToolException("Cannot get the wsdl " + wsdlsource.getSystemId(), ioe);
        } catch (SAXException saxEx) {
            throw new ToolException(saxEx);
        } catch (ParserConfigurationException e) {
            throw new ToolException(e);
        }