use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class JsonGenerator method scanTypes.
private void scanTypes(ElementDefn root, ElementDefn focus) {
for (ElementDefn e : focus.getElements()) {
if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
int i = 0;
String tn = root.getName() + "." + upFirst(e.getName()) + (i == 0 ? "" : Integer.toString(i));
while (typenames.contains(tn)) {
i++;
tn = root.getName() + "." + upFirst(e.getName()) + (i == 0 ? "" : Integer.toString(i));
}
structures.add(e);
typenames.add(tn);
types.put(e, tn);
scanTypes(root, e);
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDBaseGenerator method genResource.
private void genResource(String name, ResourceDefn res) throws Exception {
enums.clear();
enumDefs.clear();
boolean isBase = Utilities.noString(res.getRoot().typeCode());
write(" <xs:complexType name=\"" + name + "\">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(res.getDefinition()) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
if (!isBase) {
write(" <xs:complexContent>\r\n");
write(" <xs:extension base=\"" + res.getRoot().typeCode() + "\">\r\n");
}
if (!res.isInterface()) {
write(" <xs:sequence>\r\n");
for (ElementDefn e : res.getRoot().getElements()) {
generateElement(res.getRoot(), e, null, null);
}
write(" </xs:sequence>\r\n");
}
if (!isBase) {
write(" </xs:extension>\r\n");
write(" </xs:complexContent>\r\n");
}
write(" </xs:complexType>\r\n");
genRegex();
while (!structures.isEmpty()) {
String s = structures.keySet().iterator().next();
generateType(res.getRoot(), s, structures.get(s));
structures.remove(s);
}
for (BindingSpecification en : enums) {
generateEnum(en);
}
genRegex();
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDBaseGenerator method generate.
public void generate(String version, String genDate, boolean outer) throws Exception {
if (outer) {
write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
write("<!-- \r\n");
write(Config.FULL_LICENSE_CODE);
write("\r\n");
write(" Generated on " + genDate + " for FHIR v" + version + " \r\n");
write("\r\n");
write(" Note: the schemas & schematrons do not contain all of the rules about what makes resources\r\n");
write(" valid. Implementers will still need to be familiar with the content of the specification and with\r\n");
write(" any profiles that apply to the resources in order to make a conformant implementation.\r\n");
write("\r\n");
write("-->\r\n");
write("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " + "targetNamespace=\"http://hl7.org/fhir\" elementFormDefault=\"qualified\" version=\"1.0\">\r\n");
}
write(" <xs:import namespace=\"http://www.w3.org/XML/1998/namespace\" schemaLocation=\"xml.xsd\"/>\r\n");
write(" <xs:import namespace=\"http://www.w3.org/1999/xhtml\" schemaLocation=\"fhir-xhtml.xsd\"/>\r\n");
if (outer)
write(" <xs:include schemaLocation=\"fhir-all.xsd\"/>\r\n");
// genElementRoot();
write("\r\n");
genPrimitives();
write("\r\n");
genResourceReference();
genResourceContainer();
for (ElementDefn e : definitions.getInfrastructure().values()) genInfrastructure(e);
for (ElementDefn e : definitions.getTypes().values()) genType(e);
for (String n : definitions.getBaseResources().keySet()) {
ResourceDefn r = definitions.getBaseResources().get(n);
if (r.isAbstract()) {
genResource(n, r);
}
}
// todo: what to do about this?
for (BindingSpecification b : definitions.getCommonBindings().values()) if (((b.getUseContexts().size() > 1 || b.isShared()) && isEnum(b)))
generateEnum(b);
if (outer) {
write("</xs:schema>\r\n");
writer.flush();
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDBaseGenerator method generateElement.
private void generateElement(ElementDefn root, ElementDefn e, String paramType, Map<String, String> rules) throws Exception {
List<TypeRef> types = e.getTypes();
if (types.size() > 1 || (types.size() == 1 && types.get(0).isWildcardType())) {
if (!e.getName().contains("[x]"))
throw new Exception("Element has multiple types as a choice doesn't have a [x] in the element name '" + e.getName() + "' in resource " + root.getName());
if ((types.size() == 1 && types.get(0).isWildcardType())) {
generateAny(root, e, e.getName().replace("[x]", ""), null);
} else {
String close = " minOccurs=\"0\">";
;
if (!forCodeGeneration) {
write(" <xs:choice minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\" maxOccurs=\"1\">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
close = "/>";
}
for (TypeRef t : types) {
String type = encodeType(e, t, true);
String name = e.getName().substring(0, e.getName().length() - 3) + nameForType(type);
write(" <xs:element name=\"" + name + "\" type=\"" + type + "\" ");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"" + close + "\r\n");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"" + close + "\r\n");
if (forCodeGeneration) {
write(" <xs:annotation>\r\n");
if (e.hasDefinition()) {
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + " (choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
} else {
write(" <xs:documentation xml:lang=\"en\">(choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
}
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
}
}
if (!forCodeGeneration)
write(" </xs:choice>\r\n");
}
} else {
write(" ");
if ("extension".equals(e.getName()))
write("<xs:element name=\"" + e.getName() + "\" type=\"Extension\" ");
else if ("div".equals(e.getName()) && e.typeCode().equals("xhtml"))
write("<xs:element ref=\"xhtml:div\" ");
else if (e.usesCompositeType()) {
ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
String rtn = this.types.get(ref);
if (rtn == null)
throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
write("<xs:element name=\"" + e.getName() + "\" type=\"" + rtn + "\" ");
} else if (types.size() == 0 && e.getElements().size() > 0) {
String tn = root.getName() + "." + Utilities.capitalize(e.getName());
int i = 0;
while (typenames.contains(tn)) {
i++;
tn = root.getName() + "." + Utilities.capitalize(e.getName()) + Integer.toString(i);
}
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
structures.put(tn, e);
this.types.put(e, tn);
typenames.add(tn);
} else if (types.size() == 1) {
if (types.get(0).isUnboundGenericParam() && paramType != null)
write("<xs:element name=\"" + e.getName() + "\" type=\"" + paramType + "\" ");
else if (!Utilities.noString(e.getRegex())) {
String tn = root.getName() + Utilities.capitalize(e.getName()) + "Type";
regexQueue.put(tn, e.getRegex());
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
} else
write("<xs:element name=\"" + e.getName() + "\" type=\"" + encodeType(e, types.get(0), true) + "\" ");
} else
throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(types.size()));
write("minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\"");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"");
if (e.hasDefinition()) {
write(">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
} else {
write("/>\r\n");
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDGenerator method scanTypes.
private void scanTypes(ElementDefn root, ElementDefn focus) {
for (ElementDefn e : focus.getElements()) {
if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
int i = 0;
String tn = root.getName() + "." + upFirst(e.getName()) + (i == 0 ? "" : Integer.toString(i));
while (typenames.contains(tn)) {
i++;
tn = root.getName() + "." + upFirst(e.getName()) + (i == 0 ? "" : Integer.toString(i));
}
structures.add(e);
typenames.add(tn);
types.put(e, tn);
scanTypes(root, e);
}
}
}
Aggregations