From 404be73748777cdd2d09b2f29308ae6f4a3d730c Mon Sep 17 00:00:00 2001 From: luukkainen Date: Wed, 25 Jan 2017 16:47:47 +0000 Subject: [PATCH] Handling ComplexTypes defined with SimpleContent Exporting multi-schema data refs #6985 git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@33436 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../org/simantics/xml/sax/base/XMLWriter.java | 67 ++++++++++++++++--- .../simantics/xml/sax/ExporterGenerator.java | 34 +++++----- .../simantics/xml/sax/ImporterGenerator.java | 38 +++++------ .../org/simantics/xml/sax/JavaGenerator.java | 27 ++------ .../simantics/xml/sax/OntologyGenerator.java | 41 +++--------- .../xml/sax/SchemaConversionBase.java | 58 +++++++++++----- .../simantics/xml/sax/SchemaConverter.java | 34 ++++++---- 7 files changed, 165 insertions(+), 134 deletions(-) diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java index 0881a5d..f37e4d8 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java @@ -2,7 +2,6 @@ package org.simantics.xml.sax.base; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -21,16 +20,19 @@ import org.simantics.db.Statement; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; import org.simantics.message.ILogger; import org.simantics.xml.sax.ontology.XMLResource; public class XMLWriter { private ReadGraph graph; - private Map subWriters = new HashMap(); + private Map subWriters = new HashMap(); private Map, XMLElementWriter> namedWriters = new HashMap, XMLElementWriter>(); private Map writers = new HashMap<>(); private String schemaURI; + private String ontologyURI; + private Resource ontology; private ILogger logger; @@ -38,10 +40,12 @@ public class XMLWriter { return graph; } - public void setGraph(ReadGraph graph) { + public void setGraph(ReadGraph graph) throws DatabaseException { this.graph = graph; for (XMLWriter p : subWriters.values()) p.setGraph(graph); + if (ontologyURI != null) + this.ontology = graph.getResource(ontologyURI); } public String getSchemaURI() { @@ -52,6 +56,18 @@ public class XMLWriter { this.schemaURI = schemaURI; } + public String getOntologyURI() { + return ontologyURI; + } + + public void setOntologyURI(String ontologyURI) { + this.ontologyURI = ontologyURI; + } + + public Resource getOntology() { + return ontology; + } + public void add(XMLElementWriter writer) throws DatabaseException { Resource type = writer.getType(graph); if (type != null) @@ -60,7 +76,7 @@ public class XMLWriter { } public void add(XMLWriter writer) { - subWriters.put(writer.getSchemaURI(), writer); + subWriters.put(writer.getOntology(), writer); } public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException { @@ -84,7 +100,9 @@ public class XMLWriter { if (graph.hasValue(instance.instance)) elementWriter.characters(graph, instance, writer); // get all child elements - Collection childElements = graph.getStatements(instance.instance, XML.hasElement); + Set childElements = new HashSet<>(); + childElements.addAll(graph.getStatements(instance.instance, XML.hasElement)); + childElements.addAll(graph.getStatements(instance.instance, XML.hasComplexType)); // load elements, assign writers Map elementMap = new HashMap<>(); for (Statement s : childElements) { @@ -104,6 +122,8 @@ public class XMLWriter { if (processed.contains(r)) // badly generated writer could report elements several times. continue; WriterElement child = elementMap.get(r); + if (child == null) + throw new DatabaseException("Trying to export unregonized resource " +NameUtils.getSafeName(graph, r) + " " + r); write(child, writer); processed.add(r); } @@ -112,6 +132,8 @@ public class XMLWriter { if (processed.contains(stm.getObject())) continue; WriterElement child = elementMap.get(stm.getObject()); + if (child == null) + throw new DatabaseException("Trying to export unregonized resource " +NameUtils.getSafeName(graph, stm.getObject()) + " " + stm.getObject()); write(child, writer); } @@ -128,13 +150,20 @@ public class XMLWriter { childWriter = this.writers.get(childWriterClass); if (childWriter == null) { try { - Constructor c = childWriterClass.getConstructor(ReadGraph.class); + Constructor c = null; + try { + c = childWriterClass.getConstructor(ReadGraph.class); + childWriter = c.newInstance(graph); + } catch (NoSuchMethodException e) { + c = childWriterClass.getConstructor(); + childWriter = c.newInstance(); + } //childWriter = childWriterClass.newInstance(); - childWriter = c.newInstance(graph); + namedWriters.put(childWriterClass, childWriter); } catch (IllegalAccessException|InstantiationException|NoSuchMethodException|SecurityException|InvocationTargetException e) { String err = "Error processing " + childWriterClass.getName() + " : element writers must have accessible constructor with ReadGraph parameter"; - logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err)); + logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err, e)); } } } @@ -143,10 +172,30 @@ public class XMLWriter { childWriter = writers.get(type); } if (childWriter == null) { - throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance); + Resource type = graph.getSingleType(child.instance); + Resource ontology = getOntology(type); + if (ontology != null) { + XMLWriter xmlWriter = subWriters.get(ontology); + if (xmlWriter != null) { + childWriter = xmlWriter.writers.get(type); + } + } + if (childWriter == null) + throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance); } child.writer = childWriter; } + + private Resource getOntology(Resource type) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource r = type; + while (true) { + r = graph.getPossibleObject(r, L0.PartOf); + if (r != null && graph.isInstanceOf(r, L0.Ontology)) + break; + } + return r; + } } diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java index c767311..1976664 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java @@ -11,7 +11,6 @@ import java.util.Map; import javax.xml.namespace.QName; import org.simantics.utils.datastructures.BijectionMap; -import org.simantics.xml.sax.SchemaConversionBase.RefType; import org.simantics.xml.sax.configuration.AttributeComposition; import org.simantics.xml.sax.configuration.Configuration; import org.simantics.xml.sax.configuration.IDProvider; @@ -25,7 +24,6 @@ import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.LocalComplexType; import org.w3._2001.xmlschema.LocalSimpleType; import org.w3._2001.xmlschema.NamedAttributeGroup; -import org.w3._2001.xmlschema.OpenAttrs; import org.w3._2001.xmlschema.Restriction; import org.w3._2001.xmlschema.Schema; import org.w3._2001.xmlschema.SimpleType; @@ -39,7 +37,7 @@ public class ExporterGenerator extends JavaGenerator{ - public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException { + public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException { this.schema = schema; this.ontologyClassName = className; this.converter = converter; @@ -101,6 +99,7 @@ public class ExporterGenerator extends JavaGenerator{ mainWriter.println(" public " + name + parserClassPostfix+"(Session session) throws DatabaseException {"); if (schema.getTargetNamespace() != null) mainWriter.println(" setSchemaURI(\""+schema.getTargetNamespace()+"\");"); + mainWriter.println(" setOntologyURI(\""+ontologyUri+"\");"); mainWriter.println(" session.syncRequest(new ReadRequest() {"); mainWriter.println(" @Override"); mainWriter.println(" public void run(ReadGraph graph) throws DatabaseException {"); @@ -127,12 +126,15 @@ public class ExporterGenerator extends JavaGenerator{ return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase"; } + @Override + protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) { + } @Override protected void handleComplexType(SchemaObject complexTypeObj) { ComplexType topLevelComplexType = complexTypeObj.getComplexType(); - String name = getName(complexTypeObj);//topLevelComplexType.getName(); + String name = getName(complexTypeObj); String className = name;//"_"+name; @@ -143,22 +145,25 @@ public class ExporterGenerator extends JavaGenerator{ throw new RuntimeException(e); } writers.put(complexTypeObj, fw); - - boolean isList = false; - String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase"; + String baseClass = getBaseClass(); boolean inherited = false; QName type = getComplexTypeBase(topLevelComplexType); if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) { - baseClass = getName(complexTypeName.get(type.getLocalPart())); - inherited = true; + SchemaObject obj = complexTypeName.get(type.getLocalPart()); +// if (obj == null) +// obj = simpleTypeName.get(type.getLocalPart()); + if (obj != null) { + baseClass = getName(obj); + inherited = true; + } } provider = getIDProvider(topLevelComplexType); - List references = getIDReferences(topLevelComplexType); - UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType); +// List references = getIDReferences(topLevelComplexType); +// UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType); // List intrerfaces = new ArrayList(); // if (references.size() > 0) @@ -167,7 +172,7 @@ public class ExporterGenerator extends JavaGenerator{ // intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser"); createClassHeader(fw.writer); - writeClass(fw.writer,false, null, className, baseClass, Collections.EMPTY_LIST); + writeClass(fw.writer,false, topLevelComplexType.getName(), className, baseClass, Collections.EMPTY_LIST); // writeIDProvider(fw.writer); @@ -617,10 +622,7 @@ public class ExporterGenerator extends JavaGenerator{ } - @Override - protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) { - - } + diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java index 25fc020..f55f9cf 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java @@ -5,30 +5,25 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import org.simantics.utils.datastructures.BijectionMap; -import org.simantics.xml.sax.SchemaConversionBase.RefType; import org.simantics.xml.sax.configuration.AttributeComposition; import org.simantics.xml.sax.configuration.Configuration; import org.simantics.xml.sax.configuration.IDProvider; import org.simantics.xml.sax.configuration.IDReference; -import org.simantics.xml.sax.configuration.Rename; import org.simantics.xml.sax.configuration.UnrecognizedChildElement; import org.w3._2001.xmlschema.Annotated; import org.w3._2001.xmlschema.Attribute; import org.w3._2001.xmlschema.AttributeGroup; -import org.w3._2001.xmlschema.AttributeGroupRef; import org.w3._2001.xmlschema.ComplexType; import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.LocalComplexType; import org.w3._2001.xmlschema.LocalSimpleType; import org.w3._2001.xmlschema.NamedAttributeGroup; -import org.w3._2001.xmlschema.OpenAttrs; import org.w3._2001.xmlschema.Restriction; import org.w3._2001.xmlschema.Schema; import org.w3._2001.xmlschema.SimpleType; @@ -40,7 +35,7 @@ public class ImporterGenerator extends JavaGenerator{ super(configuration); } - public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException { + public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException { this.schema = schema; this.ontologyClassName = className; this.converter = converter; @@ -107,15 +102,20 @@ public class ImporterGenerator extends JavaGenerator{ } protected void handle(TopLevelAttribute topLevelAttribute) { - } + @Override + protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) { + } @Override protected void handleComplexType(SchemaObject complexTypeObj) { ComplexType topLevelComplexType = complexTypeObj.getComplexType(); - String name = getName(complexTypeObj);//topLevelComplexType.getName(); + String name = getName(complexTypeObj); + +// if (topLevelComplexType.getName().equals("Reference")) +// System.out.println(); String className = name;//"_"+name; @@ -126,17 +126,18 @@ public class ImporterGenerator extends JavaGenerator{ throw new RuntimeException(e); } writers.put(complexTypeObj, fw); - - boolean isList = false; - String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase"; + String baseClass = getBaseClass(); boolean inherited = false; QName type = getComplexTypeBase(topLevelComplexType); if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) { - baseClass = getName(complexTypeName.get(type.getLocalPart())); - inherited = true; + SchemaObject obj = complexTypeName.get(type.getLocalPart()); + if (obj != null) { + baseClass = getName(obj); + inherited = true; + } } provider = getIDProvider(topLevelComplexType); @@ -149,7 +150,7 @@ public class ImporterGenerator extends JavaGenerator{ if (unknownChildElement != null) intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser"); - createClassHeader(fw.writer, isList); + createClassHeader(fw.writer, false); writeClass(fw.writer,false, null, className, baseClass, intrerfaces); writeIDProvider(fw.writer); @@ -158,12 +159,8 @@ public class ImporterGenerator extends JavaGenerator{ fw.writer.println(" public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{"); fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);"); fw.writer.println(" "+getOntologyImport()); - if (!isList) { fw.writer.println(" Resource res = graph.newResource();"); fw.writer.println(" graph.claim(res, L0.InstanceOf, "+ontShort+name+");"); - } else { - fw.writer.println(" Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);"); - } fw.writer.println(" return res;"); fw.writer.println(" }"); fw.writer.println(); @@ -567,10 +564,7 @@ public class ImporterGenerator extends JavaGenerator{ } - @Override - protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) { - - } + IDProvider provider; diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java index b6b4fed..887bd1e 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java @@ -72,26 +72,7 @@ public abstract class JavaGenerator extends SchemaConversionBase{ public static String getAttributeGroupPrefix() { return "AttributeGroups_"; } - -// @Override -// protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) { -// Element localElement = element.getElement(); -// if (localElement.getName() != null) { -// SchemaObject eObj = elements.get(localElement); -// String refName = localElement.getName(); -// QName refType = localElement.getType(); -// if (refType != null) -// handleIndicator(parent, indicator, element, false, refName, refType); -// else { -// handleElement(eObj); -// handleIndicator(parent, indicator, element, false, refName, localElement); -// } -// } else if (localElement.getRef() != null) { -// QName refType = localElement.getRef(); -// handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType); -// } -// } - + @Override protected void handle(SchemaObject parent, SchemaElement indicator, List elements) { if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) { @@ -231,7 +212,7 @@ public abstract class JavaGenerator extends SchemaConversionBase{ } } - protected void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List interfaces) { + protected void writeClass(PrintWriter writer,boolean abst, String elementId, String className, String baseClass, List interfaces) { writer.println("@SuppressWarnings(\"unused\")"); writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass); if (interfaces.size() > 0) { @@ -246,8 +227,8 @@ public abstract class JavaGenerator extends SchemaConversionBase{ writer.println(); writer.println(" @Override"); writer.println(" public java.lang.String getElementId() {"); - if (name != null) - writer.println(" return \""+name+"\";"); + if (elementId != null) + writer.println(" return \""+elementId+"\";"); else // complex types cannot be parsed directly with name/id reference. writer.println(" return null;"); writer.println(" }"); diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java index 8e5c3c1..e64a59b 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java @@ -21,7 +21,6 @@ import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.LocalComplexType; import org.w3._2001.xmlschema.LocalSimpleType; import org.w3._2001.xmlschema.NamedAttributeGroup; -import org.w3._2001.xmlschema.OpenAttrs; import org.w3._2001.xmlschema.Restriction; import org.w3._2001.xmlschema.Schema; import org.w3._2001.xmlschema.SimpleType; @@ -37,7 +36,7 @@ public class OntologyGenerator extends SchemaConversionBase { String commentTag = "//"; Schema schema; - String ontologyName; + String ontologyUri; String className; SchemaConverter converter; @@ -51,7 +50,7 @@ public class OntologyGenerator extends SchemaConversionBase { public void createOntology(Schema schema, String ontologyName, String className, SchemaConverter converter) throws FileNotFoundException { this.schema = schema; this.converter = converter; - this.ontologyName = ontologyName; + this.ontologyUri = ontologyName; this.className = className; // for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) { @@ -85,14 +84,10 @@ public class OntologyGenerator extends SchemaConversionBase { } protected void handle(Schema schema) { - String parts[] = ontologyName.split("/"); + String parts[] = ontologyUri.split("/"); String name = parts[parts.length-1]; ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase(); - String version = schema.getVersion(); - if (version == null) - version = "1.0"; - for (String s : converter.getHeader()) { writer.println(commentTag + " " + s); } @@ -100,32 +95,13 @@ public class OntologyGenerator extends SchemaConversionBase { writer.println("L0 = "); writer.println("XML = "); writer.println(); - writer.println(ontRoot + " = <" + ontologyName +"-"+ version+"> : L0.Ontology"); + writer.println(ontRoot + " = <" + ontologyUri +"> : L0.Ontology"); writer.println(" @L0.new"); writer.println(" L0.HasResourceClass \"" + className +"\""); writer.println(); writer.println(); ontRoot += "."; - // TODO : these could be created in separate base ontology. -// writer.println(commentTag + " Built-in types"); -// writer.println(); -// writer.println(ontRoot+"XML : L0.Library"); -// writer.println(ontRoot+"XML.hasAttribute L0.String"); -// writer.println(ontRoot+"XML.ComplexType 0) { @@ -251,7 +229,6 @@ public class OntologyGenerator extends SchemaConversionBase { @Override - //protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, QName refType) { protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) { if (refType != refType.Element) { QName referenceType = null; @@ -442,10 +419,8 @@ public class OntologyGenerator extends SchemaConversionBase { @Override protected void handleComplexType(SchemaObject topLevelComplexType) { String name = getName(topLevelComplexType); - if (name.contains("Pcurve")) - System.out.println(); -// if (parent != null) -// name = parent +"_"+name; +// if (topLevelComplexType.getName().equals("Reference")) +// System.out.println(); String relationName = ontRoot+getName(topLevelComplexType,"has");//ontRoot+"has"+name; diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java index d80f94c..5df8c4a 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java @@ -38,6 +38,7 @@ import org.w3._2001.xmlschema.NamedAttributeGroup; import org.w3._2001.xmlschema.OpenAttrs; import org.w3._2001.xmlschema.Restriction; import org.w3._2001.xmlschema.Schema; +import org.w3._2001.xmlschema.SimpleContent; import org.w3._2001.xmlschema.SimpleType; import org.w3._2001.xmlschema.TopLevelAttribute; import org.w3._2001.xmlschema.TopLevelComplexType; @@ -265,6 +266,23 @@ public abstract class SchemaConversionBase { throw new RuntimeException("Groups not supported"); } } + if (ct.getSimpleContent() != null) { + SimpleContent cc = ct.getSimpleContent(); + ExtensionType extensionType = cc.getExtension(); + if (extensionType != null) { + if (extensionType.getChoice() != null) { + preload(object,extensionType.getChoice(), stack); + } + if (extensionType.getSequence()!= null) { + preload(object,extensionType.getSequence(), stack); + } + if (extensionType.getAll()!= null) { + preload(object,extensionType.getAll(), stack); + } + if (extensionType.getGroup() != null) + throw new RuntimeException("Groups not supported"); + } + } } else if (object.getType() == ObjectType.ELEMENT) { Element e = object.getElement(); if (e instanceof TopLevelElement) @@ -330,6 +348,14 @@ public abstract class SchemaConversionBase { return type; } } +// SimpleContent simpleContent = complexType.getSimpleContent(); +// if (simpleContent != null) { +// ExtensionType extensionType = simpleContent.getExtension(); +// if (extensionType != null) { +// QName type = extensionType.getBase(); +// return type; +// } +// } return null; } @@ -385,6 +411,13 @@ public abstract class SchemaConversionBase { handleAttributes(complexType, extensionType.getAttributeOrAttributeGroup()); } } + SimpleContent simpleContent = complexType.getComplexType().getSimpleContent(); + if (simpleContent != null) { + ExtensionType extensionType = simpleContent.getExtension(); + if (extensionType != null) { + handleAttributes(complexType, extensionType.getAttributeOrAttributeGroup()); + } + } } @@ -696,6 +729,10 @@ public abstract class SchemaConversionBase { } } } +// SimpleContent simpleContent = complexType.getSimpleContent(); +// if (simpleContent != null) { +// ExtensionType extensionType = simpleContent.getExtension(); +// } } } @@ -713,28 +750,15 @@ public abstract class SchemaConversionBase { protected boolean isElementRef(String ref) { -// for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) { -// if (attrs instanceof TopLevelElement) { -// TopLevelElement element = (TopLevelElement)attrs; -// if (ref.equals(element.getName())) -// return true; -// } -// } -// return false; return elementName.containsKey(ref); } protected boolean isComplexTypeRef(String ref) { -// for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) { -// if (attrs instanceof TopLevelComplexType) { -// TopLevelComplexType element = (TopLevelComplexType)attrs; -// if (ref.equals(element.getName())) -// return true; -// } -// } -// return false; return complexTypeName.containsKey(ref); - + } + + protected boolean isSimpleTypeRef(String ref) { + return simpleTypeName.containsKey(ref); } protected NamedAttributeGroup getAttributeGroup(String name) { 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 32ae167..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 @@ -102,36 +102,42 @@ public class SchemaConverter { header[3] = "Date " + new Date().toString(); - String ontologyName = schema.getTargetNamespace(); - if (ontologyName == null) { - ontologyName = getSchemaFile().getName(); + String ontologyUri = schema.getTargetNamespace(); + if (ontologyUri == null) { + ontologyUri = getSchemaFile().getName(); - int index = ontologyName.lastIndexOf("."); + int index = ontologyUri.lastIndexOf("."); if (index > 0) - ontologyName = ontologyName.substring(0, index); + ontologyUri = ontologyUri.substring(0, index); } - if (!ontologyName.startsWith("http")) - ontologyName = "http://" + ontologyName; - String parts[] = ontologyName.split("/"); + ontologyUri = ontologyUri.replaceAll(" ", "_"); + String parts[] = ontologyUri.split("/"); String name = parts[parts.length-1]; - //String ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase(); + 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; - name = name.replaceAll("\\.", "_"); - name = name.replaceAll(" ", "_"); String className = getPluginName() + "." + name; if (createPGraph) { OntologyGenerator ontologyGenerator = new OntologyGenerator(configuration); - ontologyGenerator.createOntology(schema, ontologyName, className, this); + ontologyGenerator.createOntology(schema, ontologyUri, className, this); } if (createImporter) { ImporterGenerator importerGenerator = new ImporterGenerator(configuration); - importerGenerator.createParser(schema, className, this); + importerGenerator.createParser(schema, ontologyUri, className, this); } if (createExporter) { ExporterGenerator exporterGenerator = new ExporterGenerator(configuration); - exporterGenerator.createParser(schema, className, this); + exporterGenerator.createParser(schema, ontologyUri,className, this); } } -- 2.45.2