Package org.w3.x2001.xmlSchema

Examples of org.w3.x2001.xmlSchema.TopLevelElement


        */
    }
   
    public static void dontTestQNameCopy() throws Exception
    {
        SchemaDocument xobj = SchemaDocument.Factory.parse(
                "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
                "<xs:element name='foo' type='xs:string'/></xs:schema>");
        SchemaDocument xobj2 = SchemaDocument.Factory.parse(
                "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>");
        xobj2.getSchema().addNewElement().set(xobj.getSchema().getElementArray(0));
        System.out.println(xobj2);
    }
View Full Code Here


    public void testSourceName() throws Throwable
    {
        String name = DefaultsDocument.type.getSourceName();
        Assert.assertEquals("defaults.xsd", name);
        InputStream str = XmlBeans.getContextTypeLoader().getSourceAsStream("defaults.xsd");
        SchemaDocument doc = SchemaDocument.Factory.parse(str);
        Assert.assertTrue(doc.validate());
    }
View Full Code Here

                    {
                        state.error("Referenced document is not a valid schema", XmlErrorContext.CANNOT_FIND_RESOURCE, referencedBy);
                        break download;
                    }

                    SchemaDocument sDoc = (SchemaDocument)xdoc;

                    result = sDoc.getSchema();
                    state.info("Loading referenced file " + shortname);
                }
                NsLocPair key = new NsLocPair(emptyStringIfNull(result.getTargetNamespace()), absoluteURL);
                addSuccessfulDownload(key, result);
                return result;
