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=ed11c14cd7ad762f9cb4ffc81b49db92ad1387ef;hb=f11cbe76b3f4be142c9f84ef9a7b6bc9dcc8ff23;hp=c7167545d31b96b58077f0e097c5a8d3d285443c;hpb=d788a05e77b983199f0982a0e56629e7fc30c691;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 c716754..ed11c14 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 @@ -16,6 +16,7 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import org.simantics.utils.datastructures.MapList; import org.simantics.xml.sax.configuration.Configuration; import org.w3._2001.xmlschema.Annotation; import org.w3._2001.xmlschema.Import; @@ -49,8 +50,11 @@ public class SchemaConverter { private List parent = new ArrayList<>(); private List subConverters = new ArrayList<>(); - private Map nameMap; + private Map fileMap; + private MapList schemaNSMap; + private MapList shortNameMap; + String schemaNs; String ontologyUri; String className; String name; @@ -88,9 +92,15 @@ public class SchemaConverter { this.parent.add(parent); parent.subConverters.add(this); } else { - nameMap = new HashMap<>(); + fileMap = new HashMap<>(); + schemaNSMap = new MapList<>(); + shortNameMap = new MapList<>(); } - getRoot().nameMap.put(schemaFile.getAbsolutePath(), this); + getRoot().fileMap.put(schemaFile.getAbsolutePath(), this); + } + + public List getConverter(String schemaNS) { + return getRoot().schemaNSMap.getValues(schemaNS); } public void setFileImport(ManualSchemaFileImport fileImport) { @@ -120,7 +130,7 @@ public class SchemaConverter { if (!schemaFile.exists()) throw new FileNotFoundException(schemaFile.getAbsolutePath()); } - SchemaConverter subConverter = getRoot().nameMap.get((schemaFile.getAbsolutePath())); + SchemaConverter subConverter = getRoot().fileMap.get((schemaFile.getAbsolutePath())); if (subConverter == null) { subConverter = new SchemaConverter(this,schemaFile, conversionFile, outputPlugin); subConverter.createPGraph = this.createPGraph; @@ -147,6 +157,38 @@ public class SchemaConverter { boolean init = false; + protected void assignShortName() { + shortName = name.substring(0, 3).toUpperCase(); + SchemaConverter root = getRoot(); + if (!root.shortNameMap.containsKey(shortName)) { + root.shortNameMap.add(shortName, this); + return; + } else { + SchemaConverter sc = root.shortNameMap.getValues(shortName).get(0); + if (sc.schemaNs.equals(schemaNs)) { + root.shortNameMap.add(shortName, this); + return; + } + } + int i = 1; + while (true) { + String n = shortName+i; + if (!root.shortNameMap.containsKey(n)) { + shortName = n; + root.shortNameMap.add(shortName, this); + return; + } else { + SchemaConverter sc = root.shortNameMap.getValues(n).get(0); + if (sc.schemaNs.equals(schemaNs)) { + shortName = n; + root.shortNameMap.add(shortName, this); + return; + } + } + i++; + } + } + protected void init() throws IOException, JAXBException { if (init) return; @@ -172,8 +214,8 @@ public class SchemaConverter { header[2] = "File " + schemaFile.getAbsolutePath(); header[3] = "Date " + new Date().toString(); - - ontologyUri = schema.getTargetNamespace(); + schemaNs = schema.getTargetNamespace(); + ontologyUri = schemaNs; if (ontologyUri == null) { ontologyUri = getSchemaFile().getName(); @@ -197,7 +239,9 @@ public class SchemaConverter { className = getPluginName() + "." + name; - shortName = name.substring(0, 3).toUpperCase(); + assignShortName(); + if (schemaNs != null) + getRoot().schemaNSMap.add(schemaNs, this); for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) {