Package org.apache.tuscany.sca.xsd

Examples of org.apache.tuscany.sca.xsd.XSDefinition


        wsdlDefinition.setUnresolved(false);
        wsdlDefinition.setDefinition(null);

        int index = 0;
        for (String tns : attr2.getValues()) {
            XSDefinition xsd = xsdFactory.createXSDefinition();
            xsd.setUnresolved(true);
            xsd.setNamespace(tns);
            xsd.setLocation(URI.create(doc.toURI() + "#" + index));
            index++;
            // The definition is marked as resolved but not loaded
            xsd.setUnresolved(false);
            xsd.setSchema(null);
            wsdlDefinition.getXmlSchemas().add(xsd);
        }
       
        if (attr2.getValues().size() == 0){
            // if there are no schema defined add in the XSD schema
            // so this at least gets resolved otherwise we'll get
            // errors when trying to resolve part types that
            // use primitive types
            XSDefinition xsd = xsdFactory.createXSDefinition();
            xsd.setUnresolved(true);
            xsd.setNamespace("http://www.w3.org/2001/XMLSchema");
            xsd.setUnresolved(false);
            xsd.setSchema(null);
            wsdlDefinition.getXmlSchemas().add(xsd);
        }
       
        return wsdlDefinition;
    }
View Full Code Here


        throws IOException {
        DOMResolverImpl resolver = new DOMResolverImpl();
        context.generateSchema(resolver);
        Map<String, DOMResult> results = resolver.getResults();
        for (Map.Entry<String, DOMResult> entry : results.entrySet()) {
            XSDefinition definition = factory.createXSDefinition();
            definition.setUnresolved(true);
            definition.setDocument((Document)entry.getValue().getNode());
            definition.setNamespace(entry.getKey());
            URI location = null;
            try {
                location = new URI(entry.getValue().getSystemId());
            } catch (URISyntaxException e) {
                // ignore: use null value
            }   
            definition.setLocation(location);
            definitions.add(definition);
        }
    }
View Full Code Here

            Map<Element, Map<String, String>> prefixMaps = new HashMap<Element, Map<String, String>>();
            for (Map.Entry<QName, List<ElementInfo>> entry: wrappers.entrySet()) {
                String targetNS = entry.getKey().getNamespaceURI();
                Document schemaDoc = null;
                Element schema = null;
                XSDefinition xsDef = wrapperXSDs.get(targetNS);
                if (xsDef != null) {
                    schemaDoc = xsDef.getDocument();
                    schema = schemaDoc.getDocumentElement();
                } else {
                    schemaDoc = createDocument();
                    schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema");
                    // The elementFormDefault should be set to unqualified, see TUSCANY-2388
                    schema.setAttribute("elementFormDefault", "unqualified");
                    schema.setAttribute("attributeFormDefault", "qualified");
                    schema.setAttribute("targetNamespace", targetNS);
                    schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS);
                    schemaDoc.appendChild(schema);
                    Schema schemaExt = createSchemaExt(definition);
                    schemaExt.setElement(schema);
                    prefixMaps.put(schema, new HashMap<String, String>());
                    xsDef = xsdFactory.createXSDefinition();
                    xsDef.setUnresolved(true);
                    xsDef.setNamespace(targetNS);
                    xsDef.setDocument(schemaDoc);
                    // TUSCANY-2465: Set the system id to avoid schema conflict
                    xsDef.setLocation(URI.create("xsd_" + index + ".xsd"));
                    index++;
                    wrapperXSDs.put(targetNS, xsDef);
                }
                Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element");
                schema.appendChild(wrapper);
