Search in sources :

Example 6 with XmlSchemaComplexContentRestriction

use of org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction in project hale by halestudio.

the class XmlSchemaReader method createPropertyFromElement.

/**
 * Create a property from an element
 *
 * @param element the schema element
 * @param declaringGroup the definition of the declaring group
 * @param schemaLocation the schema location
 * @param schemaNamespace the schema namespace
 */
private void createPropertyFromElement(XmlSchemaElement element, DefinitionGroup declaringGroup, String schemaLocation, String schemaNamespace) {
    if (element.getSchemaTypeName() != null) {
        // element referencing a type
        // <element name="ELEMENT_NAME" type="SCHEMA_TYPE_NAME" />
        QName elementName = element.getQName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(elementName, substitutionGroup, index.getOrCreateType(element.getSchemaTypeName()));
        // set metadata and constraints
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    } else if (element.getRefName() != null) {
        // references another element
        // <element ref="REF_NAME" />
        QName elementName = element.getRefName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        XmlElementReferenceProperty property = new XmlElementReferenceProperty(elementName, substitutionGroup, index, elementName);
        // set metadata and constraints FIXME can the constraints be set at
        // this point? or must the property determine them from the
        // SchemaElement?
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    } else if (element.getSchemaType() != null) {
        // definition
        if (element.getSchemaType() instanceof XmlSchemaComplexType) {
            // <element ...>
            // <complexType>
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) element.getSchemaType();
            XmlSchemaContentModel model = complexType.getContentModel();
            if (model != null) {
                XmlSchemaContent content = model.getContent();
                QName superTypeName = null;
                if (content instanceof XmlSchemaComplexContentExtension || content instanceof XmlSchemaComplexContentRestriction) {
                    // <complexContent>
                    // <extension base="..."> / <restriction ...>
                    String nameExt;
                    if (content instanceof XmlSchemaComplexContentExtension) {
                        superTypeName = ((XmlSchemaComplexContentExtension) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Extension";
                    } else {
                        superTypeName = ((XmlSchemaComplexContentRestriction) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Restriction";
                    }
                    if (superTypeName != null) {
                        // try to get the type definition of the super type
                        XmlTypeDefinition superType = index.getOrCreateType(superTypeName);
                        // create an anonymous type that extends the super
                        // type
                        QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
                        superTypeName.getLocalPart() + nameExt);
                        AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                        anonymousType.setSuperType(superType);
                        // set metadata and constraints
                        setMetadataAndConstraints(anonymousType, complexType, schemaLocation);
                        // add properties to the anonymous type
                        createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                        // create a property with the anonymous type
                        DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                        // set metadata and constraints
                        setMetadataAndConstraints(property, element, schemaLocation);
                    } else {
                        reporter.error(new IOMessageImpl("Could not determine super type for complex content", null, content.getLineNumber(), content.getLinePosition()));
                    }
                // </extension> / </restriction>
                // </complexContent>
                } else if (content instanceof XmlSchemaSimpleContentExtension || content instanceof XmlSchemaSimpleContentRestriction) {
                    // <simpleContent>
                    // <extension base="..."> / <restriction ...>
                    String nameExt;
                    if (content instanceof XmlSchemaSimpleContentExtension) {
                        superTypeName = ((XmlSchemaSimpleContentExtension) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Extension";
                    } else {
                        superTypeName = ((XmlSchemaSimpleContentRestriction) content).getBaseTypeName();
                        // $NON-NLS-1$
                        nameExt = "Restriction";
                    }
                    if (superTypeName != null) {
                        // try to get the type definition of the super type
                        XmlTypeDefinition superType = index.getOrCreateType(superTypeName);
                        // create an anonymous type that extends the super
                        // type
                        QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
                        superTypeName.getLocalPart() + nameExt);
                        AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                        anonymousType.setSuperType(superType);
                        // set metadata and constraints
                        setMetadata(anonymousType, complexType, schemaLocation);
                        anonymousType.setConstraint(HasValueFlag.ENABLED);
                        // set no binding, inherit it from the super type
                        // XXX is this ok?
                        // add properties to the anonymous type
                        createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                        // create a property with the anonymous type
                        DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                        // set metadata and constraints
                        setMetadataAndConstraints(property, element, schemaLocation);
                    } else {
                        reporter.error(new IOMessageImpl("Could not determine super type for simple content", null, content.getLineNumber(), content.getLinePosition()));
                    }
                // </extension>
                // </simpleContent>
                }
            } else {
                // this where we get when there is an anonymous complex type
                // as property type
                // create an anonymous type
                QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), "AnonymousType");
                // create anonymous type with no super type
                AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
                // set metadata and constraints
                setMetadataAndConstraints(anonymousType, complexType, schemaLocation);
                // add properties to the anonymous type
                createProperties(anonymousType, complexType, schemaLocation, schemaNamespace);
                // create a property with the anonymous type
                DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
                // set metadata and constraints
                setMetadataAndConstraints(property, element, schemaLocation);
            }
        // </complexType>
        // </element>
        } else if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            // simple schema type
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) element.getSchemaType();
            // create an anonymous type
            QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + element.getName(), // $NON-NLS-1$
            "AnonymousType");
            AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
            configureSimpleType(anonymousType, simpleType, schemaLocation);
            // create a property with the anonymous type
            DefaultPropertyDefinition property = new DefaultPropertyDefinition(element.getQName(), declaringGroup, anonymousType);
            // set metadata and constraints
            setMetadataAndConstraints(property, element, schemaLocation);
        }
    } else {
        // <element name="..." />
        // no type defined
        reporter.warn(new IOMessageImpl("Element definition without an associated type: {0}", null, element.getLineNumber(), element.getLinePosition(), element.getQName()));
        // assuming xsd:anyType as default type
        QName elementName = element.getQName();
        SubstitutionGroupProperty substitutionGroup = new SubstitutionGroupProperty(new QName(elementName.getNamespaceURI() + "/" + elementName.getLocalPart(), // TODO
        "choice"), // naming?
        declaringGroup);
        DefaultPropertyDefinition property = new DefaultPropertyDefinition(elementName, substitutionGroup, index.getOrCreateType(XmlTypeUtil.NAME_ANY_TYPE));
        // set metadata and constraints
        setMetadataAndConstraints(property, element, schemaLocation);
        substitutionGroup.setProperty(property);
    }
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) QName(javax.xml.namespace.QName) AnonymousXmlType(eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) XmlElementReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlElementReferenceProperty) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction) SubstitutionGroupProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.SubstitutionGroupProperty) XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 7 with XmlSchemaComplexContentRestriction

