Search in sources :

Example 1 with JavaParserXmlGenerator

use of org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator in project org.hl7.fhir.core by hapifhir.

the class JavaCoreGenerator method genClass.

public void genClass(String version, String dest, Date date, Configuration config, String jid, NpmPackage npm, Definitions master, JavaParserJsonGenerator jgen, JavaParserXmlGenerator xgen, JavaParserRdfGenerator rgen, StructureDefinition sd) throws Exception, IOException, UnsupportedEncodingException, FileNotFoundException {
    String name = javaName(sd.getName());
    System.out.println(" .. " + name);
    Analyser jca = new Analyser(master, config, version);
    Analysis analysis = jca.analyse(sd);
    String fn = Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", name + ".java");
    JavaResourceGenerator gen = new JavaResourceGenerator(new FileOutputStream(fn), master, config, date, npm.version(), jid);
    gen.generate(analysis);
    gen.close();
    jgen.seeClass(analysis);
    xgen.seeClass(analysis);
    rgen.seeClass(analysis);
}
Also used : Analyser(org.hl7.fhir.core.generator.analysis.Analyser) Analysis(org.hl7.fhir.core.generator.analysis.Analysis) FileOutputStream(java.io.FileOutputStream) JavaResourceGenerator(org.hl7.fhir.core.generator.codegen.JavaResourceGenerator)

Example 2 with JavaParserXmlGenerator

use of org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator in project org.hl7.fhir.core by hapifhir.

the class JavaCoreGenerator method generate.

private void generate(String version, String src, String dest) throws Exception {
    long start = System.currentTimeMillis();
    Date date = new Date();
    String ap = Utilities.path(src);
    System.out.println("Load Configuration from " + ap);
    Configuration config = new Configuration(ap);
    String pid = VersionUtilities.isR4BVer(version) ? "r4b" : "r5";
    String jid = VersionUtilities.isR4BVer(version) ? "r4b" : "r5";
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    System.out.println("Cache: " + pcm.getFolder());
    System.out.println("Load hl7.fhir." + pid + ".core");
    NpmPackage npm = pcm.loadPackage("hl7.fhir." + pid + ".core", version);
    Definitions master = VersionUtilities.isR4BVer(version) ? DefinitionsLoaderR4B.load(npm) : DefinitionsLoaderR5.load(npm);
    master.fix();
    markValueSets(master, config);
    System.out.println("Load hl7.fhir." + pid + ".expansions");
    Definitions expansions = DefinitionsLoaderR5.load(pcm.loadPackage("hl7.fhir." + pid + ".expansions", version));
    System.out.println("Process Expansions");
    updateExpansions(master, expansions);
    System.out.println("Generate Model");
    System.out.println(" .. Constants");
    JavaConstantsGenerator cgen = new JavaConstantsGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "Constants.java")), master, config, date, npm.version(), jid);
    cgen.generate();
    cgen.close();
    System.out.println(" .. Enumerations");
    JavaEnumerationsGenerator egen = new JavaEnumerationsGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "Enumerations.java")), master, config, date, npm.version(), jid);
    egen.generate();
    egen.close();
    JavaFactoryGenerator fgen = new JavaFactoryGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "ResourceFactory.java")), master, config, date, npm.version(), jid);
    JavaTypeGenerator tgen = new JavaTypeGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "ResourceType.java")), master, config, date, npm.version(), jid);
    JavaParserJsonGenerator jgen = new JavaParserJsonGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "JsonParser.java")), master, config, date, npm.version(), jid);
    JavaParserXmlGenerator xgen = new JavaParserXmlGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "XmlParser.java")), master, config, date, npm.version(), jid);
    JavaParserRdfGenerator rgen = new JavaParserRdfGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "RdfParser.java")), master, config, date, npm.version(), jid);
    if (VersionUtilities.isR4BVer(version)) {
        StructureDefinition sd = master.getStructures().get("http://hl7.org/fhir/StructureDefinition/Element");
        genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && !sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    if (VersionUtilities.isR4BVer(version)) {
        StructureDefinition sd = master.getStructures().get("http://hl7.org/fhir/StructureDefinition/Resource");
        genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.RESOURCE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.RESOURCE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && !sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    System.out.println(" .. Factory");
    fgen.generate();
    fgen.close();
    System.out.println(" .. Types");
    tgen.generate();
    tgen.close();
    System.out.println(" .. JsonParser");
    jgen.generate();
    jgen.close();
    System.out.println(" .. XmlParser");
    xgen.generate();
    xgen.close();
    System.out.println(" .. RdfParser");
    rgen.generate();
    rgen.close();
    System.out.println("Done (" + Long.toString(System.currentTimeMillis() - start) + "ms)");
}
Also used : JavaEnumerationsGenerator(org.hl7.fhir.core.generator.codegen.JavaEnumerationsGenerator) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) JavaTypeGenerator(org.hl7.fhir.core.generator.codegen.JavaTypeGenerator) Configuration(org.hl7.fhir.core.generator.codegen.Configuration) JavaParserRdfGenerator(org.hl7.fhir.core.generator.codegen.JavaParserRdfGenerator) JavaParserJsonGenerator(org.hl7.fhir.core.generator.codegen.JavaParserJsonGenerator) JavaParserXmlGenerator(org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator) Date(java.util.Date) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) JavaFactoryGenerator(org.hl7.fhir.core.generator.codegen.JavaFactoryGenerator) FileOutputStream(java.io.FileOutputStream) JavaConstantsGenerator(org.hl7.fhir.core.generator.codegen.JavaConstantsGenerator)

Aggregations

FileOutputStream (java.io.FileOutputStream)2 Date (java.util.Date)1 Analyser (org.hl7.fhir.core.generator.analysis.Analyser)1 Analysis (org.hl7.fhir.core.generator.analysis.Analysis)1 Configuration (org.hl7.fhir.core.generator.codegen.Configuration)1 JavaConstantsGenerator (org.hl7.fhir.core.generator.codegen.JavaConstantsGenerator)1 JavaEnumerationsGenerator (org.hl7.fhir.core.generator.codegen.JavaEnumerationsGenerator)1 JavaFactoryGenerator (org.hl7.fhir.core.generator.codegen.JavaFactoryGenerator)1 JavaParserJsonGenerator (org.hl7.fhir.core.generator.codegen.JavaParserJsonGenerator)1 JavaParserRdfGenerator (org.hl7.fhir.core.generator.codegen.JavaParserRdfGenerator)1 JavaParserXmlGenerator (org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator)1 JavaResourceGenerator (org.hl7.fhir.core.generator.codegen.JavaResourceGenerator)1 JavaTypeGenerator (org.hl7.fhir.core.generator.codegen.JavaTypeGenerator)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)1 NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)1