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());
}
}
}
}
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;
}
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);
}
}
}
}
}
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);
}
}
}
}
}
Aggregations