use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType in project geotoolkit by Geomatys.
the class JAXBFeatureTypeWriter method fillSchemaWithFeatureType.
private void fillSchemaWithFeatureType(final FeatureType featureType, final Schema schema, boolean addTopElement, Set<String> alreadyWritten) {
if (Utils.GML_FEATURE_TYPES.contains(featureType.getName())) {
// this type is part of the standard GML types
return;
}
// write parent types
for (FeatureType parent : featureType.getSuperTypes()) {
fillSchemaWithFeatureType(parent, schema, false, alreadyWritten);
}
final String typeNamespace = NamesExt.getNamespace(featureType.getName());
final String elementName = featureType.getName().tip().toString();
final String typeName = elementName + "Type";
if (addTopElement) {
final TopLevelElement topElement;
if ("3.2.1".equals(gmlVersion)) {
topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_321);
} else {
topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_311);
}
schema.addElement(topElement);
}
boolean ar = alreadyWritten.add(typeName);
final ExplicitGroup sequence = new ExplicitGroup();
final List<Attribute> attributes = new ArrayList<>();
for (final PropertyType pdesc : featureType.getProperties(false)) {
if (AttributeConvention.contains(pdesc.getName())) {
// skip convention properties
continue;
}
writeProperty(pdesc, sequence, schema, attributes, alreadyWritten);
}
if (addTopElement && ar) {
final ComplexContent content = getComplexContent(sequence);
final TopLevelComplexType tlcType = new TopLevelComplexType(typeName, content);
tlcType.getAttributeOrAttributeGroup().addAll(attributes);
schema.addComplexType(1, tlcType);
}
}
use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType 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);
}
}
use of org.geotoolkit.xsd.xml.v2001.TopLevelComplexType in project geotoolkit by Geomatys.
the class JAXBFeatureTypeWriter method writeComplexType.
private void writeComplexType(final FeatureType ctype, final Schema schema, Set<String> alreadyWritten) {
final GenericName ptypeName = ctype.getName();
// PropertyType
final String nameWithSuffix = Utils.getNameWithTypeSuffix(ptypeName.tip().toString());
boolean write = schema.getTargetNamespace().equals(NamesExt.getNamespace(ptypeName));
// search if this type has already been written
if (alreadyWritten.contains(nameWithSuffix)) {
return;
}
alreadyWritten.add(nameWithSuffix);
// complex type
final ExplicitGroup sequence = new ExplicitGroup();
final TopLevelComplexType tlcType = new TopLevelComplexType(nameWithSuffix, sequence);
if (write) {
schema.addComplexType(tlcType);
}
final List<Attribute> attributes = new ArrayList<>();
for (final PropertyType pdesc : ctype.getProperties(true)) {
writeProperty(pdesc, sequence, schema, attributes, alreadyWritten);
}
tlcType.getAttributeOrAttributeGroup().addAll(attributes);
}
Aggregations