use of org.geotoolkit.xsd.xml.v2001.ComplexType in project geotoolkit by Geomatys.
the class JAXBFeatureTypeReader method getType.
/**
* @param qname
* @param stack
* @return FeatureType or GenericName
* @throws MismatchedFeatureException
*/
private Object getType(QName qname, BuildStack stack) throws MismatchedFeatureException {
final ComplexType type = xsdContext.findComplexType(qname);
if (type == null) {
// search for an element with this name
final Element element = xsdContext.findGlobalElement(qname);
if (element != null) {
return elementToAttribute(qname.getNamespaceURI(), element, stack);
}
}
if (type == null) {
throw new MismatchedFeatureException("Unable to find complex type for name : " + qname);
}
final GenericName name = extractFinalName(qname.getNamespaceURI(), type);
if (typesCache.containsKey(name)) {
return typesCache.get(name);
}
if (stack.contains(name)) {
// recursive build
return name;
}
stack.add(name);
return getType(qname.getNamespaceURI(), type, stack, true);
}
use of org.geotoolkit.xsd.xml.v2001.ComplexType 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);
}
}
Aggregations