Search in sources :

Example 1 with TopLevelComplexType

use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType in project geotoolkit by Geomatys.

the class JAXBFeatureTypeWriter method fillSchemaWithFeatureType.

private void fillSchemaWithFeatureType(final FeatureType featureType, final Schema schema, boolean addTopElement, Set<String> alreadyWritten) {
    if (Utils.GML_FEATURE_TYPES.contains(featureType.getName())) {
        // this type is part of the standard GML types
        return;
    }
    // write parent types
    for (FeatureType parent : featureType.getSuperTypes()) {
        fillSchemaWithFeatureType(parent, schema, false, alreadyWritten);
    }
    final String typeNamespace = NamesExt.getNamespace(featureType.getName());
    final String elementName = featureType.getName().tip().toString();
    final String typeName = elementName + "Type";
    if (addTopElement) {
        final TopLevelElement topElement;
        if ("3.2.1".equals(gmlVersion)) {
            topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_321);
        } else {
            topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_311);
        }
        schema.addElement(topElement);
    }
    boolean ar = alreadyWritten.add(typeName);
    final ExplicitGroup sequence = new ExplicitGroup();
    final List<Attribute> attributes = new ArrayList<>();
    for (final PropertyType pdesc : featureType.getProperties(false)) {
        if (AttributeConvention.contains(pdesc.getName())) {
            // skip convention properties
            continue;
        }
        writeProperty(pdesc, sequence, schema, attributes, alreadyWritten);
    }
    if (addTopElement && ar) {
        final ComplexContent content = getComplexContent(sequence);
        final TopLevelComplexType tlcType = new TopLevelComplexType(typeName, content);
        tlcType.getAttributeOrAttributeGroup().addAll(attributes);
        schema.addComplexType(1, tlcType);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) Attribute(org.geotoolkit.xsd.xml.v2001.Attribute) TopLevelComplexType(org.geotoolkit.xsd.xml.v2001.TopLevelComplexType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PropertyType(org.opengis.feature.PropertyType) ComplexContent(org.geotoolkit.xsd.xml.v2001.ComplexContent) ExplicitGroup(org.geotoolkit.xsd.xml.v2001.ExplicitGroup)

Example 2 with TopLevelComplexType

use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType in project geotoolkit by Geomatys.

the class JAXBFeatureTypeWriter method writeProperty.

private void writeProperty(final PropertyType pType, final ExplicitGroup sequence, final Schema schema, final List<Attribute> attributes, final Set<String> alreadyWritten) {
    if (pType instanceof Operation) {
        // operation types are not written in the xsd.
        return;
    }
    final boolean decorated = GMLConvention.isDecoratedProperty(pType);
    if (pType instanceof AttributeType) {
        final AttributeType attType = (AttributeType) pType;
        final String name = attType.getName().tip().toString();
        final QName type = Utils.getQNameFromType(attType, gmlVersion);
        final int minOccurs = attType.getMinimumOccurs();
        final int maxOccurs = attType.getMaximumOccurs();
        final boolean nillable = FeatureExt.getCharacteristicValue(attType, GMLConvention.NILLABLE_PROPERTY.toString(), minOccurs == 0);
        final String maxOcc;
        if (maxOccurs == Integer.MAX_VALUE) {
            maxOcc = "unbounded";
        } else {
            maxOcc = Integer.toString(maxOccurs);
        }
        if (AttributeConvention.contains(attType.getName())) {
            Attribute att = new Attribute();
            att.setName(name);
            att.setType(type);
            if (minOccurs == 0) {
                att.setUse("optional");
            } else {
                att.setUse("required");
            }
            attributes.add(att);
        } else {
            if (decorated) {
                final QName decorationTypeName = GMLConvention.getDecorationTypeName(gmlVersion, pType);
                final String namespace = decorationTypeName.getNamespaceURI();
                if (!GMLConvention.isGmlNamespace(namespace)) {
                    // create a new separate type, how ?
                    throw new UnsupportedOperationException("Not supported yet.");
                }
                sequence.addElement(new LocalElement(name, decorationTypeName, minOccurs, maxOcc, nillable));
            } else {
                sequence.addElement(new LocalElement(name, type, minOccurs, maxOcc, nillable));
            }
        }
    } else if (pType instanceof FeatureAssociationRole) {
        final FeatureAssociationRole role = (FeatureAssociationRole) pType;
        final FeatureType valueType = role.getValueType();
        final String name = role.getName().tip().toString();
        final int minOccurs = role.getMinimumOccurs();
        final int maxOccurs = role.getMaximumOccurs();
        final String maxOcc;
        if (maxOccurs == Integer.MAX_VALUE) {
            maxOcc = "unbounded";
        } else {
            maxOcc = Integer.toString(maxOccurs);
        }
        if (decorated) {
            // for a complexType we have to add 2 complexType (PropertyType and type)
            final String typeName = Utils.getNameWithoutTypeSuffix(valueType.getName().tip().toString());
            final String propertyName = Utils.getNameWithPropertyTypeSuffix(typeName);
            final QName proptype = new QName(schema.getTargetNamespace(), propertyName);
            final String nameWithSuffix = propertyName;
            // search if this type has already been written
            if (!alreadyWritten.contains(nameWithSuffix)) {
                alreadyWritten.add(nameWithSuffix);
                final QName type = Utils.getQNameFromType(role, gmlVersion);
                // property type
                // <xsd:element name="Address" type="gml:AddressType" xmlns:gml="http://www.opengis.net/gml" nillable="false" minOccurs="1" maxOccurs="1" />
                final ExplicitGroup exp = new ExplicitGroup();
                final TopLevelComplexType tlcType = new TopLevelComplexType(propertyName, exp);
                final LocalElement le = new LocalElement(typeName, type, 1, "1", Boolean.FALSE);
                le.setType(Utils.getQNameFromType(valueType, gmlVersion));
                exp.addElement(le);
                schema.addComplexType(tlcType);
            }
            // attribute type
            final boolean nillable = FeatureExt.getCharacteristicValue(role, GMLConvention.NILLABLE_PROPERTY.toString(), minOccurs == 0);
            sequence.addElement(new LocalElement(name, proptype, minOccurs, maxOcc, nillable));
        } else {
            final QName type = Utils.getQNameFromType(valueType, gmlVersion);
            final boolean nillable = FeatureExt.getCharacteristicValue(role, GMLConvention.NILLABLE_PROPERTY.toString(), false);
            sequence.addElement(new LocalElement(name, type, minOccurs, maxOcc, nillable));
        }
        // real type
        writeComplexType(role.getValueType(), schema, alreadyWritten);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) Attribute(org.geotoolkit.xsd.xml.v2001.Attribute) QName(javax.xml.namespace.QName) LocalElement(org.geotoolkit.xsd.xml.v2001.LocalElement) Operation(org.opengis.feature.Operation) ExplicitGroup(org.geotoolkit.xsd.xml.v2001.ExplicitGroup) TopLevelComplexType(org.geotoolkit.xsd.xml.v2001.TopLevelComplexType) AttributeType(org.opengis.feature.AttributeType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 3 with TopLevelComplexType

use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType in project geotoolkit by Geomatys.

the class JAXBFeatureTypeWriter method writeComplexType.

private void writeComplexType(final FeatureType ctype, final Schema schema, Set<String> alreadyWritten) {
    final GenericName ptypeName = ctype.getName();
    // PropertyType
    final String nameWithSuffix = Utils.getNameWithTypeSuffix(ptypeName.tip().toString());
    boolean write = schema.getTargetNamespace().equals(NamesExt.getNamespace(ptypeName));
    // search if this type has already been written
    if (alreadyWritten.contains(nameWithSuffix)) {
        return;
    }
    alreadyWritten.add(nameWithSuffix);
    // complex type
    final ExplicitGroup sequence = new ExplicitGroup();
    final TopLevelComplexType tlcType = new TopLevelComplexType(nameWithSuffix, sequence);
    if (write) {
        schema.addComplexType(tlcType);
    }
    final List<Attribute> attributes = new ArrayList<>();
    for (final PropertyType pdesc : ctype.getProperties(true)) {
        writeProperty(pdesc, sequence, schema, attributes, alreadyWritten);
    }
    tlcType.getAttributeOrAttributeGroup().addAll(attributes);
}
Also used : GenericName(org.opengis.util.GenericName) TopLevelComplexType(org.geotoolkit.xsd.xml.v2001.TopLevelComplexType) Attribute(org.geotoolkit.xsd.xml.v2001.Attribute) ArrayList(java.util.ArrayList) PropertyType(org.opengis.feature.PropertyType) ExplicitGroup(org.geotoolkit.xsd.xml.v2001.ExplicitGroup)

Aggregations

Attribute (org.geotoolkit.xsd.xml.v2001.Attribute)3 ExplicitGroup (org.geotoolkit.xsd.xml.v2001.ExplicitGroup)3 TopLevelComplexType (org.geotoolkit.xsd.xml.v2001.TopLevelComplexType)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 FeatureType (org.opengis.feature.FeatureType)2 PropertyType (org.opengis.feature.PropertyType)2 ComplexContent (org.geotoolkit.xsd.xml.v2001.ComplexContent)1 LocalElement (org.geotoolkit.xsd.xml.v2001.LocalElement)1 TopLevelElement (org.geotoolkit.xsd.xml.v2001.TopLevelElement)1 AttributeType (org.opengis.feature.AttributeType)1 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)1 Operation (org.opengis.feature.Operation)1 GenericName (org.opengis.util.GenericName)1