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