in SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/transform/impl/BaseSchemaGenerator.java [121:247]
protected void init(OutputStream out, int xsdType, String targetNamespace, SDMX_SCHEMA targetSchemaVersion, DataStructureSuperBean keyFamily) {
this.targetSchemaVersion = targetSchemaVersion;
switch (targetSchemaVersion) {
case VERSION_ONE:
COMPACT_NS = SdmxConstants.COMPACT_NS_1_0;
COMMON_NS = SdmxConstants.COMMON_NS_1_0;
UTILITY_NS = SdmxConstants.UTILITY_NS_1_0;
MESSAGE_NS = SdmxConstants.MESSAGE_NS_1_0;
break;
case VERSION_TWO:
COMPACT_NS = SdmxConstants.COMPACT_NS_2_0;
COMMON_NS = SdmxConstants.COMMON_NS_2_0;
UTILITY_NS = SdmxConstants.UTILITY_NS_2_0;
MESSAGE_NS = SdmxConstants.MESSAGE_NS_2_0;
break;
case VERSION_TWO_POINT_ONE:
COMPACT_NS = SdmxConstants.COMPACT_NS_2_1;
COMMON_NS = SdmxConstants.COMMON_NS_2_1;
MESSAGE_NS = SdmxConstants.STRUCTURE_SPECIFIC_NS_2_1;
break;
default:
throw new SdmxNotImplementedException(ExceptionCode.UNSUPPORTED, targetSchemaVersion);
}
if (!keyFamily.getBuiltFrom().isCompatible(targetSchemaVersion)) {
String errorString = "The Data Structure '" + keyFamily.getName() + "' is not compatible with the target schema version: " + targetSchemaVersion;
throw new IllegalArgumentException(errorString);
}
if (targetNamespace == null) {
targetNamespace = "undefined";
}
this.dsd = keyFamily;
try {
XMLOutputFactory xmlOutputfactory = XMLOutputFactory.newInstance();
writer = xmlOutputfactory.createXMLStreamWriter(out, "UTF-8");
writer.writeStartDocument();
writer.writeStartElement("xs", "schema", SCHEMA_NS); // Start Schema - not ended till end of document
if (targetSchemaVersion == SDMX_SCHEMA.VERSION_TWO_POINT_ONE) {
writer.writeAttribute("xmlns:dsd", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific");
}
writer.writeDefaultNamespace(targetNamespace);
writer.writeNamespace("xs", SCHEMA_NS);
switch (xsdType) {
case COMPACT:
writer.writeNamespace("compact", COMPACT_NS);
break;
case UTILITY:
writer.writeNamespace("utility", UTILITY_NS);
break;
}
writer.writeNamespace("common", COMMON_NS);
writer.writeNamespace("message", MESSAGE_NS);
writer.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
writer.writeAttribute("targetNamespace", targetNamespace);
writer.writeAttribute("elementFormDefault", "qualified");
writer.writeAttribute("attributeFormDefault", "unqualified");
//IMPORT SCHEMAS
writer.writeStartElement(SCHEMA_NS, "import"); // Start Import
writer.writeAttribute("namespace", COMMON_NS);
if (schemaLocation == null) {
schemaLocation = "";
}
writer.writeAttribute("schemaLocation", schemaLocation + "SDMXCommon.xsd");
//String schema = MESSAGE_NS + " " + schemaLocation+"SDMXMessage.xsd";
writer.writeEndElement(); // End Import
if (targetSchemaVersion.equals(SDMX_SCHEMA.VERSION_TWO_POINT_ONE)) {
writer.writeStartElement(SCHEMA_NS, "import"); // Start Import
writer.writeAttribute("namespace", MESSAGE_NS);
writer.writeAttribute("schemaLocation", schemaLocation + "SDMXDataStructureSpecific.xsd");
writer.writeEndElement(); // End Import
} else {
writer.writeStartElement(SCHEMA_NS, "import"); // Start Import
switch (xsdType) {
case COMPACT:
writer.writeAttribute("namespace", COMPACT_NS);
writer.writeAttribute("schemaLocation", schemaLocation + "SDMXCompactData.xsd");
break;
case UTILITY:
writer.writeAttribute("namespace", UTILITY_NS);
writer.writeAttribute("schemaLocation", schemaLocation + "SDMXUtilityData.xsd");
break;
}
writer.writeEndElement(); // End Import
writer.writeStartElement(SCHEMA_NS, "import"); // Start Import
writer.writeAttribute("namespace", MESSAGE_NS);
writer.writeAttribute("schemaLocation", schemaLocation + "SDMXMessage.xsd");
writer.writeEndElement(); // End Import
}
// Components
Set<String> processed = new HashSet<String>();
for (ComponentSuperBean csb : keyFamily.getComponents()) {
if (csb.getCodelist(true) != null) {
// Coded
CodelistSuperBean cl = csb.getCodelist(true);
if (processed.contains(cl.getUrn())) {
continue;
}
processed.add(cl.getUrn());
processCodelist(csb.getId(), cl);
} else {
TextFormatBean tf = csb.getTextFormat();
if (tf != null && tf.getTextType() != null) {
processUncodedWithRestriction(csb.getId(), tf);
}
}
}
} catch (Throwable th) {
throw new RuntimeException(th);
}
}