Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.SchemaTypeLoader


                                           File baseDir,
                                           File schemasDir,
                                           EntityResolver entResolver) {


        SchemaTypeLoader loader = XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());

        // parse all the XSD files.
        List<SchemaDocument.Schema> scontentlist = new ArrayList<SchemaDocument.Schema>();
        try {
            URL url = new URL(wsdlFile);
            XmlOptions options = new XmlOptions();
            options.setLoadLineNumbers();
            options.setLoadSubstituteNamespaces(Collections
                .singletonMap("http://schemas.xmlsoap.org/wsdl/",
                              "http://www.apache.org/internal/xmlbeans/wsdlsubst"));
            options.setEntityResolver(entResolver);
            options.setGenerateJavaVersion(XmlOptions.GENERATE_JAVA_15);

            state.addSourceUri(wsdlFile, null);
            loadWSDLDoc(loader, url, options, scontentlist, errorListener);


        } catch (XmlException e) {
            errorListener.add(e.getError());
        } catch (Exception e) {
            StscState.addError(errorListener, XmlErrorCodes.CANNOT_LOAD_FILE, new Object[] {
                "url", wsdlFile, e.getMessage()
            }, (URL)null);
        }

        SchemaDocument.Schema[] sdocs = (SchemaDocument.Schema[])scontentlist
            .toArray(new SchemaDocument.Schema[scontentlist.size()]);
       
        // now the config files.
        List<ConfigDocument.Config> cdoclist = new ArrayList<ConfigDocument.Config>();
        List<File> javaFiles = new ArrayList<File>();
        if (configFiles != null) {
            for (int i = 0; i < configFiles.length; i++) {
                if (configFiles[i].endsWith(".java")) {
                    javaFiles.add(new File(configFiles[i]));
                    continue;
                }
                if (!configFiles[i].endsWith(".xsdconfig")) {
                    //jaxws/jaxb customization file or something else
                    continue;
                }
                try {
                    XmlOptions options = new XmlOptions();
                    options.put(XmlOptions.LOAD_LINE_NUMBERS);
                    options.setEntityResolver(entResolver);
                    options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);

                    URI uri = new URI(configFiles[i]);
                    XmlObject configdoc = null;
                    if ("file".equals(uri.getRawSchemeSpecificPart())) {
                        configdoc = loader.parse(new File(uri), null, options);                       
                    } else {
                        InputSource source = new InputSource(configFiles[i]);
                        Document doc = XMLUtils.parse(source);
                        configdoc = loader.parse(doc, null, options);                       
                    }
                   
                    if (!(configdoc instanceof ConfigDocument)) {
                        StscState.addError(errorListener, XmlErrorCodes.INVALID_DOCUMENT_TYPE, new Object[] {
                            configFiles[i], "xsd config"
                        }, configdoc);
                    } else {
                        StscState.addInfo(errorListener, "Loading config file " + configFiles[i]);
                        if (configdoc.validate(new XmlOptions().setErrorListener(errorListener))) {
                            ConfigDocument.Config config = ((ConfigDocument)configdoc).getConfig();
                            cdoclist.add(config);
                            config.setExtensionArray(new Extensionconfig[] {});
                        }
                    }
                } catch (XmlException e) {
                    errorListener.add(e.getError());
                } catch (Exception e) {
                    StscState.addError(errorListener, XmlErrorCodes.CANNOT_LOAD_FILE, new Object[] {
                        "xsd config", configFiles[i], e.getMessage()
                    }, new File(configFiles[i]));
                }
            }
        }
        ConfigDocument.Config[] cdocs = (ConfigDocument.Config[])cdoclist
            .toArray(new ConfigDocument.Config[cdoclist.size()]);


        SchemaTypeLoader linkTo = SchemaTypeLoaderImpl.build(null, cpResourceLoader, null);

        URI baseURI = null;
        if (baseDir != null) {
            baseURI = baseDir.toURI();
        }
View Full Code Here


    public static Test suite() { return new TestSuite(RuntimeSchemaLoaderTest.class); }

    public void testDynamicLoad() throws Throwable
    {
        File inputfile1 = TestEnv.xbeanCase("schema/dynamic/dyntest.xsd");
        SchemaTypeLoader loader = XmlBeans.loadXsd(new XmlObject[] { XmlObject.Factory.parse(inputfile1) });
        XmlObject result = loader.parse(TestEnv.xbeanCase("schema/dynamic/dyntest.xml"), null, null);
        Assert.assertEquals("D=wrappedinstance@http://openuri.org/test/dyntest", result.schemaType().toString());
        Assert.assertEquals(loader.findDocumentType(new QName("http://openuri.org/test/dyntest", "wrappedinstance" )),
                            result.schemaType());
    }
