Search in sources :

Example 1 with LocalComplexType

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

the class JAXBFeatureTypeReader method elementToAttribute.

private PropertyType elementToAttribute(final String namespaceURI, Element element, BuildStack stack) {
    GenericName name = null;
    final QName refName = element.getRef();
    PropertyType refType = null;
    if (refName != null) {
        final Element parentElement = xsdContext.findGlobalElement(refName);
        if (parentElement == null) {
            throw new MismatchedFeatureException("unable to find referenced element : " + refName);
        }
        refType = elementToAttribute(namespaceURI, parentElement, stack);
        name = NamesExt.create(refName);
    }
    // extract name
    String localName = element.getName();
    if (localName == null) {
        localName = element.getId();
    }
    if (localName != null) {
        // override name
        name = NamesExt.create(namespaceURI, localName);
    }
    // extract min/max
    final Integer[] minMax = getMinMax(element);
    if (minMax[0] == null)
        minMax[0] = 1;
    if (minMax[1] == null)
        minMax[1] = 1;
    final QName typeName = element.getType();
    if (typeName != null) {
        PropertyType parentType = resolveType(typeName, stack);
        if (element instanceof TopLevelElement && parentType instanceof FeatureAssociationRole) {
            final Object sct = getType(typeName, stack);
            if (sct instanceof FeatureType) {
                FeatureType type = new FeatureTypeBuilder().setSuperTypes((FeatureType) sct).setName(name).build();
                parentType = new FeatureTypeBuilder().addAssociation(type).setName(name).build();
            }
        }
        return reDefine(parentType, name, minMax[0], minMax[1], element.isNillable());
    }
    if (refType != null) {
        return reDefine(refType, name, minMax[0], minMax[1], element.isNillable());
    }
    final LocalSimpleType simpleType = element.getSimpleType();
    if (simpleType != null) {
        final PropertyType restrictionType = toProperty(simpleType, stack);
        return reDefine(restrictionType, name, minMax[0], minMax[1], element.isNillable());
    }
    final LocalComplexType complexType = element.getComplexType();
    if (complexType != null) {
        final FeatureTypeBuilder ftb = new FeatureTypeBuilder((FeatureType) getType(namespaceURI, complexType, stack, false));
        ftb.setName(name);
        if (element.isNillable()) {
            ftb.addAttribute(GMLConvention.NILLABLE_CHARACTERISTIC);
        }
        return new DefaultAssociationRole(Collections.singletonMap("name", name), ftb.build(), minMax[0], minMax[1]);
    }
    if (element.isAbstract()) {
        // create an abstract feature type with nothing in it
        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
        ftb.setName(name);
        ftb.setAbstract(true);
        if (element.isNillable()) {
            ftb.addAttribute(GMLConvention.NILLABLE_CHARACTERISTIC);
        }
        return new DefaultAssociationRole(Collections.singletonMap("name", name), ftb.build(), minMax[0], minMax[1]);
    } else {
        throw new UnsupportedOperationException("No type defined for " + element);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) QName(javax.xml.namespace.QName) Element(org.geotoolkit.xsd.xml.v2001.Element) JAXBElement(javax.xml.bind.JAXBElement) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) PropertyType(org.opengis.feature.PropertyType) GenericName(org.opengis.util.GenericName) DefaultAssociationRole(org.apache.sis.feature.DefaultAssociationRole) LocalSimpleType(org.geotoolkit.xsd.xml.v2001.LocalSimpleType) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) LocalComplexType(org.geotoolkit.xsd.xml.v2001.LocalComplexType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 DefaultAssociationRole (org.apache.sis.feature.DefaultAssociationRole)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 Element (org.geotoolkit.xsd.xml.v2001.Element)1 LocalComplexType (org.geotoolkit.xsd.xml.v2001.LocalComplexType)1 LocalSimpleType (org.geotoolkit.xsd.xml.v2001.LocalSimpleType)1 TopLevelElement (org.geotoolkit.xsd.xml.v2001.TopLevelElement)1 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)1 FeatureType (org.opengis.feature.FeatureType)1 MismatchedFeatureException (org.opengis.feature.MismatchedFeatureException)1 PropertyType (org.opengis.feature.PropertyType)1 GenericName (org.opengis.util.GenericName)1