]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Handling ComplexTypes defined with SimpleContent
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 25 Jan 2017 16:47:47 +0000 (16:47 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 12:01:35 +0000 (14:01 +0200)
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/src/org/simantics/xml/sax/base/XMLWriter.java
org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java

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