View Full Code Here

    }

    public void testDynamicLoad2() throws Throwable
    {
        File inputfile1 = TestEnv.xbeanCase("schema/dynamic/dyntest2.xsd");
        SchemaTypeLoader loader = XmlBeans.loadXsd(new XmlObject[] { XmlObject.Factory.parse(inputfile1) });
        XmlObject result = loader.parse(TestEnv.xbeanCase("schema/dynamic/dyntest2.xml"), null, null);
        Assert.assertEquals("D=wrappedwildcard@http://openuri.org/test/dyntest", result.schemaType().toString());
        Assert.assertEquals(loader.findDocumentType(new QName("http://openuri.org/test/dyntest", "wrappedwildcard")),
                            result.schemaType());
        XmlCursor cur = result.newCursor();
        Assert.assertTrue("Should have a root element", cur.toFirstChild());
        result = cur.getObject();
        Assert.assertEquals("E=wrappedwildcard|D=wrappedwildcard@http://openuri.org/test/dyntest", result.schemaType().toString());
        Assert.assertEquals(loader.findElement(new QName("http://openuri.org/test/dyntest", "wrappedwildcard")).getType(),
                            result.schemaType());
        Assert.assertTrue("Should have a first child", cur.toFirstChild());
        Assert.assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "schema"), cur.getName());
        XmlObject obj = cur.getObject();
        Assert.assertEquals(Schema.type, obj.schemaType());
View Full Code Here

            "  </xs:element>\n" +
            "" +
            "</xs:schema>\n" +
            "";

        SchemaTypeLoader stl =
            XmlBeans.loadXsd( new XmlObject[] {
                XmlObject.Factory.parse(schema) } );

       
        //
        // Test the set_XMLName function on XmlQNameImpl
        //

        String ns =
            "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
                "xmlns:xs='http://www.w3.org/2001/XMLSchema'";
       
        XmlObject sourceDocument =
            stl.parse(
                "<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'>" +
                    "xxx:abc</any>", null, null );

        XmlCursor sourceCursor = sourceDocument.newCursor();

        sourceCursor.toFirstChild();

        XmlQName sourceQName = (XmlQName) sourceCursor.getObject();

        XmlObject targetDocument =
            stl.parse(
                "<any " + ns + " xsi:type='xs:QName'>" +
                    "</any>", null, null );

        XmlCursor targetCursor = targetDocument.newCursor();

        targetCursor.toFirstChild();

        XmlQName targetQName = (XmlQName) targetCursor.getObject();

        targetQName.set( sourceQName );

        Assert.assertTrue(
            targetQName.qNameValue().getNamespaceURI().equals( "xxx.com" ) );

        //
        // Test the set_text function on XmlQNameImpl
        //
       
        targetDocument =
            stl.parse(
                "<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'>" +
                    "</any>", null, null );

        targetCursor = targetDocument.newCursor();
