Search in sources :

Example 6 with ComplexType

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

the class JAXBFeatureTypeReader method getType.

/**
 * @param qname
 * @param stack
 * @return FeatureType or GenericName
 * @throws MismatchedFeatureException
 */
private Object getType(QName qname, BuildStack stack) throws MismatchedFeatureException {
    final ComplexType type = xsdContext.findComplexType(qname);
    if (type == null) {
        // search for an element with this name
        final Element element = xsdContext.findGlobalElement(qname);
        if (element != null) {
            return elementToAttribute(qname.getNamespaceURI(), element, stack);
        }
    }
    if (type == null) {
        throw new MismatchedFeatureException("Unable to find complex type for name : " + qname);
    }
    final GenericName name = extractFinalName(qname.getNamespaceURI(), type);
    if (typesCache.containsKey(name)) {
        return typesCache.get(name);
    }
    if (stack.contains(name)) {
        // recursive build
        return name;
    }
    stack.add(name);
    return getType(qname.getNamespaceURI(), type, stack, true);
}
Also used : GenericName(org.opengis.util.GenericName) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) Element(org.geotoolkit.xsd.xml.v2001.Element) JAXBElement(javax.xml.bind.JAXBElement) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) LocalComplexType(org.geotoolkit.xsd.xml.v2001.LocalComplexType) ComplexType(org.geotoolkit.xsd.xml.v2001.ComplexType)

Example 7 with ComplexType

use of org.geotoolkit.xsd.xml.v2001.ComplexType 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)

Aggregations

QName (javax.xml.namespace.QName)5 LocalComplexType (org.geotoolkit.xsd.xml.v2001.LocalComplexType)5 FeatureType (org.opengis.feature.FeatureType)5 ComplexType (org.geotoolkit.xsd.xml.v2001.ComplexType)4 TopLevelElement (org.geotoolkit.xsd.xml.v2001.TopLevelElement)4 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)4 GenericName (org.opengis.util.GenericName)4 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 MismatchedFeatureException (org.opengis.feature.MismatchedFeatureException)3 JAXBElement (javax.xml.bind.JAXBElement)2 Element (org.geotoolkit.xsd.xml.v2001.Element)2 ExplicitGroup (org.geotoolkit.xsd.xml.v2001.ExplicitGroup)2 AttributeType (org.opengis.feature.AttributeType)2 PropertyType (org.opengis.feature.PropertyType)2 ComplexType (io.atlasmap.v2.ComplexType)1 Field (io.atlasmap.v2.Field)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DefaultAssociationRole (org.apache.sis.feature.DefaultAssociationRole)1