Search in sources :

Example 41 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class CorbaUtils method isElementFormQualified.

// Change this method to access the XmlSchemaCollection.
public static boolean isElementFormQualified(ServiceInfo serviceInfo, String uri) {
    if (uri != null) {
        SchemaInfo schemaInfo = serviceInfo.getSchema(uri);
        if (schemaInfo != null) {
            return schemaInfo.isElementFormQualified();
        }
        Iterator<SchemaInfo> it = serviceInfo.getSchemas().iterator();
        while (it.hasNext()) {
            XmlSchema schema = it.next().getSchema();
            return isElementFormQualified(schema, uri);
        }
    }
    return false;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 42 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class ParticleInfo method factoryCommon.

private static void factoryCommon(XmlSchemaParticle particle, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, ParticleInfo elementInfo) {
    if (particle instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) particle;
        QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, currentSchema);
        String elementNamespaceURI = elementQName.getNamespaceURI();
        boolean elementNoNamespace = "".equals(elementNamespaceURI);
        XmlSchema elementSchema = null;
        if (!elementNoNamespace) {
            elementSchema = schemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
            if (elementSchema == null) {
                throw new RuntimeException("Missing schema " + elementNamespaceURI);
            }
        }
        boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, true, currentSchema, elementSchema);
        elementInfo.xmlName = prefixAccumulator.xmlElementString(elementQName, qualified);
        // we are assuming here that we are not dealing, in close proximity,
        // with elements with identical local names and different
        // namespaces.
        elementInfo.javascriptName = elementQName.getLocalPart();
        String schemaDefaultValue = element.getDefaultValue();
        /*
             * Schema default values are carried as strings.
             * In javascript, for actual strings, we need quotes, but not for
             * numbers. The following is a trick.
             */
        schemaDefaultValue = protectDefaultValue(schemaDefaultValue);
        elementInfo.defaultValue = schemaDefaultValue;
        factorySetupType(element, schemaCollection, elementInfo);
        elementInfo.isGroup = false;
    } else if (particle instanceof XmlSchemaChoice) {
        elementInfo.isGroup = true;
    } else if (particle instanceof XmlSchemaSequence) {
        elementInfo.isGroup = true;
    } else {
        // any
        elementInfo.any = true;
        // unknown until runtime.
        elementInfo.xmlName = null;
        // TODO: multiple 'any'
        elementInfo.javascriptName = "any";
        // runtime for any.
        elementInfo.type = null;
        elementInfo.isGroup = false;
    }
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 43 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class SchemaJavascriptBuilder method deserializeElement.