View Full Code Here

        {
            try
            {
                for (int i = 0; i < ITERATION_COUNT; i++)
                {
                    SchemaTypeLoader loader = XmlBeans.loadXsd(new XmlObject[] { XmlObject.Factory.parse(TestEnv.xbeanCase("schema/XmlSignature/xmldsig-core-schema.xsd")) });
                    XmlObject result = loader.parse(TestEnv.xbeanCase("schema/XmlSignature/signature-example.xml"), null, null);
                    Assert.assertEquals(loader.findDocumentType(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature")), result.schemaType());
                }
                _result = true;
            }
            catch (Throwable t)
            {
View Full Code Here

    public void doTest (
        String[] schemas, QName docType,
        String[] validInstances, String[] invalidInstances, boolean startOnDocument )
            throws Exception
    {
        SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );

        XmlOptions options = new XmlOptions();

        if (docType != null)
        {
            SchemaType docSchema = stl.findDocumentType( docType );

            Assert.assertTrue( docSchema != null );
           
            options.put( XmlOptions.DOCUMENT_TYPE, docSchema );
        }

        for ( int i = 0 ; i < validInstances.length ; i++ )
        {
            XmlObject x =
                stl.parse( (String) validInstances[ i ], null, options );

            if (!startOnDocument)
            {
                XmlCursor c = x.newCursor();
                c.toFirstChild();
                x = c.getObject();
                c.dispose();
            }
           
            List xel = new ArrayList();
           
            options.put( XmlOptions.ERROR_LISTENER, xel );
           
            boolean isValid = x.validate( options );
           
            if (!isValid)
            {
                System.err.println( "Invalid doc, expected a valid doc: " );
                System.err.println( "Instance(" + i + "): " );
                System.err.println( x.xmlText() );
                Root.dump( x );
                System.err.println( "Errors: " );
                for ( int j = 0 ; j < xel.size() ; j++ )
                    System.err.println( xel.get( j ) );
                System.err.println();
            }
           
            Assert.assertTrue( isValid );
        }

        for ( int i = 0 ; i < invalidInstances.length ; i++ )
        {
            XmlObject x;
           
            try
            {
                x = stl.parse( (String) invalidInstances[ i ], null, options );

                if (! startOnDocument)
                {
                    XmlCursor c = x.newCursor();
                    c.toFirstChild();
View Full Code Here

            "</xs:schema>" +
            "";
       
        String[] schemas = { schema };
       
        SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );
       
        //
        // One which uses ##targetNamespace on a wildcard
        //
       
        schema =
            "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
            "  <xs:complexType name='foo'>\n" +
            "    <xs:sequence>\n" +
            "      <xs:any namespace='##targetNamespace'/>\n" +
            "    </xs:sequence>\n" +
            "  </xs:complexType>\n" +
            "</xs:schema>" +
            "";
       
        String[] schemas99 = { schema };
       
        stl = makeSchemaTypeLoader( schemas99 );
       
        //
        // A big, nasty schema :-)
        //
       
        File file = TestEnv.getRootFile();
        File schemeFile = new File( file, "test/cases/schema/s4s/XMLSchema.xsd" );
        File xmlFile = new File( file, "test/cases/schema/s4s/XML.xsd" );

        File[] schemasF = { schemeFile, xmlFile };

        Root.disableStoreValidation();
        try
        {
            stl = makeSchemaTypeLoader( schemasF );
        }
        finally
        {
            Root.enableStoreValidation();
        }

        SchemaType type =
            stl.findDocumentType(
                new QName( "http://www.w3.org/2001/XMLSchema", "schema" ) );

        Assert.assertTrue( type != null );

View Full Code Here

            "</xs:schema>\n" +
            "";

        String[] schemas = { schema };

        SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );

        XmlObject x =
            stl.parse(
                "<any " + ns + " xsi:type='kindaPrime'>100</any>",
                null, null );

        // Make sure the unvalidated stream is OK

        XMLInputStream xis = x.newXMLInputStream();

        while ( xis.hasNext() )
            xis.next();

        // Make sure the validated stream fails

        boolean blewChunks = false;

        xis =
            stl.newValidatingXMLInputStream(
                x.newXMLInputStream(), null, null );

        try
        {
            while ( xis.hasNext() )
View Full Code Here

            "</xs:schema>\n" +
            "";

        String[] schemas = { schema };

        SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );

        XmlObject x =
            stl.parse(
                "<hee yee='3'><haw>66</haw></hee>",
                    null, null );

        XmlCursor c = x.newCursor();

        for ( ; ; )
        {
            XmlObject obj = c.getObject();

            if (obj != null)
                obj.validate();

            if (c.toNextToken().isNone())
                break;
        }

        // invalid

        x =
            stl.parse(
                "<hee yee='five'><haw>66</haw></hee>",
                null, null );

        Assert.assertTrue( ! x.validate() );
View Full Code Here

            "</xs:schema>" +
            "";

        String[] schemas = { schema };

        SchemaTypeLoader stl = makeSchemaTypeLoader( schemas );

        XmlObject x =
            stl.parse(
                "<base><foo/></base>", null, null );

        Assert.assertTrue( x.validate() );

        XmlCursor c = x.newCursor();

        c.toFirstChild();

        XmlObject base = c.getObject();

        c.toEndToken();
        c.insertElement( "bar" );

        Assert.assertTrue( !x.validate() );

        c.toPrevSibling();

        c.removeXml();

        Assert.assertTrue( x.validate() );

        base.changeType( stl.findType( new QName( "derived" ) ) );

        c.insertElement( "bar" );

        Assert.assertTrue( x.validate() );
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.SchemaTypeLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.