View Full Code Here

        for (int i = 0; i < files.length; i++)
        {
            try
            {
                // load schema
                SchemaDocument doc = SchemaDocument.Factory.parse(files[i]);
                schemaDocs.put(doc, files[i]);
               
                // warn about for imports, includes
                if (doc.getSchema().sizeOfImportArray() > 0 || doc.getSchema().sizeOfIncludeArray() > 0)
                    System.out.println("warning: " + files[i] + " contains imports or includes that are being ignored.");
               
                // collect together names
                String targetNamespace = doc.getSchema().getTargetNamespace();
                if (targetNamespace == null)
                    targetNamespace = "";
               
                TopLevelComplexType ct[] = doc.getSchema().getComplexTypeArray();
                for (int j = 0; j < ct.length; j++)
                    noteName(ct[j].getName(), targetNamespace, typeNames, dupeTypeNames, dupeNamespaces);

                TopLevelSimpleType st[] = doc.getSchema().getSimpleTypeArray();
                for (int j = 0; j < st.length; j++)
                    noteName(st[j].getName(), targetNamespace, typeNames, dupeTypeNames, dupeNamespaces);

                TopLevelElement el[] = doc.getSchema().getElementArray();
                for (int j = 0; j < el.length; j++)
                    noteName(el[j].getName(), targetNamespace, elementNames, dupeElementNames, dupeNamespaces);

                TopLevelAttribute at[] = doc.getSchema().getAttributeArray();
                for (int j = 0; j < at.length; j++)
                    noteName(at[j].getName(), targetNamespace, attributeNames, dupeAttributeNames, dupeNamespaces);
               
                NamedGroup gr[] = doc.getSchema().getGroupArray();
                for (int j = 0; j < gr.length; j++)
                    noteName(gr[j].getName(), targetNamespace, modelGroupNames, dupeModelGroupNames, dupeNamespaces);
               
                NamedAttributeGroup ag[] = doc.getSchema().getAttributeGroupArray();
                for (int j = 0; j < ag.length; j++)
                    noteName(ag[j].getName(), targetNamespace, attrGroupNames, dupeAttrGroupNames, dupeNamespaces);
               
            }
            catch (XmlException e)
            {
                System.out.println("warning: " + files[i] + " is not a schema file - " + e.getError().toString());
            }
            catch (IOException e)
            {
                System.err.println("Unable to load " + files[i] + " - " + e.getMessage());
                System.exit(1);
                return;
            }
        }
       
        if (schemaDocs.size() == 0)
        {
            System.out.println("No schema files found.");
            System.exit(0);
            return;
        }
       
        if (dupeTypeNames.size() + dupeElementNames.size() + dupeAttributeNames.size() +
                dupeModelGroupNames.size() + dupeAttrGroupNames.size() == 0)
        {
            System.out.println("No duplicate names found.");
            System.exit(0);
            return;
        }
       
        // create a schema doc for each namespace to be imported
        Map commonDocs = new HashMap();
        Map commonFiles = new HashMap();
        int count = dupeNamespaces.size() == 1 ? 0 : 1;
        for (Iterator i = dupeNamespaces.iterator(); i.hasNext(); )
        {
            String namespace = (String)i.next();
            SchemaDocument commonDoc = SchemaDocument.Factory.parse(
                    "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'/>"
            );
            if (namespace.length() > 0)
                commonDoc.getSchema().setTargetNamespace(namespace);
            commonDoc.getSchema().setElementFormDefault(FormChoice.QUALIFIED);
            commonDocs.put(namespace, commonDoc);
            commonFiles.put(commonDoc, commonFileFor(commonName, namespace, count++, outdir));
        }
       
        // pull out all the duplicate definitions and drop them into the file
        // we reuse the elementNames (etc) sets to keep track of which definitions
        // we have already inserted.
        for (Iterator i = schemaDocs.keySet().iterator(); i.hasNext(); )
        {
            SchemaDocument doc = (SchemaDocument)i.next();
           
            // collect together names
            String targetNamespace = doc.getSchema().getTargetNamespace();
            if (targetNamespace == null)
                targetNamespace = "";
           
            SchemaDocument commonDoc = (SchemaDocument)commonDocs.get(targetNamespace);
           
            boolean needImport = false;
               
            TopLevelComplexType ct[] = doc.getSchema().getComplexTypeArray();
            for (int j = ct.length - 1; j >= 0; j--)
            {
                if (!isDuplicate(ct[j].getName(), targetNamespace, dupeTypeNames))
                    continue;
                if (isFirstDuplicate(ct[j].getName(), targetNamespace, typeNames, dupeTypeNames))
                    commonDoc.getSchema().addNewComplexType().set(ct[j]);
                needImport = true;
                doc.getSchema().removeComplexType(j);
            }

            TopLevelSimpleType st[] = doc.getSchema().getSimpleTypeArray();
            for (int j = 0; j < st.length; j++)
            {
                if (!isDuplicate(st[j].getName(), targetNamespace, dupeTypeNames))
                    continue;
                if (isFirstDuplicate(st[j].getName(), targetNamespace, typeNames, dupeTypeNames))
                    commonDoc.getSchema().addNewSimpleType().set(st[j]);
                needImport = true;
                doc.getSchema().removeSimpleType(j);
            }

            TopLevelElement el[] = doc.getSchema().getElementArray();
            for (int j = 0; j < el.length; j++)
            {
                if (!isDuplicate(el[j].getName(), targetNamespace, dupeElementNames))
                    continue;
                if (isFirstDuplicate(el[j].getName(), targetNamespace, elementNames, dupeElementNames))
                    commonDoc.getSchema().addNewElement().set(el[j]);
                needImport = true;
                doc.getSchema().removeElement(j);
            }

            TopLevelAttribute at[] = doc.getSchema().getAttributeArray();
            for (int j = 0; j < at.length; j++)
            {
                if (!isDuplicate(at[j].getName(), targetNamespace, dupeAttributeNames))
                    continue;
                if (isFirstDuplicate(at[j].getName(), targetNamespace, attributeNames, dupeAttributeNames))
                    commonDoc.getSchema().addNewElement().set(at[j]);
                needImport = true;
                doc.getSchema().removeElement(j);
            }

            NamedGroup gr[] = doc.getSchema().getGroupArray();
            for (int j = 0; j < gr.length; j++)
            {
                if (!isDuplicate(gr[j].getName(), targetNamespace, dupeModelGroupNames))
                    continue;
                if (isFirstDuplicate(gr[j].getName(), targetNamespace, modelGroupNames, dupeModelGroupNames))
                    commonDoc.getSchema().addNewElement().set(gr[j]);
                needImport = true;
                doc.getSchema().removeElement(j);
            }
               
            NamedAttributeGroup ag[] = doc.getSchema().getAttributeGroupArray();
            for (int j = 0; j < ag.length; j++)
            {
                if (!isDuplicate(ag[j].getName(), targetNamespace, dupeAttrGroupNames))
                    continue;
                if (isFirstDuplicate(ag[j].getName(), targetNamespace, attrGroupNames, dupeAttrGroupNames))
                    commonDoc.getSchema().addNewElement().set(ag[j]);
                needImport = true;
                doc.getSchema().removeElement(j);
            }
           
            if (needImport)
            {
                IncludeDocument.Include newInclude = doc.getSchema().addNewInclude();
                File inputFile = (File)schemaDocs.get(doc);
                File outputFile = outputFileFor(inputFile, basedir, outdir);
                File commonFile = (File)commonFiles.get(commonDoc);
                if (targetNamespace != null)
                    newInclude.setSchemaLocation(relativeURIFor(outputFile, commonFile));
            }
        }
       
        // make the directory for output
        if (!outdir.isDirectory() && !outdir.mkdirs())
        {
            System.err.println("Unable to makedir " + outdir);
            System.exit(1);
            return;
        }
       
        // now write all those docs back out.
        for (Iterator i = schemaDocs.keySet().iterator(); i.hasNext(); )
        {
            SchemaDocument doc = (SchemaDocument)i.next();
            File inputFile = (File)schemaDocs.get(doc);
            File outputFile = outputFileFor(inputFile, basedir, outdir);
            if (outputFile == null)
                System.out.println("Cannot copy " + inputFile);
            else
                doc.save(outputFile, new XmlOptions().setSavePrettyPrint().setSaveAggresiveNamespaces());
        }
       
        for (Iterator i = commonFiles.keySet().iterator(); i.hasNext(); )
        {
            SchemaDocument doc = (SchemaDocument)i.next();
            File outputFile = (File)commonFiles.get(doc);
            doc.save(outputFile, new XmlOptions().setSavePrettyPrint().setSaveAggresiveNamespaces());
        }
       
    }