use of org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction in project hale by halestudio.

the class XmlSchemaReader method getSuperTypeName.

/**
 * Find a super type name based on a complex type
 *
 * @param item the complex type defining a super type
 * @return the name of the super type or <code>null</code>
 */
private QName getSuperTypeName(XmlSchemaComplexType item) {
    QName qname = null;
    XmlSchemaContentModel model = item.getContentModel();
    if (model != null) {
        XmlSchemaContent content = model.getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            qname = ((XmlSchemaComplexContentExtension) content).getBaseTypeName();
        } else if (content instanceof XmlSchemaComplexContentRestriction) {
            // restriction
            qname = ((XmlSchemaComplexContentRestriction) content).getBaseTypeName();
        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            qname = ((XmlSchemaSimpleContentExtension) content).getBaseTypeName();
        } else if (content instanceof XmlSchemaSimpleContentRestriction) {
            // restriction
            qname = ((XmlSchemaSimpleContentRestriction) content).getBaseTypeName();
        }
    }
    return qname;
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) QName(javax.xml.namespace.QName) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Example 8 with XmlSchemaComplexContentRestriction

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

the class CommonsSchemaInfoBuilder method extractSoapArrayComponentType.

/**
 * Extract the nested component type of an Array from the XML Schema Type.
 *
 * @return the QName of the nested component type or null if the schema type can not be determined
 * @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType
 */
