org.apache.ws.commons.schema.XmlSchemaForm Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaForm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean getElementQualification(XmlSchemaElement element, String uri) {
    QName schemaName = element.getQName();
    if (element.isRef()) {
        schemaName = element.getRef().getTargetQName();
    }

    if (schemaName.getNamespaceURI().isEmpty()) {
        schemaName = new QName(uri, schemaName.getLocalPart());
    }
    boolean qualified = false;
    if (element.getForm() == XmlSchemaForm.QUALIFIED) {
        qualified = true;
    } else {
        qualified = WSDLUtils.isElementFormQualified(xmlSchemaList, schemaName);
    }
    return qualified;
}
 
Example #2
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SchemaInfo createSchemaIfNeeded(String namespace, NamespaceMap nsMap) {
    SchemaInfo schemaInfo = serviceInfo.getSchema(namespace);
    if (schemaInfo == null) {
        XmlSchema xmlSchema = schemas.newXmlSchemaInCollection(namespace);

        if (qualifiedSchemas) {
            xmlSchema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
        }

        xmlSchema.setNamespaceContext(nsMap);

        schemaInfo = new SchemaInfo(namespace);
        schemaInfo.setSchema(xmlSchema);
        serviceInfo.addSchema(schemaInfo);
    }
    return schemaInfo;
}
 
Example #3
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isSchemaFormQualified(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = schemaCol.getSchemaForElement(partElement);
    if (schema != null) {
        return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
    }
    return false;

}
 
Example #4
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isElementNameQualified(XmlSchemaElement element, XmlSchema schema) {
    if (element.isRef()) {
        throw new RuntimeException("isElementNameQualified on element with ref=");
    }
    if (element.getForm().equals(XmlSchemaForm.QUALIFIED)) {
        return true;
    }
    if (element.getForm().equals(XmlSchemaForm.UNQUALIFIED)) {
        return false;
    }
    return schema.getElementFormDefault().equals(XmlSchemaForm.QUALIFIED);
}
 
Example #5
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isAttributeNameQualified(XmlSchemaAttribute attribute, XmlSchema schema) {
    if (attribute.isRef()) {
        throw new RuntimeException("isElementNameQualified on element with ref=");
    }
    if (attribute.getForm().equals(XmlSchemaForm.QUALIFIED)) {
        return true;
    }
    if (attribute.getForm().equals(XmlSchemaForm.UNQUALIFIED)) {
        return false;
    }
    return schema.getAttributeFormDefault().equals(XmlSchemaForm.QUALIFIED);
}
 
Example #6
Source File: CorbaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static boolean isAttributeFormQualified(XmlSchema schema, String uri) {
    if (uri.equals(schema.getTargetNamespace())) {
        return schema.getAttributeFormDefault() == XmlSchemaForm.QUALIFIED;
    }
    for (XmlSchemaExternal extSchema : schema.getExternals()) {
        return isAttributeFormQualified(extSchema.getSchema(), uri);
    }
    return false;
}
 
Example #7
Source File: CorbaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static boolean isElementFormQualified(XmlSchema schema, String uri) {
    if (uri.equals(schema.getTargetNamespace())) {
        return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
    }
    for (XmlSchemaExternal extSchema : schema.getExternals()) {
        return isElementFormQualified(extSchema.getSchema(), uri);
    }
    return false;
}
 
Example #8
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) {
    XmlSchemaElement el = null;
    SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI());
    if (schemaInfo != null) {
        el = schemaInfo.getElementByQName(qn);
        if (el == null) {
            createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo);

        } else if (!typeName.equals(el.getSchemaTypeName())) {
            throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG,
                                        qn, typeName, el.getSchemaTypeName()));
        }
        return;
    }

    XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI());
    if (qualifiedSchemas) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false);
    schemaInfo.setSchema(schema);

    el = createXsElement(schema, part, typeName, schemaInfo);

    NamespaceMap nsMap = new NamespaceMap();
    nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace());
    nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    schema.setNamespaceContext(nsMap);

    serviceInfo.addSchema(schemaInfo);
}
 
Example #9
Source File: BindingHelper.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public String getSpecification() throws ParserException {

        // add a SOAP schema to hold wrapper elements, to be removed by soap connector
        final SchemaCollection targetSchemas = new SchemaCollection();
        final XmlSchema soapSchema = targetSchemas.newXmlSchemaInCollection(soapVersion.getEnvelope().getNamespaceURI());
        soapSchema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
        soapSchema.setAttributeFormDefault(XmlSchemaForm.QUALIFIED);

        // extract elements/types from source schema using an XmlSchemaExtractor
        final XmlSchemaExtractor schemaExtractor = new XmlSchemaExtractor(targetSchemas, schemaCollection);

        // TODO also handle faults for output message, which requires an enhancement in Syndesis

        if (style == Style.RPC) {
            final OperationInfo operationInfo = bindingOperation.getOperationInfo();
            final QName operationName = operationInfo.getName();
            final QName wrapperElement = bindingMessageInfo.getMessageInfo().getType() == MessageInfo.Type.INPUT ?
                operationName : new QName(operationName.getNamespaceURI(), operationName.getLocalPart() + "Response");

            createRpcEnvelope(schemaExtractor, wrapperElement);
        } else {
            final List<XmlSchemaElement> bodyElements = getPartElements(schemaExtractor, soapSchema, bodyParts);

            // if topLevel is true, root element was already added to generated schema as top level element
            final List<XmlSchemaElement> headerElements = hasHeaders ? getPartElements(schemaExtractor, soapSchema,
                headerParts) : null;
            createDocumentEnvelope(schemaExtractor, headerElements, bodyElements);
        }

        return getSpecificationString(schemaExtractor);
    }
 