View Full Code Here

        */
    }
   
    public static void dontTestQNameCopy() throws Exception
    {
        SchemaDocument xobj = SchemaDocument.Factory.parse(
                "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
                "<xs:element name='foo' type='xs:string'/></xs:schema>");
        SchemaDocument xobj2 = SchemaDocument.Factory.parse(
                "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>");
        xobj2.getSchema().addNewElement().set(xobj.getSchema().getElementArray(0));
        System.out.println(xobj2);
    }
View Full Code Here

    public void testSourceName() throws Throwable
    {
        String name = DefaultsDocument.type.getSourceName();
        Assert.assertEquals("defaults.xsd", name);
        InputStream str = XmlBeans.getContextTypeLoader().getSourceAsStream("defaults.xsd");
        SchemaDocument doc = SchemaDocument.Factory.parse(str);
        Assert.assertTrue(doc.validate());
    }
View Full Code Here

    }

    static XmlObject parseWithNamespaces(Element element, Map namespaceMap) throws XmlException {
        ArrayList errors = new ArrayList();
        XmlOptions xmlOptions = SchemaConversionUtils.createXmlOptions(errors);
        SchemaDocument parsed = SchemaDocument.Factory.parse(element, xmlOptions);
        if (errors.size() != 0) {
            throw new XmlException(errors.toArray().toString());
        }
        XmlCursor cursor = parsed.newCursor();
        try {
            cursor.toFirstContentToken();
            for (Iterator namespaces = namespaceMap.entrySet().iterator(); namespaces.hasNext();) {
                Map.Entry entry = (Map.Entry) namespaces.next();
                cursor.insertNamespace((String) entry.getKey(), (String) entry.getValue());
View Full Code Here

        for (Iterator iterator = rawWsdlMap.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            URI key = (URI) entry.getKey();
            Object value = entry.getValue();
            if (value instanceof SchemaDocument) {
                SchemaDocument schemaDocument = (SchemaDocument) ((SchemaDocument) value).copy();
                SchemaDocument.Schema schema = schemaDocument.getSchema();
                rewriteSchema(schema, contextURI, key);
                String schemaString = schemaDocument.toString();
                wsdlMap.put(key.toString(), schemaString);
            } else if (value instanceof DefinitionsDocument) {
                DefinitionsDocument doc = (DefinitionsDocument) ((DefinitionsDocument) value).copy();
                TDefinitions definitions = doc.getDefinitions();
                TImport[] imports = definitions.getImportArray();
View Full Code Here

    public static void resolveComplexType(SchemaTypeImpl sImpl)
    {
        ComplexType parseCt = (ComplexType)sImpl.getParseObject();
        StscState state = StscState.get();
        Schema schema = getSchema(parseCt);

        // Set abstract & final flags
        boolean abs = parseCt.isSetAbstract() ? parseCt.getAbstract() : false;
        boolean finalExt = false;
        boolean finalRest = false;
        boolean finalList = false;
        boolean finalUnion = false;

        Object ds = null;
        if (parseCt.isSetFinal())
        {
            ds = parseCt.getFinal();
        }
        // Inspect the final default attribute on the schema
        else if (schema != null && schema.isSetFinalDefault())
        {
            ds = schema.getFinalDefault();
        }

        if (ds != null)
        {
            if (ds instanceof String && ds.equals("#all"))
            {
                // #ALL value
                finalExt = finalRest = finalList = finalUnion = true;
            }
            else if (ds instanceof List)
            {
                if (((List)ds).contains("extension"))
                    finalExt = true;
               
                if (((List)ds).contains("restriction"))
                    finalRest = true;

// Since complex types don't participate in list and unions, these can remain
// false.  Perhaps we should throw an error.

//                if (((List)ds).contains("list"))
//                    finalList = true;
//               
//                if (((List)ds).contains("union"))
//                    finalUnion = true;
            }
        }

        sImpl.setAbstractFinal(abs, finalExt, finalRest, finalList, finalUnion);

        // Set block flags
        boolean blockExt = false;
        boolean blockRest = false;
        Object block = null;

        if (parseCt.isSetBlock())
            block = parseCt.getBlock();
        else if (schema != null && schema.isSetBlockDefault())
            block = schema.getBlockDefault();

        if (block != null)
        {
            if (block instanceof String && block.equals("#all"))
            {
View Full Code Here

            }

            // probe 1: ns+url - perfect match
            if (absoluteURL != null && targetNamespace != null)
            {
                Schema result = (Schema)schemaByNsLocPair.get(new NsLocPair(targetNamespace, absoluteURL));
                if (result != null)
                    return result;
            }

            StscState state = StscState.get();

            // probe 2: we have preexisting knowledge of this namespace,
            // either from another schema file or from the linker.
            // If we're not downloading the given URL, skip it silently if the
            // namespace is already represented by a file we have.
            // Also, suppress downloads of URLs to namespaces that are already
            // known by the linker.
            // (We never assume preexisting knowledge of the no-namespace,
            // even if we have some definitions, since it's likely that
            // more than one person is playing in the no-namespace at once.)
            if (targetNamespace != null && !targetNamespace.equals(""))
            {
                // the URL is not one to download; should we assume we know about the namespace?
                if (!state.shouldDownloadURI(absoluteURL))
                {
                    // If we already have a schema representing this namespace,
                    // then skip this URL silently without producing an error.
                    Schema result = (Schema)schemaByNsLocPair.get(new NsLocPair(targetNamespace, null));
                    if (result != null)
                        return result;
                }

                // If the linker already knows about this namespace, skip
                // this URL.
                if (state.linkerDefinesNamespace(targetNamespace))
                    return null;
            }

            // probe 3: url only
            if (absoluteURL != null)
            {
                Schema result = (Schema)schemaByNsLocPair.get(new NsLocPair(null, absoluteURL));
                if (result != null)
                    return result;
            }

            // no match: error if we can't or won't download.
            if (absoluteURL == null)
            {
                state.error("Could not find resource - no valid location URL.", XmlErrorContext.CANNOT_FIND_RESOURCE, referencedBy);
                return null;
            }

            if (previouslyFailedToDownload(absoluteURL))
            {
                // an error message has already been produced.
                return null;
            }

            if (!state.shouldDownloadURI(absoluteURL))
            {
                state.error("Could not load resource \"" + absoluteURL + "\" (network downloads disabled).", XmlErrorContext.CANNOT_FIND_RESOURCE, referencedBy);
                addFailedDownload(absoluteURL);
                return null;
            }

            // try to download
            download: try
            {
                XmlObject xdoc = downloadDocument(state.getS4SLoader(), targetNamespace, absoluteURL);

                Schema result = findMatchByDigest(xdoc);
                String shortname = state.relativize(absoluteURL);
                if (result != null)
                {
                    // if an exactly-the-same document has already been loaded, use the original and spew
                    String dupname = state.relativize(result.documentProperties().getSourceName());
                    if (dupname != null)
                        state.info(shortname + " is the same as " + dupname + " (ignoring the duplicate file)");
                    else
                        state.info(shortname + " is the same as another schema");
                }
                else
                {
                    // otherwise, it's a new document: validate it and grab the contents
                    XmlOptions voptions = new XmlOptions();
                    voptions.setErrorListener(state.getErrorListener());
                    if (!(xdoc instanceof SchemaDocument) || !xdoc.validate(voptions))
                    {
                        state.error("Referenced document is not a valid schema", XmlErrorContext.CANNOT_FIND_RESOURCE, referencedBy);
                        break download;
                    }

                    SchemaDocument sDoc = (SchemaDocument)xdoc;

                    result = sDoc.getSchema();
                    state.info("Loading referenced file " + shortname);
                }
                NsLocPair key = new NsLocPair(emptyStringIfNull(result.getTargetNamespace()), absoluteURL);
                addSuccessfulDownload(key, result);
                return result;
            }
            catch (MalformedURLException malformed)
            {
View Full Code Here

TOP

Related Classes of org.w3.x2001.xmlSchema.TopLevelElement

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.