private void deserializeElement(XmlSchemaComplexType type, ParticleInfo itemInfo) {
    if (itemInfo.isGroup()) {
        for (ParticleInfo childElement : itemInfo.getChildren()) {
            deserializeElement(type, childElement);
        }
        return;
    }
    XmlSchemaType itemType = itemInfo.getType();
    boolean simple = itemType instanceof XmlSchemaSimpleType || JavascriptUtils.notVeryComplexType(itemType);
    boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType);
    String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
    utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
    XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();
    QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema);
    String elementNamespaceURI = elementQName.getNamespaceURI();
    boolean elementNoNamespace = "".equals(elementNamespaceURI);
    XmlSchema elementSchema = null;
    if (!elementNoNamespace) {
        elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
    }
    boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema, elementSchema);
    if (!qualified) {
        elementNamespaceURI = "";
    }
    String localName = elementQName.getLocalPart();
    String valueTarget = "item";
    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "')");
        if (itemInfo.isArray()) {
            utils.appendLine("item = [];");
            utils.startDo();
            valueTarget = "arrayItem";
            utils.appendLine("var arrayItem = null;");
        }
    }
    utils.appendLine("var value = null;");
    utils.startIf("!cxfjsutils.isElementNil(curElement)");
    if (itemInfo.isAnyType()) {
        // use our utility
        utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils, curElement);");
    } else if (simple) {
        if (mtomCandidate) {
            utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);");
        } else {
            utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
            utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value") + ";");
        }
    } else {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) itemType;
        QName baseQName = complexType.getQName();
        if (baseQName == null) {
            baseQName = element.getQName();
        }
        String elTypeJsName = nameManager.getJavascriptName(baseQName);
        utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
    }
    // the if for the nil.
    utils.endBlock();
    if (itemInfo.isArray()) {
        utils.appendLine("item.push(arrayItem);");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
        utils.appendLine("  while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "'));");
    }
    utils.appendLine("newobject." + accessorName + "(item);");
    utils.appendLine("var item = null;");
    if (!itemInfo.isArray()) {
        utils.startIf("curElement != null");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
    }
    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.endBlock();
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 44 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project tomee by apache.

the class CommonsSchemaInfoBuilder method buildXmlTypeInfos.

private void buildXmlTypeInfos() {
    for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
        // Global Elements
        for (Iterator iterator = schema.getElements().getValues(); iterator.hasNext(); ) {
            XmlSchemaElement globalElement = (XmlSchemaElement) iterator.next();
            addGlobalElement(globalElement);
        }
        // Global Types
        for (Iterator iterator = schema.getSchemaTypes().getValues(); iterator.hasNext(); ) {
            XmlSchemaType globalType = (XmlSchemaType) iterator.next();
            addType(globalType.getQName(), globalType);
        }
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Iterator(java.util.Iterator) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 45 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.

the class JAXBDataBinding method validateSchema.

public void validateSchema(Element ele, String uri, final OASISCatalogManager catalog, final SchemaCollection schemaCollection) throws ToolException {
    SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schemaFact.setResourceResolver(new LSResourceResolver() {

        public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
            String s = JAXBDataBinding.mapSchemaLocation(systemId, baseURI, catalog);
            LOG.fine("validating: " + namespaceURI + " " + systemId + " " + baseURI + " " + s);
            if (s == null) {
                XmlSchema sc = schemaCollection.getSchemaByTargetNamespace(namespaceURI);
                if (sc != null) {
                    StringWriter writer = new StringWriter();
                    sc.write(writer);
                    InputSource src = new InputSource(new StringReader(writer.toString()));
                    src.setSystemId(sc.getSourceURI());
                    return new LSInputSAXWrapper(src);
                }
                throw new ToolException("Schema not found for namespace: " + namespaceURI);
            }
            return new LSInputSAXWrapper(new InputSource(s));
        }
    });
    DOMSource domSrc = new DOMSource(ele, uri);
    try {
        schemaFact.newSchema(domSrc);
    } catch (SAXException e) {
        if (e.getLocalizedMessage().indexOf("src-resolve.4.2") > -1) {
        // Ignore schema resolve error and do nothing
        } else {
            // e.printStackTrace();
            throw new ToolException("Schema Error : " + e.getLocalizedMessage(), e);
        }
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) StringWriter(java.io.StringWriter) LSResourceResolver(org.w3c.dom.ls.LSResourceResolver) XmlSchema(org.apache.ws.commons.schema.XmlSchema) LSInput(org.w3c.dom.ls.LSInput) StringReader(java.io.StringReader) LSInputSAXWrapper(com.sun.tools.xjc.reader.xmlschema.parser.LSInputSAXWrapper) ToolException(org.apache.cxf.tools.common.ToolException) SAXException(org.xml.sax.SAXException)

Aggregations

XmlSchema (org.apache.ws.commons.schema.XmlSchema)116 QName (javax.xml.namespace.QName)61 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)52 Test (org.junit.Test)49 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)37 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)32 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)18 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)17 ArrayList (java.util.ArrayList)14 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)13 Element (org.w3c.dom.Element)12 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)10 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)10 Document (org.w3c.dom.Document)10 HashMap (java.util.HashMap)9 Map (java.util.Map)8 NamespaceMap (org.apache.ws.commons.schema.utils.NamespaceMap)8 List (java.util.List)7 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)7