Search in sources :

Example 1 with OpenAttrs

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

the class JAXBFeatureTypeReader method listFeatureTypes.

private void listFeatureTypes(Schema schema, GenericNameIndex<FeatureType> result) throws MismatchedFeatureException, IllegalNameException {
    // then we look for feature type and groups
    for (OpenAttrs opAtts : schema.getSimpleTypeOrComplexTypeOrGroup()) {
        if (opAtts instanceof TopLevelElement) {
            final TopLevelElement element = (TopLevelElement) opAtts;
            final QName typeName = element.getType();
            if (typeName != null) {
                final ComplexType type = xsdContext.findComplexType(typeName);
                if (type == null && xsdContext.findSimpleType(typeName) == null) {
                    LOGGER.log(Level.WARNING, "Unable to find a the declaration of type {0} in schemas.", typeName.getLocalPart());
                    continue;
                }
                // if (xsdContext.isFeatureType(type)) {
                final BuildStack stack = new BuildStack();
                Object typeObj = getType(typeName.getNamespaceURI(), type, stack, true);
                FeatureType ft = null;
                if (typeObj instanceof FeatureAssociationRole) {
                    ft = ((FeatureAssociationRole) typeObj).getValueType();
                } else if (typeObj instanceof FeatureType) {
                    ft = (FeatureType) typeObj;
                }
                if (ft != null) {
                    addIfMissing(result, ft);
                    // if the type name is not the same as the element name, make a subtype
                    if (!ft.getName().tip().toString().equals(element.getName())) {
                        final GenericName name = NamesExt.create(NamesExt.getNamespace(ft.getName()), element.getName());
                        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
                        ftb.setName(name);
                        ftb.setSuperTypes(ft);
                        final FeatureType renamed = ftb.build();
                        addIfMissing(result, renamed);
                    }
                }
            // }
            } else {
                LOGGER.log(Level.WARNING, "null typeName for element : {0}", element.getName());
            }
        }
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GenericName(org.opengis.util.GenericName) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) QName(javax.xml.namespace.QName) LocalComplexType(org.geotoolkit.xsd.xml.v2001.LocalComplexType) ComplexType(org.geotoolkit.xsd.xml.v2001.ComplexType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole) OpenAttrs(org.geotoolkit.xsd.xml.v2001.OpenAttrs)

Example 2 with OpenAttrs

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

the class XSDSchemaContext method findGlobalElement.

public Element findGlobalElement(final QName typeName) {
    Element element = null;
    final Iterator<Schema> schemas = getForNamespace(typeName.getNamespaceURI()).iterator();
    // look in the schemas
    while (schemas.hasNext()) {
        final Schema schema = schemas.next();
        for (OpenAttrs att : schema.getSimpleTypeOrComplexTypeOrGroup()) {
            if (att instanceof Element) {
                final TopLevelElement candidate = (TopLevelElement) att;
                if (candidate.getName().equals(typeName.getLocalPart())) {
                    // check if it's a deprecated type, we will return it only in last case
                    if (GMLConvention.isDeprecated(candidate)) {
                        element = candidate;
                    } else {
                        // found it
                        return candidate;
                    }
                }
            }
        }
    }
    return element;
}
Also used : TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) Element(org.geotoolkit.xsd.xml.v2001.Element) JAXBElement(javax.xml.bind.JAXBElement) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) Schema(org.geotoolkit.xsd.xml.v2001.Schema) OpenAttrs(org.geotoolkit.xsd.xml.v2001.OpenAttrs)

Example 3 with OpenAttrs

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

the class XSDSchemaContext method fillAllSubstitution.

/**
 * list all elements and complexe types and put them in the allCache map.
 * Do not parse them yet.
 */