View Full Code Here

    private void resolvePropertyType(String parentName, Property property, Contribution contribution, ProcessorContext context){
        // resolve the reference to a complex property
        // we ignore any types in the schema namespace
        if (property.getXSDType() != null &&
            property.getXSDType().getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema") != true){
            XSDefinition xsdDefinition = xsdFactory.createXSDefinition();
            xsdDefinition.setUnresolved(true);
            xsdDefinition.setNamespace(property.getXSDType().getNamespaceURI());
            // some unit tests don't set up contribution and model resolvers properly
            if (contribution != null && contribution.getModelResolver() != null) {
                XSDefinition resolved = contribution.getModelResolver().resolveModel(XSDefinition.class, xsdDefinition, context);
                if (resolved == null || resolved.isUnresolved()){
                    // raise an error
                    // [rfeng] The XSD might be not available if we use JAXB annotated classes, report it as a warning for now
                    warning(context.getMonitor(), "PropertyTypeNotFound", property, property.getXSDType().toString(), property.getName(), parentName);
                } else {
                    // store the schema in the property
View Full Code Here

    private XmlSchemaElement getElement(QName elementName) {

        XmlSchemaElement element = wsdlDefinition.getXmlSchemaElement(elementName);
        if (element == null) {
            XSDefinition definition = xsdFactory.createXSDefinition();
            definition.setUnresolved(true);
            definition.setNamespace(elementName.getNamespaceURI());
            definition = resolver.resolveModel(XSDefinition.class, definition, context);
            if (definition.getSchema() != null) {
                element = definition.getSchema().getElementByName(elementName);
            }
        }
        return element;
    }
View Full Code Here

    }

    private XmlSchemaType getType(QName typeName) {
        XmlSchemaType type = wsdlDefinition.getXmlSchemaType(typeName);
        if (type == null) {
            XSDefinition definition = xsdFactory.createXSDefinition();
            definition.setUnresolved(true);
            definition.setNamespace(typeName.getNamespaceURI());
            definition = resolver.resolveModel(XSDefinition.class, definition, context);
            if (definition.getSchema() != null) {
                type = definition.getSchema().getTypeByName(typeName);
            }
        }
        return type;
    }
View Full Code Here

                        element = ((UnknownExtensibilityElement)extElement).getElement();
                    }
                }
                if (element != null) {
                    Document doc = promote(element);
                    XSDefinition xsDefinition = xsdFactory.createXSDefinition();
                    xsDefinition.setUnresolved(true);
                    xsDefinition.setNamespace(element.getAttribute("targetNamespace"));
                    xsDefinition.setDocument(doc);
                    xsDefinition.setLocation(URI.create(doc.getDocumentURI() + "#" + index));
                    XSDefinition resolved =
                        contribution.getModelResolver().resolveModel(XSDefinition.class, xsDefinition, context);
                    if (resolved != null && !resolved.isUnresolved()) {
                        if (!wsdlDefinition.getXmlSchemas().contains(resolved)) {
                            // Don't add resolved because it may be an aggregate that
                            // contains more than we need.  The resolver will have
                            // set the specific schema we need into unresolved.
                            wsdlDefinition.getXmlSchemas().add(xsDefinition);
View Full Code Here

                // if this is the SCA schema store it in the system contribution
                if (namespace.equals(Constants.SCA11_TUSCANY_NS)){
                   
                    // add the schema to the model resolver under the Tuscany namespace
                    XSDefinition scaSchema = xsdFactory.createXSDefinition();
                    scaSchema.setUnresolved(true);
                    scaSchema.setNamespace(namespace);
                    scaSchema.setLocation(IOHelper.toURI(scaSchemaURL));
                    scaSchema.setUnresolved(false);
//                    modelResolver.addModel(scaSchema, context);
                } else if (namespace.equals(Constants.SCA11_NS)) {
                    // we know that the SCA schema's are referenced form the Tuscany schemas so
                    // register the schema under the SCA namespace too
                    XSDefinition scaSchema = xsdFactory.createXSDefinition();
                    scaSchema.setUnresolved(true);
                    scaSchema.setNamespace(Constants.SCA11_NS);
                    scaSchema.setLocation(IOHelper.toURI(scaSchemaURL));
                    scaSchema.setUnresolved(false);
                    modelResolver.addModel(scaSchema, context);                 
                }
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
View Full Code Here

            Map<Element, Map<String, String>> prefixMaps = new HashMap<Element, Map<String, String>>();
            for (Map.Entry<QName, List<ElementInfo>> entry: wrappers.entrySet()) {
                String targetNS = entry.getKey().getNamespaceURI();
                Document schemaDoc = null;
                Element schema = null;
                XSDefinition xsDef = wrapperXSDs.get(targetNS);
                if (xsDef != null) {
                    schemaDoc = xsDef.getDocument();
                    schema = schemaDoc.getDocumentElement();
                } else {
                    schemaDoc = createDocument();
                    schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema");
                    // The elementFormDefault should be set to unqualified, see TUSCANY-2388
                    schema.setAttribute("elementFormDefault", "unqualified");
                    schema.setAttribute("attributeFormDefault", "qualified");
                    schema.setAttribute("targetNamespace", targetNS);
                    schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS);
                    schemaDoc.appendChild(schema);
                    Schema schemaExt = createSchemaExt(definition);
                    schemaExt.setElement(schema);
                    prefixMaps.put(schema, new HashMap<String, String>());
                    xsDef = xsdFactory.createXSDefinition();
                    xsDef.setUnresolved(true);
                    xsDef.setNamespace(targetNS);
                    xsDef.setDocument(schemaDoc);
                    // TUSCANY-2465: Set the system id to avoid schema conflict
                    xsDef.setLocation(URI.create("xsd_" + index + ".xsd"));
                    index++;
                    wrapperXSDs.put(targetNS, xsDef);
                }
                Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element");
                schema.appendChild(wrapper);
View Full Code Here

        this.schemaCollection = new XmlSchemaCollection();
        this.factory = new DefaultXSDFactory();
    }

    public void addModel(Object resolved, ProcessorContext context) {
        XSDefinition definition = (XSDefinition)resolved;
        List<XSDefinition> list = map.get(definition.getNamespace());
        if (list == null) {
            list = new ArrayList<XSDefinition>();
            map.put(definition.getNamespace(), list);
        }
        list.add(definition);
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.xsd.XSDefinition

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.