X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaConverter.java;h=3b2c1a0c42749b6bddf5babe3525924696bfb844;hb=404be73748777cdd2d09b2f29308ae6f4a3d730c;hp=523788c8e33971819ed2c709cc79c48c642edb66;hpb=ada38ab0a1a98dcb413bef3273064da36ce2d273;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java index 523788c..3b2c1a0 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java @@ -33,6 +33,12 @@ public class SchemaConverter { private String[] header; + boolean createPGraph = true; + boolean createImporter = true; + boolean createExporter = true; + + + public void convertSchema(File schemaFile, File conversionFile, File outputPlugin) throws JAXBException, IOException { pluginName = outputPlugin.getName(); @@ -61,6 +67,18 @@ public class SchemaConverter { } + public void setCreateExporter(boolean createExporter) { + this.createExporter = createExporter; + } + + public void setCreateImporter(boolean createImporter) { + this.createImporter = createImporter; + } + + public void setCreatePGraph(boolean createPGraph) { + this.createPGraph = createPGraph; + } + private void convert() throws JAXBException, IOException { JAXBContext jc = JAXBContext.newInstance("org.w3._2001.xmlschema"); Unmarshaller u = jc.createUnmarshaller(); @@ -84,10 +102,43 @@ public class SchemaConverter { header[3] = "Date " + new Date().toString(); + String ontologyUri = schema.getTargetNamespace(); + if (ontologyUri == null) { + ontologyUri = getSchemaFile().getName(); + + int index = ontologyUri.lastIndexOf("."); + if (index > 0) + ontologyUri = ontologyUri.substring(0, index); + } + ontologyUri = ontologyUri.replaceAll(" ", "_"); + String parts[] = ontologyUri.split("/"); + String name = parts[parts.length-1]; + name = name.replaceAll("\\.", "_"); + if (!ontologyUri.startsWith("http://")) + ontologyUri = "http://" + ontologyUri.replaceAll("/", "_"); + else + ontologyUri = "http://" + ontologyUri.substring("http://".length()).replaceAll("/", "_"); + + String version = schema.getVersion(); + if (version == null) + version = "1.0"; + ontologyUri +="-"+ version; + + + String className = getPluginName() + "." + name; + + if (createPGraph) { OntologyGenerator ontologyGenerator = new OntologyGenerator(configuration); - ontologyGenerator.createOntology(schema, this); + ontologyGenerator.createOntology(schema, ontologyUri, className, this); + } + if (createImporter) { ImporterGenerator importerGenerator = new ImporterGenerator(configuration); - importerGenerator.createParser(schema, ontologyGenerator.getClassName(), this); + importerGenerator.createParser(schema, ontologyUri, className, this); + } + if (createExporter) { + ExporterGenerator exporterGenerator = new ExporterGenerator(configuration); + exporterGenerator.createParser(schema, ontologyUri,className, this); + } } public File getOntologyFile() {