private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) {
    // Soap arrays are based on complex content restriction
    if (!isSoapArray(complexType)) {
        return null;
    }
    XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType.getContentModel().getContent();
    // First, handle case that looks like this:
    // <complexType name="ArrayOfstring">
    // <complexContent>
    // <restriction base="soapenc:Array">
    // <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
    // </restriction>
    // </complexContent>
    // </complexType>
    XmlSchemaObjectCollection attributes = restriction.getAttributes();
    for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
        Object item = iterator.next();
        if (item instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
            if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) {
                for (Attr attr : attribute.getUnhandledAttributes()) {
                    QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName());
                    if (WSDL_ARRAY_TYPE.equals(attQName)) {
                        // value is a namespace prefixed xsd type
                        String value = attr.getValue();
                        // extract local part
                        int pos = value.lastIndexOf(":");
                        QName componentType;
                        if (pos < 0) {
                            componentType = new QName("", value);
                        } else {
                            String localPart = value.substring(pos + 1);
                            // resolve the namespace prefix
                            String prefix = value.substring(0, pos);
                            String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement());
                            componentType = new QName(namespace, localPart);
                        }
                        LOG.debug("determined component type from element type");
                        return componentType;
                    }
                }
            }
        }
    }
    // If that didn't work, try to handle case like this:
    // <complexType name="ArrayOfstring1">
    // <complexContent>
    // <restriction base="soapenc:Array">
    // <sequence>
    // <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
    // </sequence>
    // </restriction>
    // </complexContent>
    // </complexType>
    XmlSchemaParticle particle = restriction.getParticle();
    if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
        if (sequence.getItems().getCount() != 1) {
            throw new IllegalArgumentException("more than one element inside array definition: " + complexType);
        }
        XmlSchemaObject item = sequence.getItems().getItem(0);
        if (item instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) item;
            QName componentType = element.getSchemaTypeName();
            LOG.debug("determined component type from element type");
            return componentType;
        }
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) Attr(org.w3c.dom.Attr) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) Iterator(java.util.Iterator) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 9 with XmlSchemaComplexContentRestriction

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

the class CommonsSchemaInfoBuilder method isSoapArray.

private static boolean isSoapArray(XmlSchemaComplexType complexType) {
    // Soap arrays are based on complex content restriction
    XmlSchemaContentModel contentModel = complexType.getContentModel();
    if (contentModel == null) {
        return false;
    }
    XmlSchemaContent content = contentModel.getContent();
    if (!(content instanceof XmlSchemaComplexContentRestriction)) {
        return false;
    }
    XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
    return SOAP_ARRAY.equals(restriction.getBaseTypeName());
}
Also used : XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel)

Example 10 with XmlSchemaComplexContentRestriction

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

the class SchemaCollection method addCrossImports.

private void addCrossImports(XmlSchema schema, XmlSchemaContentModel contentModel) {
    if (contentModel == null) {
        return;
    }
    XmlSchemaContent content = contentModel.getContent();
    if (content == null) {
        return;
    }
    if (content instanceof XmlSchemaComplexContentExtension) {
        XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
        XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
        addCrossImportsAttributeList(schema, extension.getAttributes());
        XmlSchemaParticle particle = extension.getParticle();
        if (particle instanceof XmlSchemaSequence) {
            addCrossImports(schema, (XmlSchemaSequence) particle);
        } else if (particle instanceof XmlSchemaChoice) {
            addCrossImports(schema, (XmlSchemaChoice) particle);
        } else if (particle instanceof XmlSchemaAll) {
            addCrossImports(schema, (XmlSchemaAll) particle);
        }
    } else if (content instanceof XmlSchemaComplexContentRestriction) {
        XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
        XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
        addCrossImportsAttributeList(schema, restriction.getAttributes());
    } else if (content instanceof XmlSchemaSimpleContentExtension) {
        XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
        XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
        addCrossImportsAttributeList(schema, extension.getAttributes());
    } else if (content instanceof XmlSchemaSimpleContentRestriction) {
        XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
        XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
        addCrossImportsAttributeList(schema, restriction.getAttributes());
    }
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Aggregations

XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)12 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)9 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)7 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)6 XmlSchemaContent (org.apache.ws.commons.schema.XmlSchemaContent)6 QName (javax.xml.namespace.QName)5 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)5 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)5 XmlSchemaSimpleContentRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)5 XmlSchemaContentModel (org.apache.ws.commons.schema.XmlSchemaContentModel)4 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)4 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)4 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)3 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)3 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)3 XmlSchemaAll (org.apache.ws.commons.schema.XmlSchemaAll)2 XmlSchemaChoice (org.apache.ws.commons.schema.XmlSchemaChoice)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)1 ComplexContentHasValue (eu.esdihumboldt.hale.io.xsd.model.ComplexContentHasValue)1