Search in sources :

Example 71 with XmlSchemaComplexType

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

the class XmlSchemaReader method createProperties.

/**
 * Create the properties for the given complex type
 *
 * @param typeDef the definition of the declaring type
 * @param item the complex type item
 * @param schemaLocation the schema location
 * @param schemaNamespace the scheme namspace
 */
private void createProperties(XmlTypeDefinition typeDef, XmlSchemaComplexType item, String schemaLocation, String schemaNamespace) {
    // item:
    // <complexType ...>
    XmlSchemaContentModel model = item.getContentModel();
    if (model != null) {
        XmlSchemaContent content = model.getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            // <complexContent>
            // <extension base="...">
            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
            // particle (e.g. sequence)
            if (extension.getParticle() != null) {
                XmlSchemaParticle particle = extension.getParticle();
                createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
            }
            // attributes
            XmlSchemaObjectCollection attributeCollection = extension.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
            // complex content may have a value in certain cases
            // (if it is mixed it definitely has, which will override this
            // setting)
            typeDef.setConstraintIfNotSet(new ComplexContentHasValue(typeDef));
        // </extension>
        // </complexContent>
        } else if (content instanceof XmlSchemaComplexContentRestriction) {
            // <complexContent>
            // <restriction base="...">
            XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
            // particle (e.g. sequence)
            if (restriction.getParticle() != null) {
                XmlSchemaParticle particle = restriction.getParticle();
                createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
            }
            // attributes
            XmlSchemaObjectCollection attributeCollection = restriction.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
            // complex content does not have a value
            // (only if it is mixed, which can override this setting)
            typeDef.setConstraintIfNotSet(HasValueFlag.DISABLED);
        // </restriction>
        // </complexContent>
        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            // <simpleContent>
            // <extension base="...">
            XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
            // attributes
            XmlSchemaObjectCollection attributeCollection = extension.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
        // </extension>
        // </simpleContent>
        } else if (content instanceof XmlSchemaSimpleContentRestriction) {
            // <simpleContent>
            // <restriction base="...">
            XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
            // attributes
            XmlSchemaObjectCollection attributeCollection = restriction.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
        // </restriction>
        // </simpleContent>
        }
    } else {
        // no complex content (instead e.g. <sequence>)
        XmlSchemaComplexType complexType = item;
        // particle (e.g. sequence)
        if (item.getParticle() != null) {
            XmlSchemaParticle particle = complexType.getParticle();
            createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
        }
        // attributes
        XmlSchemaObjectCollection attributeCollection = complexType.getAttributes();
        if (attributeCollection != null) {
            createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
        }
    }
// </complexType>
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) ComplexContentHasValue(eu.esdihumboldt.hale.io.xsd.model.ComplexContentHasValue) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Example 72 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType 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 73 with XmlSchemaComplexType

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

the class CommonsSchemaInfoBuilder method createXmlTypeInfo.

public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
    if (qname == null)
        throw new NullPointerException("qname is null");
    if (type == null)
        throw new NullPointerException("type is null");
    XmlTypeInfo typeInfo = new XmlTypeInfo();
    typeInfo.qname = qname;
    typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;
    if (type instanceof XmlSchemaSimpleType) {
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            typeInfo.simpleBaseType = list.getItemType().getQName();
            // this is a list
            typeInfo.listType = true;
        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            typeInfo.simpleBaseType = restriction.getBaseTypeName();
            // is this an enumeration?
            for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
                if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
                    typeInfo.enumType = true;
                    break;
                }
            }
        }
    } else if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
        // SOAP array component type
        typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);
        // process attributes (skip soap arrays which have non-mappable attributes)
        if (!isSoapArray(complexType)) {
            XmlSchemaObjectCollection attributes = complexType.getAttributes();
            for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
                Object item = iterator.next();
                if (item instanceof XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
                    Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
                    if (old != null) {
                        throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
                    }
                }
            }
        }
    } else {
        LOG.warn("Unknown schema type class " + typeInfo.getClass().getName());
    }
    return typeInfo;
}
Also used : XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaSimpleTypeContent(org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Iterator(java.util.Iterator) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaEnumerationFacet(org.apache.ws.commons.schema.XmlSchemaEnumerationFacet) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 74 with XmlSchemaComplexType

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

the class CommonsSchemaInfoBuilder method addType.

private void addType(QName typeQName, XmlSchemaType type) {
    // skip built in xml schema types
    if (XML_SCHEMA_NS.equals(typeQName.getNamespaceURI())) {
        return;
    }
    XmlTypeInfo typeInfo = createXmlTypeInfo(typeQName, type);
    xmlTypes.put(typeQName, typeInfo);
    if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
        // process elements nested inside of this element
        List<XmlSchemaElement> elements = getNestedElements(complexType);
        for (XmlSchemaElement element : elements) {
            addNestedElement(element, typeInfo);
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 75 with XmlSchemaComplexType

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

the class JAXBSchemaInitializer method buildGenericElements.

private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Field f) {
    XmlSchemaComplexType generics = new XmlSchemaComplexType(schema, true);
    Type type = f.getGenericType();
    String rawType = ((ParameterizedType) type).getRawType().toString();
    String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
    generics.setName(typeName);
    Class<?> genericsClass = f.getType();
    buildGenericSeq(schema, generics, genericsClass);
    String name = Character.toLowerCase(f.getName().charAt(0)) + f.getName().substring(1);
    XmlSchemaElement newel = new XmlSchemaElement(schema, false);
    newel.setName(name);
    newel.setSchemaTypeName(generics.getQName());
    newel.setMinOccurs(0);
    if (!seq.getItems().contains(newel)) {
        seq.getItems().add(newel);
    }
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) Type(java.lang.reflect.Type) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlType(javax.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)136 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)101 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)71 QName (javax.xml.namespace.QName)59 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)33 XmlSchema (org.apache.ws.commons.schema.XmlSchema)32 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)31 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)23 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)20 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)18 Test (org.junit.Test)18 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)16 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)15 ArrayList (java.util.ArrayList)13 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)12 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)12 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)12 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)8 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8