Example #10
Source File: WSDLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isElementFormQualified(XmlSchema schema, QName type) {
    if (type != null) {
        String uri = type.getNamespaceURI();
        if (uri.equals(schema.getTargetNamespace())) {
            return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
        }
        for (XmlSchemaExternal extSchema : schema.getExternals()) {
            return isElementFormQualified(extSchema.getSchema(), type);
        }
    }
    return false;
}
 
Example #11
Source File: WSDLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isElementFormQualified(SchemaCollection schemas, QName type) {
    if (type != null) {
        XmlSchema sch = schemas.getSchemaByTargetNamespace(type.getNamespaceURI());
        if (sch != null) {
            return sch.getElementFormDefault()  == XmlSchemaForm.QUALIFIED;
        }
    }
    return false;
}
 
Example #12
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean getAttributeQualification(XmlSchemaAttribute attr, String uri) {
    QName schemaName = attr.getQName();

    boolean qualified = false;
    if (attr.getForm() == XmlSchemaForm.QUALIFIED) {
        qualified = true;
    } else {
        qualified = WSDLUtils.isElementFormQualified(xmlSchemaList, schemaName);
    }
    return qualified;
}
 
Example #13
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void setQualified(boolean qualified) throws Exception  {
    if (qualified) {
        XmlSchemaForm form = XmlSchemaForm.QUALIFIED;
        schema.setAttributeFormDefault(form);
        schema.setElementFormDefault(form);
    }
}
 
Example #14
Source File: AbstractXsdEmitterTester.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @return an empty XML schema for testing
 */
public XmlSchema getXmlSchema() {
    XmlSchema xsd = new XmlSchema("http://legstar.com/test",
            new XmlSchemaCollection());
    xsd.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    return xsd;
}
 
Example #15
Source File: Cob2Xsd.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an empty XML Schema.
 * <p/>
 * If no targetNamespace, make sure there is no default namespace otherwise
 * our complex types would be considered part of that default namespace
 * (usually XML Schema namespace).
 * 
 * @param encoding the character set used to encode this XML Schema
 * @param targetNamespace the target namespace to use (null for no namespace)
 * @return a new empty XML schema using the model
 */
protected XmlSchema createXmlSchema(final String encoding, final String targetNamespace) {
    XmlSchema xsd = new XmlSchema(targetNamespace,
            new XmlSchemaCollection());
    if (targetNamespace != null) {
        xsd.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    xsd.setAttributeFormDefault(null);
    xsd.setInputEncoding(encoding);
    if (targetNamespace == null) {
        NamespaceMap prefixmap = new NamespaceMap();
        NamespacePrefixList npl = xsd.getNamespaceContext();
        if (npl == null) {
            prefixmap.add("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI);
        } else {
            for (int i = 0; i < npl.getDeclaredPrefixes().length; i++) {
                String prefix = npl.getDeclaredPrefixes()[i];
                String namespace = npl.getNamespaceURI(prefix);
                if (namespace.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                    if (prefix.equals("")) {
                        prefix = "xsd";
                    }
                }
                prefixmap.add(prefix, namespace);
            }
        }
        xsd.setNamespaceContext(prefixmap);
    }
    return xsd;
}
 
Example #16
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo, String namespaceURI, boolean qualified) {
    for (SchemaInfo s : serviceInfo.getSchemas()) {
        if (s.getNamespaceURI().equals(namespaceURI)) {
            return s;
        }
    }

    SchemaInfo schemaInfo = new SchemaInfo(namespaceURI);
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = col.getSchemaByTargetNamespace(namespaceURI);

    if (schema != null) {
        schemaInfo.setSchema(schema);
        serviceInfo.addSchema(schemaInfo);
        return schemaInfo;
    }

    schema = col.newXmlSchemaInCollection(namespaceURI);
    if (qualified) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo.setSchema(schema);

    Map<String, String> explicitNamespaceMappings = this.getDataBinding().getDeclaredNamespaceMappings();
    if (explicitNamespaceMappings == null) {
        explicitNamespaceMappings = Collections.emptyMap();
    }
    NamespaceMap nsMap = new NamespaceMap();
    for (Map.Entry<String, String> mapping : explicitNamespaceMappings.entrySet()) {
        nsMap.add(mapping.getValue(), mapping.getKey());
    }

    if (!explicitNamespaceMappings.containsKey(WSDLConstants.NS_SCHEMA_XSD)) {
        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    }
    if (!explicitNamespaceMappings.containsKey(serviceInfo.getTargetNamespace())) {
        nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, serviceInfo.getTargetNamespace());
    }
    schema.setNamespaceContext(nsMap);
    serviceInfo.addSchema(schemaInfo);
    return schemaInfo;
}
 
Example #17
Source File: SchemaInfo.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setSchema(XmlSchema schema) {
    this.schema = schema;
    isElementQualified = schema.getElementFormDefault().equals(XmlSchemaForm.QUALIFIED);
    isAttributeQualified = schema.getAttributeFormDefault().equals(XmlSchemaForm.QUALIFIED);
}