private void fillAllSubstitution(Schema schema) {
    for (OpenAttrs att : schema.getSimpleTypeOrComplexTypeOrGroup()) {
        if (att instanceof TopLevelElement) {
            final TopLevelElement ele = (TopLevelElement) att;
            final QName parent = ele.getSubstitutionGroup();
            if (parent != null) {
                Set<QName> subList = substitutionGroups.get(parent);
                if (subList == null) {
                    subList = new HashSet<>();
                    substitutionGroups.put(parent, subList);
                }
                final QName name = new QName(schema.getTargetNamespace(), ele.getName());
                if (subList.contains(name)) {
                    // name already here, check if one of them is deprecated
                    subList.add(name);
                } else {
                    subList.add(name);
                }
            }
        }
    }
}
Also used : TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) QName(javax.xml.namespace.QName) OpenAttrs(org.geotoolkit.xsd.xml.v2001.OpenAttrs)

Example 4 with OpenAttrs

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

the class XSDSchemaContext method listAllSchemas.

/**
 * TODO : Mechanism of schema discovery is messy. The interdependance with
 * its current state is far too strong, and its use is also strongly
 * dependant with {@link JAXBFeatureTypeReader}.
 */
public void listAllSchemas(final Schema schema, final String baseLocation, List<Map.Entry<Schema, String>> refs) throws MismatchedFeatureException {
    fillAllSubstitution(schema);
    for (OpenAttrs attr : schema.getIncludeOrImportOrRedefine()) {
        if (attr instanceof Import || attr instanceof Include) {
            final String schemalocation = Utils.getIncludedLocation(baseLocation, attr);
            if (schemalocation != null && !locatedSchemas.containsKey(schemalocation)) {
                // check for a relocation
                final String relocation = locationMap.get(schemalocation);
                final String finalLocation = (relocation == null) ? schemalocation : relocation;
                Schema importedSchema = null;
                try {
                    importedSchema = SCHEMA_CACHE.getOrCreate(finalLocation, new Callable() {

                        public Schema call() {
                            Schema schema = Utils.getDistantSchema(finalLocation);
                            schema.getOtherAttributes().put(new QName("__location"), finalLocation);
                            return schema;
                        }
                    });
                } catch (Exception ex) {
                    throw new MismatchedFeatureException(ex.getMessage(), ex);
                }
                if (importedSchema != null) {
                    locatedSchemas.put(schemalocation, importedSchema);
                    final String newBaseLocation = getNewBaseLocation(schemalocation, baseLocation);
                    refs.add(new AbstractMap.SimpleEntry<>(importedSchema, newBaseLocation));
                    // recursive search of all imports and include
                    listAllSchemas(importedSchema, newBaseLocation, refs);
                } else {
                    LOGGER.log(Level.WARNING, "Unable to retrieve imported schema:{0}", schemalocation);
                }
            }
        }
    }
}
Also used : AbstractMap(java.util.AbstractMap) Import(org.geotoolkit.xsd.xml.v2001.Import) QName(javax.xml.namespace.QName) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) Schema(org.geotoolkit.xsd.xml.v2001.Schema) Include(org.geotoolkit.xsd.xml.v2001.Include) OpenAttrs(org.geotoolkit.xsd.xml.v2001.OpenAttrs) Callable(java.util.concurrent.Callable) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Aggregations

OpenAttrs (org.geotoolkit.xsd.xml.v2001.OpenAttrs)4 QName (javax.xml.namespace.QName)3 TopLevelElement (org.geotoolkit.xsd.xml.v2001.TopLevelElement)3 Schema (org.geotoolkit.xsd.xml.v2001.Schema)2 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 Callable (java.util.concurrent.Callable)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 ComplexType (org.geotoolkit.xsd.xml.v2001.ComplexType)1 Element (org.geotoolkit.xsd.xml.v2001.Element)1 Import (org.geotoolkit.xsd.xml.v2001.Import)1 Include (org.geotoolkit.xsd.xml.v2001.Include)1 LocalComplexType (org.geotoolkit.xsd.xml.v2001.LocalComplexType)1 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)1 FeatureType (org.opengis.feature.FeatureType)1 MismatchedFeatureException (org.opengis.feature.MismatchedFeatureException)1 GenericName (org.opengis.util.GenericName)1