]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Several updates to interoperability. 63/463/2
authorReino Ruusu <reino.ruusu@vtt.fi>
Tue, 25 Apr 2017 20:28:26 +0000 (23:28 +0300)
committerReino Ruusu <reino.ruusu@vtt.fi>
Tue, 2 May 2017 14:39:19 +0000 (17:39 +0300)
Declaration of simpleTypes as literal types.
Support for value elements with simple datatypes.
Fixed Base64 support.
Improved support for choice indicators.
Fixes for schemas without target namespace.
Generation of empty string literals for empty elements.

Change-Id: I8ae3b4fa47690c7c58df5a44eaf3191cc13f1fa2

12 files changed:
org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java
org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ValueElementWriter.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java
org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.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/SchemaConversionComponent.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java

index af298319bee16eb3447a7b99c54295c8fe04d635..c8445bef770f2222b81327841faf1ef616e9ab59 100644 (file)
@@ -1,91 +1,91 @@
-package org.simantics.interop.stubs;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-public class InteropResource {\r
-    \r
-    public final Resource HasDestination;\r
-    public final Resource HasGeneratorID;\r
-    public final Resource HasGeneratorID_Inverse;\r
-    public final Resource HasImportData;\r
-    public final Resource HasInputResource;\r
-    public final Resource HasSource;\r
-    public final Resource INodeType;\r
-    public final Resource ImportDataOf;\r
-    public final Resource ImportLibrary;\r
-    public final Resource InteropBrowseContext;\r
-    public final Resource InteropBrowseContext_InteropChildRule;\r
-    public final Resource InteropBrowseContext_InteropNode;\r
-        \r
-    public static class URIs {\r
-        public static final String HasDestination = "http://www.simantics.org/Interop-1.0/HasDestination";\r
-        public static final String HasGeneratorID = "http://www.simantics.org/Interop-1.0/HasGeneratorID";\r
-        public static final String HasGeneratorID_Inverse = "http://www.simantics.org/Interop-1.0/HasGeneratorID/Inverse";\r
-        public static final String HasImportData = "http://www.simantics.org/Interop-1.0/HasImportData";\r
-        public static final String HasInputResource = "http://www.simantics.org/Interop-1.0/HasInputResource";\r
-        public static final String HasSource = "http://www.simantics.org/Interop-1.0/HasSource";\r
-        public static final String INodeType = "http://www.simantics.org/Interop-1.0/INodeType";\r
-        public static final String ImportDataOf = "http://www.simantics.org/Interop-1.0/ImportDataOf";\r
-        public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary";\r
-        public static final String InteropBrowseContext = "http://www.simantics.org/Interop-1.0/InteropBrowseContext";\r
-        public static final String InteropBrowseContext_InteropChildRule = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropChildRule";\r
-        public static final String InteropBrowseContext_InteropNode = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropNode";\r
-    }\r
-    \r
-    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
-        try {\r
-            return graph.getResource(uri);\r
-        } catch(DatabaseException e) {\r
-            System.err.println(e.getMessage());\r
-            return null;\r
-        }\r
-    }\r
-    \r
-    public InteropResource(ReadGraph graph) {\r
-        HasDestination = getResourceOrNull(graph, URIs.HasDestination);\r
-        HasGeneratorID = getResourceOrNull(graph, URIs.HasGeneratorID);\r
-        HasGeneratorID_Inverse = getResourceOrNull(graph, URIs.HasGeneratorID_Inverse);\r
-        HasImportData = getResourceOrNull(graph, URIs.HasImportData);\r
-        HasInputResource = getResourceOrNull(graph, URIs.HasInputResource);\r
-        HasSource = getResourceOrNull(graph, URIs.HasSource);\r
-        INodeType = getResourceOrNull(graph, URIs.INodeType);\r
-        ImportDataOf = getResourceOrNull(graph, URIs.ImportDataOf);\r
-        ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);\r
-        InteropBrowseContext = getResourceOrNull(graph, URIs.InteropBrowseContext);\r
-        InteropBrowseContext_InteropChildRule = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropChildRule);\r
-        InteropBrowseContext_InteropNode = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropNode);\r
-    }\r
-    \r
-    public static InteropResource getInstance(ReadGraph graph) {\r
-        Session session = graph.getSession();\r
-        InteropResource ret = session.peekService(InteropResource.class);\r
-        if(ret == null) {\r
-            QueryControl qc = graph.getService(QueryControl.class);\r
-            ret = new InteropResource(qc.getIndependentGraph(graph));\r
-            session.registerService(InteropResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-    public static InteropResource getInstance(RequestProcessor session) throws DatabaseException {\r
-        InteropResource ret = session.peekService(InteropResource.class);\r
-        if(ret == null) {\r
-            ret = session.syncRequest(new Read<InteropResource>() {\r
-                public InteropResource perform(ReadGraph graph) throws DatabaseException {\r
-                    QueryControl qc = graph.getService(QueryControl.class);\r
-                    return new InteropResource(qc.getIndependentGraph(graph));\r
-                }\r
-            });\r
-            session.registerService(InteropResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-}\r
-\r
+package org.simantics.interop.stubs;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.request.Read;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.QueryControl;
+
+public class InteropResource {
+    
+    public final Resource HasDestination;
+    public final Resource HasGeneratorID;
+    public final Resource HasGeneratorID_Inverse;
+    public final Resource HasImportData;
+    public final Resource HasInputResource;
+    public final Resource HasSource;
+    public final Resource INodeType;
+    public final Resource ImportDataOf;
+    public final Resource ImportLibrary;
+    public final Resource InteropBrowseContext;
+    public final Resource InteropBrowseContext_InteropChildRule;
+    public final Resource InteropBrowseContext_InteropNode;
+        
+    public static class URIs {
+        public static final String HasDestination = "http://www.simantics.org/Interop-1.0/HasDestination";
+        public static final String HasGeneratorID = "http://www.simantics.org/Interop-1.0/HasGeneratorID";
+        public static final String HasGeneratorID_Inverse = "http://www.simantics.org/Interop-1.0/HasGeneratorID/Inverse";
+        public static final String HasImportData = "http://www.simantics.org/Interop-1.0/HasImportData";
+        public static final String HasInputResource = "http://www.simantics.org/Interop-1.0/HasInputResource";
+        public static final String HasSource = "http://www.simantics.org/Interop-1.0/HasSource";
+        public static final String INodeType = "http://www.simantics.org/Interop-1.0/INodeType";
+        public static final String ImportDataOf = "http://www.simantics.org/Interop-1.0/ImportDataOf";
+        public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary";
+        public static final String InteropBrowseContext = "http://www.simantics.org/Interop-1.0/InteropBrowseContext";
+        public static final String InteropBrowseContext_InteropChildRule = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropChildRule";
+        public static final String InteropBrowseContext_InteropNode = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropNode";
+    }
+    
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {
+        try {
+            return graph.getResource(uri);
+        } catch(DatabaseException e) {
+            System.err.println(e.getMessage());
+            return null;
+        }
+    }
+    
+    public InteropResource(ReadGraph graph) {
+        HasDestination = getResourceOrNull(graph, URIs.HasDestination);
+        HasGeneratorID = getResourceOrNull(graph, URIs.HasGeneratorID);
+        HasGeneratorID_Inverse = getResourceOrNull(graph, URIs.HasGeneratorID_Inverse);
+        HasImportData = getResourceOrNull(graph, URIs.HasImportData);
+        HasInputResource = getResourceOrNull(graph, URIs.HasInputResource);
+        HasSource = getResourceOrNull(graph, URIs.HasSource);
+        INodeType = getResourceOrNull(graph, URIs.INodeType);
+        ImportDataOf = getResourceOrNull(graph, URIs.ImportDataOf);
+        ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);
+        InteropBrowseContext = getResourceOrNull(graph, URIs.InteropBrowseContext);
+        InteropBrowseContext_InteropChildRule = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropChildRule);
+        InteropBrowseContext_InteropNode = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropNode);
+    }
+    
+    public static InteropResource getInstance(ReadGraph graph) {
+        Session session = graph.getSession();
+        InteropResource ret = session.peekService(InteropResource.class);
+        if(ret == null) {
+            QueryControl qc = graph.getService(QueryControl.class);
+            ret = new InteropResource(qc.getIndependentGraph(graph));
+            session.registerService(InteropResource.class, ret);
+        }
+        return ret;
+    }
+    
+    public static InteropResource getInstance(RequestProcessor session) throws DatabaseException {
+        InteropResource ret = session.peekService(InteropResource.class);
+        if(ret == null) {
+            ret = session.syncRequest(new Read<InteropResource>() {
+                public InteropResource perform(ReadGraph graph) throws DatabaseException {
+                    QueryControl qc = graph.getService(QueryControl.class);
+                    return new InteropResource(qc.getIndependentGraph(graph));
+                }
+            });
+            session.registerService(InteropResource.class, ret);
+        }
+        return ret;
+    }
+    
+}
+
index e3251ac07f2756b42224e76c9eb3a664edeb03c5..3bd21b51b1cb3d0dd2f440d6467c87e954dd0af7 100644 (file)
@@ -28,6 +28,14 @@ public class TypeComparator extends ResourceComparator {
        ArrayList<Resource> rs1 = new ArrayList<Resource>();\r
        ArrayList<Resource> rs2 = new ArrayList<Resource>();\r
        \r
+       @Override\r
+       public int compare(ReadGraph g, Resource o1, Resource o2, boolean local) throws DatabaseException {\r
+               if (local)\r
+                       return new TypeComparator().compare(g, o1, o2);\r
+               else\r
+                       return compare(g, o1, o2);\r
+       }\r
+       \r
        @Override\r
        public int compare(ReadGraph g, Resource o1, Resource o2) throws DatabaseException{\r
                if (!compareType(g,o1, o2)) {\r
index 42aa3c16a3af32f4178dec1dfebdf561b0de372e..3035ae81c27f0888395710a7b3a8a49a2144b8fe 100644 (file)
@@ -1,8 +1,6 @@
 package org.simantics.xml.sax.base;\r
 \r
 import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
 import java.util.Set;\r
 \r
 import javax.xml.stream.XMLStreamException;\r
@@ -13,9 +11,8 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.Statement;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
 \r
-public class ValueElementWriter implements XMLElementWriter{\r
+public abstract class ValueElementWriter implements XMLElementWriter{\r
        \r
        String name;\r
        Binding binding;\r
@@ -61,36 +58,13 @@ public class ValueElementWriter implements XMLElementWriter{
                \r
        }\r
        \r
+       public abstract String decode(Object value);\r
+       \r
        @Override\r
        public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
                        throws XMLStreamException, DatabaseException {\r
-                       Layer0 l0 = Layer0.getInstance(graph);\r
                Object value = graph.getValue(instance.getResource(), binding);\r
-               writer.writeCharacters(value.toString());\r
-//             if (binding == Bindings.STRING) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.String);\r
-//                     graph.claimValue(element.getData(), string, binding);\r
-//             } else if (binding == Bindings.INTEGER) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Integer);\r
-//                     graph.claimValue(element.getData(), Integer.parseInt(string), binding);\r
-//             } else if (binding == Bindings.FLOAT) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Float);\r
-//                     graph.claimValue(element.getData(), Float.parseFloat(string), binding);\r
-//             } else if (binding == Bindings.DOUBLE) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Double);\r
-//                     graph.claimValue(element.getData(), Double.parseDouble(string), binding);\r
-//             } else if (binding == Bindings.BOOLEAN) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Boolean);\r
-//                     graph.claimValue(element.getData(), Boolean.parseBoolean(string), binding);\r
-//             } else if (binding == Bindings.LONG) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Long);\r
-//                     graph.claimValue(element.getData(), Long.parseLong(string), binding);\r
-//             } else if (binding == Bindings.BYTE) {\r
-//                     graph.claim(element.getData(), l0.InstanceOf, l0.Byte);\r
-//                     graph.claimValue(element.getData(), Byte.parseByte(string), binding);\r
-//             } else {\r
-//                     throw new DatabaseException("Unknown datatype " + binding);\r
-//             }\r
+               writer.writeCharacters(decode(value));\r
        }\r
 \r
 }\r
index 01b8deba7b3ad341cba064836ab78417977bf62f..9c04001477ce22e7d3e23934d21936f5c7a54d54 100644 (file)
@@ -247,8 +247,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
                        e = current.pop();\r
                }\r
                if (e != null) {\r
-                       if (charactersValue.length() > 0)\r
-                               handleCharacters(e, charactersValue.toString());\r
+                       handleCharacters(e, charactersValue.toString());\r
                        handleElement(current,e);\r
                }\r
                if (current.isEmpty()) {\r
index 01b5156048a55eee110c6faaf2fd23e9cc06d7f6..1bb9dbb8270da8695fc82852cabcb67b4ea6a8e5 100644 (file)
-package org.simantics.xml.sax.ontology;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-public class XMLResource {\r
-    \r
-    public final Resource AttributeGroup;\r
-    public final Resource ComplexType;\r
-    public final Resource Date;\r
-    public final Resource DateTime;\r
-    public final Resource Element;\r
-    public final Resource ElementList;\r
-    public final Resource Entity;\r
-    public final Resource Time;\r
-    public final Resource externalReferenceOf;\r
-    public final Resource hasAttribute;\r
-    public final Resource hasAttribute_Inverse;\r
-    public final Resource hasComplexType;\r
-    public final Resource hasComplexType_Inverse;\r
-    public final Resource hasElement;\r
-    public final Resource hasElementList;\r
-    public final Resource hasElementList_Inverse;\r
-    public final Resource hasElement_Inverse;\r
-    public final Resource hasExternalReference;\r
-    public final Resource hasID;\r
-    public final Resource hasID_Inverse;\r
-    public final Resource hasOriginalElementList;\r
-    public final Resource hasOriginalElementList_Inverse;\r
-    public final Resource hasReference;\r
-        \r
-    public static class URIs {\r
-        public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup";\r
-        public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType";\r
-        public static final String Date = "http://www.simantics.org/XML-1.0/Date";\r
-        public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";\r
-        public static final String Element = "http://www.simantics.org/XML-1.0/Element";\r
-        public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";\r
-        public static final String Entity = "http://www.simantics.org/XML-1.0/Entity";\r
-        public static final String Time = "http://www.simantics.org/XML-1.0/Time";\r
-        public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";\r
-        public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";\r
-        public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse";\r
-        public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType";\r
-        public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse";\r
-        public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement";\r
-        public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList";\r
-        public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse";\r
-        public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse";\r
-        public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference";\r
-        public static final String hasID = "http://www.simantics.org/XML-1.0/hasID";\r
-        public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse";\r
-        public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList";\r
-        public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse";\r
-        public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference";\r
-    }\r
-    \r
-    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
-        try {\r
-            return graph.getResource(uri);\r
-        } catch(DatabaseException e) {\r
-            System.err.println(e.getMessage());\r
-            return null;\r
-        }\r
-    }\r
-    \r
-    public XMLResource(ReadGraph graph) {\r
-        AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup);\r
-        ComplexType = getResourceOrNull(graph, URIs.ComplexType);\r
-        Date = getResourceOrNull(graph, URIs.Date);\r
-        DateTime = getResourceOrNull(graph, URIs.DateTime);\r
-        Element = getResourceOrNull(graph, URIs.Element);\r
-        ElementList = getResourceOrNull(graph, URIs.ElementList);\r
-        Entity = getResourceOrNull(graph, URIs.Entity);\r
-        Time = getResourceOrNull(graph, URIs.Time);\r
-        externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);\r
-        hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);\r
-        hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse);\r
-        hasComplexType = getResourceOrNull(graph, URIs.hasComplexType);\r
-        hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse);\r
-        hasElement = getResourceOrNull(graph, URIs.hasElement);\r
-        hasElementList = getResourceOrNull(graph, URIs.hasElementList);\r
-        hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse);\r
-        hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse);\r
-        hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference);\r
-        hasID = getResourceOrNull(graph, URIs.hasID);\r
-        hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse);\r
-        hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList);\r
-        hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse);\r
-        hasReference = getResourceOrNull(graph, URIs.hasReference);\r
-    }\r
-    \r
-    public static XMLResource getInstance(ReadGraph graph) {\r
-        Session session = graph.getSession();\r
-        XMLResource ret = session.peekService(XMLResource.class);\r
-        if(ret == null) {\r
-            QueryControl qc = graph.getService(QueryControl.class);\r
-            ret = new XMLResource(qc.getIndependentGraph(graph));\r
-            session.registerService(XMLResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-    public static XMLResource getInstance(RequestProcessor session) throws DatabaseException {\r
-        XMLResource ret = session.peekService(XMLResource.class);\r
-        if(ret == null) {\r
-            ret = session.syncRequest(new Read<XMLResource>() {\r
-                public XMLResource perform(ReadGraph graph) throws DatabaseException {\r
-                    QueryControl qc = graph.getService(QueryControl.class);\r
-                    return new XMLResource(qc.getIndependentGraph(graph));\r
-                }\r
-            });\r
-            session.registerService(XMLResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-}\r
-\r
+package org.simantics.xml.sax.ontology;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.request.Read;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.QueryControl;
+
+public class XMLResource {
+    
+    public final Resource AttributeGroup;
+    public final Resource ComplexType;
+    public final Resource Date;
+    public final Resource DateTime;
+    public final Resource Element;
+    public final Resource ElementList;
+    public final Resource Entity;
+    public final Resource Time;
+    public final Resource externalReferenceOf;
+    public final Resource hasAttribute;
+    public final Resource hasAttribute_Inverse;
+    public final Resource hasComplexType;
+    public final Resource hasComplexType_Inverse;
+    public final Resource hasElement;
+    public final Resource hasElementList;
+    public final Resource hasElementList_Inverse;
+    public final Resource hasElement_Inverse;
+    public final Resource hasExternalReference;
+    public final Resource hasID;
+    public final Resource hasID_Inverse;
+    public final Resource hasOriginalElementList;
+    public final Resource hasOriginalElementList_Inverse;
+    public final Resource hasReference;
+        
+    public static class URIs {
+        public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup";
+        public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType";
+        public static final String Date = "http://www.simantics.org/XML-1.0/Date";
+        public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";
+        public static final String Element = "http://www.simantics.org/XML-1.0/Element";
+        public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";
+        public static final String Entity = "http://www.simantics.org/XML-1.0/Entity";
+        public static final String Time = "http://www.simantics.org/XML-1.0/Time";
+        public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";
+        public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";
+        public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse";
+        public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType";
+        public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse";
+        public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement";
+        public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList";
+        public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse";
+        public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse";
+        public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference";
+        public static final String hasID = "http://www.simantics.org/XML-1.0/hasID";
+        public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse";
+        public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList";
+        public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse";
+        public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference";
+    }
+    
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {
+        try {
+            return graph.getResource(uri);
+        } catch(DatabaseException e) {
+            System.err.println(e.getMessage());
+            return null;
+        }
+    }
+    
+    public XMLResource(ReadGraph graph) {
+        AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup);
+        ComplexType = getResourceOrNull(graph, URIs.ComplexType);
+        Date = getResourceOrNull(graph, URIs.Date);
+        DateTime = getResourceOrNull(graph, URIs.DateTime);
+        Element = getResourceOrNull(graph, URIs.Element);
+        ElementList = getResourceOrNull(graph, URIs.ElementList);
+        Entity = getResourceOrNull(graph, URIs.Entity);
+        Time = getResourceOrNull(graph, URIs.Time);
+        externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);
+        hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);
+        hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse);
+        hasComplexType = getResourceOrNull(graph, URIs.hasComplexType);
+        hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse);
+        hasElement = getResourceOrNull(graph, URIs.hasElement);
+        hasElementList = getResourceOrNull(graph, URIs.hasElementList);
+        hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse);
+        hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse);
+        hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference);
+        hasID = getResourceOrNull(graph, URIs.hasID);
+        hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse);
+        hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList);
+        hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse);
+        hasReference = getResourceOrNull(graph, URIs.hasReference);
+    }
+    
+    public static XMLResource getInstance(ReadGraph graph) {
+        Session session = graph.getSession();
+        XMLResource ret = session.peekService(XMLResource.class);
+        if(ret == null) {
+            QueryControl qc = graph.getService(QueryControl.class);
+            ret = new XMLResource(qc.getIndependentGraph(graph));
+            session.registerService(XMLResource.class, ret);
+        }
+        return ret;
+    }
+    
+    public static XMLResource getInstance(RequestProcessor session) throws DatabaseException {
+        XMLResource ret = session.peekService(XMLResource.class);
+        if(ret == null) {
+            ret = session.syncRequest(new Read<XMLResource>() {
+                public XMLResource perform(ReadGraph graph) throws DatabaseException {
+                    QueryControl qc = graph.getService(QueryControl.class);
+                    return new XMLResource(qc.getIndependentGraph(graph));
+                }
+            });
+            session.registerService(XMLResource.class, ret);
+        }
+        return ret;
+    }
+    
+}
+
index dc82a9fdf16542e8923d156deb42e0f539268d80..121a6352b8e73401ad894c00b90add2e29083c7d 100644 (file)
@@ -337,17 +337,21 @@ public class ExporterGenerator extends JavaGenerator{
        }\r
        \r
        @Override\r
-       protected void createPrimitiveIndicator(SchemaObject parent, String refName, String binding) {\r
+       protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {\r
                FileWriter fw = getWriter(parent);\r
-               //SchemaObject refElement = elementName.get(refType.getLocalPart());\r
-               //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " +  ontShort+".hasElement");\r
-               fw.writer.println("        addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");\r
+               String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());\r
+               String typeURI = ontologyClassName != null ? ontologyClassName + ".URIs." + getName(base.getSimpleType(typeName)) : "null";\r
+               \r
+               fw.writer.println("      addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");\r
                \r
                fw.delayedWriter2.println("   public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
                fw.delayedWriter2.println("      public "+ getName(parent) +"_" +refName +"(){");\r
-               //fw.delayedWriter2.println("           super(\""+ref+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+ref+", "+binding+");");\r
-               fw.delayedWriter2.println("           super(\""+refName+"\",null, "+binding+");");\r
-               fw.delayedWriter2.println("       }");\r
+               fw.delayedWriter2.println("         super(\""+refName+"\", " + typeURI + ", " + typeEntry.binding+");");\r
+               fw.delayedWriter2.println("      }\n");\r
+               fw.delayedWriter2.println("      @Override");\r
+               fw.delayedWriter2.println("      public String decode(Object value) {");\r
+               fw.delayedWriter2.println("         return " + typeEntry.stringPrefix + "(" + typeEntry.javaType + ")value" + typeEntry.stringPostfix + ";");\r
+               fw.delayedWriter2.println("      }");\r
                fw.delayedWriter2.println("   }");\r
        }\r
        \r
index f1076b80bda639560696b04eff3a3db08c896466..ba1eff9cc261e62331fb1b865c25783785aec6c2 100644 (file)
@@ -199,10 +199,10 @@ public class ImporterGenerator extends JavaGenerator{
                fw.writer.println("   @Override");
                fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");
                if (inheritance.type == InheritanceType.ComplexType) {
-               fw.writer.println("             super.configure(graph,parents,element);");
+               fw.writer.println("      super.configure(graph,parents,element);");
                }
-               fw.writer.println("        "+getOntologyImport());
-               
+               fw.writer.println("      "+getOntologyImport());
+               fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");
                this.base.handleComplexTypeAttributes(complexTypeObj);
                this.base.handleExtensionAttributes(complexTypeObj);
                
@@ -279,14 +279,30 @@ public class ImporterGenerator extends JavaGenerator{
        }
        
        @Override
-       protected void createPrimitiveIndicator(SchemaObject parent, String refName, String binding) {
+       protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {
                FileWriter fw = getWriter(parent);
-               fw.writer.println("        addParser(\""+ refName +"\", "+getName(parent) +"_" +refName+".class);");
+               String className = getName(parent) +"_" +refName;
+               fw.writer.println("        addParser(\"" + refName + "\", " + className  + ".class);");
+               fw.delayedWriter2.println("   public static class " + className + " extends org.simantics.xml.sax.base.ValueElementParser {");
+               fw.delayedWriter2.println("      public "+ className +"(){");
+               fw.delayedWriter2.println("         super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+typeEntry.binding+");");
+               fw.delayedWriter2.println("      }\n");
+               fw.delayedWriter2.println("      @Override");
+               fw.delayedWriter2.println("      public void configure(WriteGraph graph, ParserElement element, String value)   throws DatabaseException {");
+               fw.delayedWriter2.println("         Layer0 L0 = Layer0.getInstance(graph);");
+
+               SchemaObject simpleType = base.getSimpleType(typeName);
+               String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());
+               if (ontologyClassName != null && simpleType != null) 
+                       fw.delayedWriter2.println("         graph.claim(element.getData(), L0.InstanceOf, " + ontologyClassName + ".getInstance(graph)." + getName(simpleType, "") + ");");
+               else {
+                       if (typeEntry.l0Type.startsWith("XML"))
+                               fw.delayedWriter2.println("         XMLResource XML = XMLResource.getInstance(graph);");
+                       fw.delayedWriter2.println("         graph.claim(element.getData(), L0.InstanceOf, " + typeEntry.l0Type + ");");
+               }
                
-               fw.delayedWriter2.println("   public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementParser {");
-               fw.delayedWriter2.println("      public "+ getName(parent) +"_" +refName +"(){");
-               fw.delayedWriter2.println("           super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+binding+");");
-               fw.delayedWriter2.println("       }");
+               fw.delayedWriter2.println("         graph.claimValue(element.getData(), " +getValueGetter(typeEntry) + ", " + typeEntry.binding + ");");
+               fw.delayedWriter2.println("      }");
                fw.delayedWriter2.println("   }");
        }
        
@@ -386,7 +402,7 @@ public class ImporterGenerator extends JavaGenerator{
                        TypeEntry binding = this.base.getTypeEntry(primitiveType);
                        
                        if (binding != null) {
-                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                               writeAttribute(fw, attrName, relationName, binding, isReference, primitiveType);
                                return;
                    } else {
                        if (simpleType == null) {
@@ -399,8 +415,9 @@ public class ImporterGenerator extends JavaGenerator{
                if (simpleType != null) {
                        org.w3._2001.xmlschema.List list = simpleType.getList();
                        if (list != null) {
-                               TypeEntry binding = this.base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
-                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                               QName typeName = new QName(SchemaConversionBase.SCHEMA_NS, "string");
+                               TypeEntry binding = this.base.getTypeEntry(typeName);
+                               writeAttribute(fw, attrName, relationName, binding, isReference, typeName);
                        } else {
 //                             Restriction restriction = simpleType.getRestriction();
 //                             if (restriction == null)
@@ -411,22 +428,24 @@ public class ImporterGenerator extends JavaGenerator{
                                
                                //String binding = getBindingFromPrimitiveType(base);
                                TypeEntry binding = this.base.getTypeEntry(base);
-                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                               writeAttribute(fw, attrName, relationName, binding, isReference, base);
                        }
                } else {
                        // TODO : using default String attribute should be configured with rules.
                        //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());
                        fw.writer.println("    //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");
                        //writeAttribute(fw, attrName, relationName, "STRING", isReference);
-                       writeAttribute(fw, attrName, relationName, this.base.getTypeEntry("string"), isReference);
+                       writeAttribute(fw, attrName, relationName, this.base.getTypeEntry("string"), isReference, new QName(SchemaConversionBase.SCHEMA_NS, "string"));
                }
        }
        
-       private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {
+       private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference, QName typeName) {
+               String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());
+               String ontologyType = ontologyClassName != null ? ontologyClassName + ".getInstance(graph)." + getName(base.getSimpleType(typeName)) : binding.l0Type; 
                fw.writer.println("      {");
                fw.writer.println("         Attribute a = element.getAttribute(\"" +attrName+"\");");
                fw.writer.println("         if (a != null) {");
-               fw.writer.println("            graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");
+               fw.writer.println("            graph.claimLiteral(element.getData(), " + relationName + ", " + ontologyType + ", " + getValueGetterMethod(binding,"a") + ", " + binding.binding + ");");
                if (isReference)
                fw.writer.println("            idProviderValue = a.getValue();");       
                fw.writer.println("         }");
@@ -589,9 +608,11 @@ public class ImporterGenerator extends JavaGenerator{
                fw.writer.println("   @Override");
                fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");
                if (inheritance.type == InheritanceType.ComplexType) {
-               fw.writer.println("             super.configure(graph,parents,element);");
+               fw.writer.println("      super.configure(graph,parents,element);");
                }
-               fw.writer.println("        "+getOntologyImport());
+               fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");
+               fw.writer.println("      XMLResource XML = XMLResource.getInstance(graph);");
+               fw.writer.println("      "+getOntologyImport());
                
                LocalComplexType complexType = element.getComplexType();
                LocalSimpleType simpleType = element.getSimpleType();
index 72b2956a7016073ee910d04d700bccf5a19892f1..4869e0711e073297f01c390aac96849dcf9d6be3 100644 (file)
@@ -10,6 +10,7 @@ import java.util.Map;
 \r
 import javax.xml.namespace.QName;\r
 \r
+import org.simantics.xml.sax.SchemaConversionBase.Inheritance;\r
 import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
 import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;\r
 import org.w3._2001.xmlschema.AttributeGroupRef;\r
@@ -80,6 +81,11 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
                return binding.getValueGetter();\r
        }\r
        \r
+       @Override\r
+       public String getSimpleTypePrefix() {\r
+               return "SimpleTypes_";\r
+       }       \r
+       \r
        @Override\r
        public String getComplexTypePrefix() {\r
                return "ComplexTypes_";\r
@@ -91,22 +97,24 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
        }\r
        \r
        @Override\r
-       public void handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name) {\r
-\r
-               for (SchemaElement e : elements) {\r
-                       Element localElement = e.getElement();\r
-                       if (localElement.getName() != null) {\r
-                               QName refType = localElement.getType();\r
-                               if (refType != null)\r
-                                       //handleIndicator(parent, indicator, e, false, name, refType);\r
-                                       handleIndicator(parent, indicator, e, name, RefType.Type);\r
-                       } else if (localElement.getRef() != null) {\r
-                               //QName refType = localElement.getRef();\r
-                               //handleIndicator(parent, indicator, e, true, name, refType);\r
-                               handleIndicator(parent, indicator, e, name, RefType.Reference);\r
-                       }\r
-               }\r
+       public String handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name) {\r
+               String baseRelationName = getName(parent) + ".has" + name;\r
+               \r
+//             for (SchemaElement e : elements) {\r
+//                     Element localElement = e.getElement();\r
+//                     if (localElement.getName() != null) {\r
+//                             QName refType = localElement.getType();\r
+//                             if (refType != null)\r
+//                                     //handleIndicator(parent, indicator, e, false, name, refType);\r
+//                                     handleIndicator(parent, indicator, e, name, RefType.Type, baseRelationName);\r
+//                     } else if (localElement.getRef() != null) {\r
+//                             //QName refType = localElement.getRef();\r
+//                             //handleIndicator(parent, indicator, e, true, name, refType);\r
+//                             handleIndicator(parent, indicator, e, name, RefType.Reference, baseRelationName);\r
+//                     }\r
+//             }\r
                \r
+               return baseRelationName;\r
        }\r
        \r
        protected String getOntologyImport() {\r
@@ -142,7 +150,7 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:\r
                                return getAttributeGroupPrefix()+obj.getName();\r
                        case SIMPLE_TYPE:\r
-                               return obj.getName();\r
+                               return getSimpleTypePrefix()+obj.getName();\r
                        }\r
                } else {\r
                        SchemaObject o = obj;\r
@@ -165,7 +173,7 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:\r
                                return getAttributeGroupPrefix()+name;\r
                        case SIMPLE_TYPE:\r
-                               return name;\r
+                               return getSimpleTypePrefix()+name;\r
                        }\r
                }\r
                throw new RuntimeException();\r
@@ -182,7 +190,7 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:\r
                                return getAttributeGroupPrefix()+rel+obj.getName();\r
                        case SIMPLE_TYPE:\r
-                               return rel+obj.getName();\r
+                               return getSimpleTypePrefix()+rel+obj.getName();\r
                        }\r
                } else {\r
                        SchemaObject o = obj;\r
@@ -203,7 +211,7 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:\r
                                return getAttributeGroupPrefix()+rel+name;\r
                        case SIMPLE_TYPE:\r
-                               return rel+name;\r
+                               return getSimpleTypePrefix()+rel+name;\r
                        }\r
                }\r
                throw new RuntimeException();\r
@@ -236,49 +244,60 @@ public abstract class JavaGenerator implements SchemaConversionComponent {
        \r
        \r
        protected abstract void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName, String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList);\r
-       protected abstract void createPrimitiveIndicator(SchemaObject parent, String refName, String binding);\r
+       protected abstract void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName);\r
        protected abstract void createElementIndicator(SchemaObject parent, boolean useElementList, String refName, String className, boolean useOriginalList);\r
        \r
        @Override\r
-       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType) {\r
+       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType, String baseRelationName) {\r
                String objectName;\r
                if (referenceType != RefType.Element) {\r
-                       QName refType;\r
+                       QName refTypeName;\r
+                       SchemaObject refObject = null;\r
                        if (referenceType == RefType.Type) {\r
-                               refType = element.getElement().getType();\r
+                               refTypeName = element.getElement().getType();\r
                                if (refName == null)\r
                                        refName = element.getElement().getName();\r
                                objectName = element.getElement().getName();\r
+                               refObject = this.base.getComplexType(refTypeName);\r
+                               if (refObject == null) this.base.getSimpleType(refTypeName);\r
                        } else {\r
-                               refType = element.getElement().getRef();\r
+                               refTypeName = element.getElement().getRef();\r
                                if (refName == null)\r
-                                       refName = refType.getLocalPart();\r
-                               objectName = refType.getLocalPart();\r
+                                       refName = refTypeName.getLocalPart();\r
+                               objectName = refTypeName.getLocalPart();\r
+                               refObject = this.base.getElement(refTypeName);\r
                        }\r
                        \r
-                       String binding = this.base.getBindingFromPrimitiveType(refType);\r
-                       if (binding == null) {\r
-                               SchemaObject refElement = this.base.getElement(refType);\r
-                               SchemaObject refComplexType = this.base.getComplexType(refType);\r
-       \r
+                       TypeEntry typeEntry = this.base.getTypeEntry(refTypeName);\r
+                       if (typeEntry == null) {\r
                                // prefer element reference over complex type reference\r
                                String primaryClassName = null;\r
                                String secondaryClassName = null;\r
-                               if (refElement != null)\r
-                                       primaryClassName = getName(refElement);\r
-                               else\r
-                                       primaryClassName = getName(refComplexType);\r
+                               if (refObject != null)\r
+                                       primaryClassName = getName(refObject);\r
+                               else if (this.base.getSimpleType(refTypeName) != null) {\r
+                                       Inheritance inheritance = new Inheritance("");\r
+                                       this.base.getAtomicTypeInheritance(refTypeName, inheritance);\r
+                                       if (inheritance.atomicType != null) {\r
+                                               createPrimitiveIndicator(parent, refName, inheritance.atomicType, refTypeName);\r
+                                               return;\r
+                                       }\r
+                                       else {\r
+                                               throw new RuntimeException("No supported atomic type found for simple type " + refTypeName.toString());\r
+                                       }\r
+                               }\r
+                               else {\r
+                                       throw new RuntimeException("Type that is neither complex nor simple??");\r
+                               }\r
                                \r
-                               if (refComplexType != null) {\r
-                                       secondaryClassName = getName(refComplexType);\r
-                               } else {\r
-                                       secondaryClassName = getName(refElement);\r
+                               if (refObject != null) {\r
+                                       secondaryClassName = getName(refObject);\r
                                }\r
-                               boolean useElementList = this.base.useElementList(parent, indicator,element, referenceType == RefType.Reference, refName, refType);\r
-                               boolean useOriginalList = this.base.useOriginalList(parent, indicator,element, referenceType == RefType.Reference, refName, refType);\r
+                               boolean useElementList = this.base.useElementList(parent, indicator,element, referenceType == RefType.Reference, refName, refTypeName);\r
+                               boolean useOriginalList = this.base.useOriginalList(parent, indicator,element, referenceType == RefType.Reference, refName, refTypeName);\r
                                createReferenceIndicator(parent, referenceType, refName, objectName, primaryClassName, secondaryClassName, useElementList, useOriginalList);\r
                        } else {\r
-                               createPrimitiveIndicator(parent, refName, binding);\r
+                               createPrimitiveIndicator(parent, refName, typeEntry, refTypeName);\r
                        }\r
                } else {\r
                        Element attrs= element.getElement();\r
index 6e4355876ff4c7f58e5a38162fdec8db4e3dac78..3e0ffb1d3136327fb703a8421d01af176f384499 100644 (file)
@@ -3,7 +3,6 @@ package org.simantics.xml.sax;
 import java.io.FileNotFoundException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -12,7 +11,6 @@ import javax.xml.namespace.QName;
 
 import org.simantics.utils.datastructures.BijectionMap;
 import org.simantics.xml.sax.SchemaConversionBase.Inheritance;
-import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;
 import org.simantics.xml.sax.SchemaConversionBase.RefType;
 import org.simantics.xml.sax.SchemaObject.ObjectType;
 import org.simantics.xml.sax.configuration.AttributeComposition;
@@ -25,7 +23,6 @@ import org.w3._2001.xmlschema.LocalComplexType;
 import org.w3._2001.xmlschema.LocalSimpleType;
 import org.w3._2001.xmlschema.NamedAttributeGroup;
 import org.w3._2001.xmlschema.NamedGroup;
-import org.w3._2001.xmlschema.Restriction;
 import org.w3._2001.xmlschema.Schema;
 import org.w3._2001.xmlschema.SimpleType;
 
@@ -90,6 +87,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                writer.println();
                
                ontRoot += ".";
+               writer.println(ontRoot+"SimpleTypes : L0.Library");
                writer.println(ontRoot+"ComplexTypes : L0.Library");
                writer.println(ontRoot+"AttributeGroups : L0.Library");
                writer.println();
@@ -99,22 +97,25 @@ public class OntologyGenerator implements SchemaConversionComponent {
                base.handle(this);
        }
                
-       protected String getType(QName qtype) {
+       protected String getType(QName qtype, String rel) {
                String ontType = base.getL0TypeFromPrimitiveType(qtype);
                if (ontType != null)
                        return ontType;
-               else if (base.isComplexTypeRef(qtype.getLocalPart()))
-                       return ontRoot+getComplexTypePrefix()+qtype.getLocalPart();
-               else if (base.isSimpleTypeRef(qtype.getLocalPart()))
-                       return ontRoot+qtype.getLocalPart();
-               else if (base.isElementRef(qtype.getLocalPart()))
-                       return ontRoot+qtype.getLocalPart();
-               else if (qtype.getPrefix() != null && qtype.getPrefix().length() > 0) {
-                       return ontRoot+qtype.getPrefix()+qtype.getLocalPart();
+               else {
+                       if (base.isComplexTypeRef(qtype.getLocalPart()))
+                               return getName(base.getComplexType(qtype), rel);
+                       else if (base.isSimpleTypeRef(qtype.getLocalPart()))
+                               return getName(base.getSimpleType(qtype), rel);
+                       else if (base.isElementRef(qtype.getLocalPart()))
+                               return getName(base.getElement(qtype), rel);
                }
                throw new RuntimeException("Reference to unknown type " + qtype.getLocalPart());
        }
        
+       public String getSimpleTypePrefix() {
+               return "SimpleTypes.";
+       }
+       
        public String getComplexTypePrefix() {
                return "ComplexTypes.";
        }
@@ -123,7 +124,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                return "AttributeGroups.";
        }
        
-       public void handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
+       public String handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
                boolean single = true;
                for (SchemaElement e : elements) {
                        if (e.getRestriction().many()) {
@@ -133,70 +134,24 @@ public class OntologyGenerator implements SchemaConversionComponent {
                }
                String relationName = getName(parent)+".has"+name;
                writer.print(relationName);
-               
-               List<String> types = new ArrayList<String>();
-               for (SchemaElement e : elements) {
-                       Element localElement = e.getElement();
-                       QName refType = null;
-                       String type = null;
-                       
-                       if (localElement.getName() != null) {
-                               refType = localElement.getType();
-                               type = base.getL0TypeFromPrimitiveType(refType);        
-                       } else if (localElement.getRef() != null) {
-                               refType = localElement.getRef();
-                               type = base.getL0TypeFromPrimitiveType(refType);
-                       }
-                       if (type == null) {
-                               SchemaObject obj = base.getWithName(refType);
-                               types.add(getName(obj,"has"));
-                       } 
-               }
-               if (types.size() > 0) {
-                       for (String type : types) {
-                               writer.print(" <R " + type);
-                       }
-               } else {
-                       writer.print(" <R XML.hasElement");
-               }
-               
+               writer.print(" <R XML.hasElement");
                writer.println();
                
-               for (SchemaElement e : elements) {
-                       Element localElement = e.getElement();
-                       QName refType = null;
-                       String type = null;
-                       if (localElement.getName() != null) {
-                               refType = localElement.getType();
-                               type = getType(refType);        
-                       } else if (localElement.getRef() != null) {
-                               refType = localElement.getRef();
-                               type = getType(refType);
-                       }
-                       if (type != null) {
-                               writer.println("   --> " + type);
-                       }
-               }
                if (!single) {
-                       writer.println(ontRoot+name+ "List <T XML.ElementList");
-                       if (types.size() == 0) {
-                       writer.println(relationName+ "List <R XML.hasElementList : L0.FunctionalRelation");
-                       } else {
-                               writer.print(relationName+ "List");
-                               for (String type : types) {
-                                       writer.print(" <R " + type+"List");
-                               }
-                               writer.println(" : L0.FunctionalRelation");
-                       }
-                       writer.println("   --> " + ontRoot+name+"List");
+                       String elementListType = getName(parent) + "." + name + "List";
+                       writer.println(elementListType + " <T XML.ElementList");
+                       writer.println(relationName + "List <R XML.hasElementList : L0.FunctionalRelation");
+                       writer.println("   --> " + elementListType);
                }
+               
+               return relationName;
        };
        
        
        
        @Override
-       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {
-               if (refType != refType.Element) {
+       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName) {
+               if (refType != RefType.Element) {
                        QName referenceType = null;
                        if (refType == RefType.Type) {
                                referenceType = element.getElement().getType();
@@ -213,12 +168,14 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        SchemaObject obj = null;
                        if (type == null) {
                                obj = base.getWithName(referenceType);
-                               
-                               writer.println(getName(parent)+".has"+refName + " <R " +  getName(obj,"has"));
-                               writer.println("   --> " + getName(obj));
+                               writer.print(getName(parent)+".has"+refName + " <R XML.hasElement <R " +  getName(obj,"has"));
+                               if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+                               writer.println();
                        } else {
-                               writer.println(getName(parent)+".has"+refName + " <R XML.hasElement");
-                               writer.println("   --> " + getType(referenceType));
+                               writer.print(getName(parent)+".has"+refName + " <R XML.hasElement");
+                               if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+                               writer.println();
+                               writer.println("   --> " + getType(referenceType, ""));
                        }
                        
                        if (base.useElementList(parent, indicator,element, refType == RefType.Reference, refName, referenceType)) {
@@ -237,7 +194,9 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        if (refName == null)
                                refName = obj.getName();
                        
-                       writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+                       writer.print(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+                       if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+                       writer.println();
                        writer.println("   --> " + getName(obj));
                        if (base.useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {
                                writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
@@ -315,7 +274,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                } else if (ontType != null) {
                        writer.println("   --> " + ontType);
                } else if (primitiveType != null) {
-                       writer.println("   <R "+ontRoot+"has"+primitiveType.getLocalPart());
+                       writer.println("   <R " + getType(primitiveType, "has"));
                }
        }
        
@@ -366,26 +325,19 @@ public class OntologyGenerator implements SchemaConversionComponent {
                org.w3._2001.xmlschema.List list = simpleType.getList();
                if (list != null) {
                        // TODO : process restriction in lists
-                       String relationName = ontRoot+"has"+name;
-                       if (parent != null)
-                               relationName = getName(parent)+".has"+name;
+                       String relationName = getName(simpleTypeObj, "has");
                        writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
                        
                        String ontType = base.getL0Type(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
                        writer.println("   --> " + ontType);
                } else {
-                       String relationName = ontRoot+"has"+name;
-                       if (parent != null)
-                               relationName = getName(parent)+".has"+name;
+                       QName base = this.base.getSimpleTypeBase(simpleType);
+                       writer.println(getName(simpleTypeObj) + " <T " + getType(base, ""));
                        
-                       writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
+                       String relationName = getName(simpleTypeObj, "has");
                        
-                       QName base = this.base.getSimpleTypeBase(simpleType);
-                       Inheritance inheritance = new Inheritance("");
-                       this.base.getAtomicTypeInheritance(base, inheritance);
-                       if (inheritance.atomicType == null)
-                               throw new RuntimeException("Could not locate atomic type for SimpleType " + simpleType.getName());
-                       writer.println("   --> " + inheritance.atomicType.l0Type);
+                       writer.println(relationName+ " : L0.FunctionalRelation");
+                       writer.println("   --> " + getName(simpleTypeObj));
                        
 //                     Restriction restriction = simpleType.getRestriction();
 //                     if (restriction != null) {
@@ -444,13 +396,6 @@ public class OntologyGenerator implements SchemaConversionComponent {
 //             if (topLevelComplexType.getName().equals("Reference"))
 //                     System.out.println();
                
-               String relationName = getName(topLevelComplexType,"has");//ontRoot+"has"+name;
-               
-               writer.println(relationName+ " <R XML.hasComplexType");
-               writer.println(relationName+ "List <R XML.hasElementList");
-               //writer.println("   --> " + ontRoot+getComplexTypePrefix()+name);
-               writer.println("   --> " + name);
-               writer.println();
 //             String baseType = "XML.ComplexType";
 //
 //             QName base = getComplexTypeBase(topLevelComplexType.getComplexType());
@@ -465,11 +410,19 @@ public class OntologyGenerator implements SchemaConversionComponent {
                
 //             writer.println(name+ " <T "+baseType);
                
-               if(inheritance.type == InheritanceType.AtomicType) {
-                       writer.println(name+ " <T "+inheritance.baseClass + " <T "+inheritance.atomicType.l0Type);
-               } else {
-                       writer.println(name+ " <T "+inheritance.baseClass);
-               }
+               // Type definition
+               writer.println(name+ " <T " + inheritance.baseClass);
+               writer.println(name + "List <T XML.ElementList");
+               
+               // Access relations
+               String relationName = getName(topLevelComplexType,"has");
+               writer.println(relationName+ " <R XML.hasComplexType");
+               writer.println("   --> " + name);
+               writer.println(relationName+ "List <R XML.hasElementList");
+               writer.println("   --> " + name + "List");
+               writer.println();
+               
+               // Attributes 
 //             if (!baseType.equals(inheritance.baseClass))
 //                     System.out.println();
                //super.handleComplexType(topLevelComplexType);
@@ -490,7 +443,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                String type = "XML.Element";
                Set<String> types = new LinkedHashSet<String>();
                if (element.getType() != null) {
-                       types.add(getType(element.getType()));
+                       types.add(getType(element.getType(), ""));
                }
                QName base = this.base.getElementBase(element);
                if (base != null) {
@@ -566,7 +519,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:
                                return ontRoot+getAttributeGroupPrefix()+obj.getName();
                        case SIMPLE_TYPE:
-                               return ontRoot+obj.getName();
+                               return ontRoot+getSimpleTypePrefix()+obj.getName();
                        }
                } else {
                        SchemaObject o = obj;
@@ -587,13 +540,23 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:
                                return ontRoot+getAttributeGroupPrefix()+name;
                        case SIMPLE_TYPE:
-                               return ontRoot+name;
+                               return ontRoot+getSimpleTypePrefix()+name;
                        }
                }
                throw new RuntimeException();
                
        }
        
+       public String getName(SchemaObject parent, SchemaElement e, String rel) {
+               QName ref = e.getElement().getRef();
+               if (ref != null) {
+                       return converter.getShortName(ref.getNamespaceURI()) + rel + ref.getLocalPart();
+               }
+               else {
+                       return getName(parent, "") + "." + rel + e.getElement().getName();
+               }
+       }
+       
        public String getName(SchemaObject obj, String rel) {
                if (obj.getParent() == null) {
                        switch (obj.getType()) {
@@ -604,7 +567,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:
                                return ontRoot+getAttributeGroupPrefix()+rel+obj.getName();
                        case SIMPLE_TYPE:
-                               return ontRoot+rel+obj.getName();
+                               return ontRoot+getSimpleTypePrefix()+rel+obj.getName();
                        }
                } else {
                        SchemaObject o = obj;
@@ -625,7 +588,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        case ATTRIBUTE_GROUP:
                                return ontRoot+getAttributeGroupPrefix()+rel+name;
                        case SIMPLE_TYPE:
-                               return ontRoot+rel+name;
+                               return ontRoot+getSimpleTypePrefix()+rel+name;
                        }
                }
                throw new RuntimeException();
index 1e13951da7d8f522c47558e872534da51a474fb4..f349cde8960667c3ac33004c6fd1c5d62c538c5f 100644 (file)
@@ -111,7 +111,7 @@ public final class SchemaConversionBase {
                schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));
                schemaTypes.put("long",                 new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
                schemaTypes.put("unsignedLong", new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
-               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)","new java.lang.String(",", org.simantics.databoard.util.binary.UTF8.CHARSET)"));
+               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","java.util.Base64.getDecoder().decode(",")","java.util.Base64.getEncoder().encodeToString(",")"));
                
                l0Types.put("doubleArray",              new TypeEntry("L0.DoubleArray",  "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")"));
                l0Types.put("stringArray",              new TypeEntry("L0.StringArray",  "Bindings.STRING_ARRAY", "string[]", null,null,null,"",""));
@@ -769,21 +769,26 @@ public final class SchemaConversionBase {
        
        protected enum RefType{Element,Reference,Type};
        
-       protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {
-               component.handleIndicator(parent, indicator, element, refName, refType);
+       protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName) {
+               component.handleIndicator(parent, indicator, element, refName, refType, baseRelationName);
        }
        protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {
                component.handleIndicator(parent, indicator, any);
        }
        protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {
                //component.handle(parent, indicator, elements);
-               if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {
+               // Generate combined relation
+               String baseRelationName = null;
+               if (indicator.getType() == SchemaElement.ElementType.CHOICE) {
+                       String name = getChoiceName(elements);
+                       if (name != null)
+                               baseRelationName = component.handleChoice(parent, indicator, elements, name);
+               }
+               
+               if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || indicator.getType() == SchemaElement.ElementType.CHOICE) {
                        for (SchemaElement e : elements) {
-                               handle(parent, indicator, e);
+                               handle(parent, indicator, e, baseRelationName);
                        }
-               } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {
-                       String name = getChoiceName(elements);
-                       component.handleChoice(parent, indicator, elements, name);
                }
        }
        
@@ -931,19 +936,19 @@ public final class SchemaConversionBase {
        }
        
        
-       protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {
+       protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element, String baseRelationName) {
                Element localElement = element.getElement();
                if (localElement.getName() != null) {
-                       SchemaObject eObj = elements.get(localElement); 
+                       SchemaObject eObj = elements.get(localElement);
                        QName refType = localElement.getType();
                        if (refType != null)
-                               handleIndicator(parent, indicator, element, null, RefType.Type);
+                               handleIndicator(parent, indicator, element, null, RefType.Type, baseRelationName);
                        else {
                                handleElement(eObj);
-                               handleIndicator(parent, indicator, element, null, RefType.Element);
-                       }
+                               handleIndicator(parent, indicator, element, null, RefType.Element, baseRelationName);
+                       } 
                } else if (localElement.getRef() != null) {
-                       handleIndicator(parent, indicator,element, null, RefType.Reference);
+                       handleIndicator(parent, indicator,element, null, RefType.Reference, baseRelationName);
                }
        }
        
@@ -963,22 +968,27 @@ public final class SchemaConversionBase {
        
        protected String getChoiceName(List<SchemaElement> elements) {
                if (elements.size() == 1) {
-                       return getElementName(elements.get(0).getElement());
+                       return null;
                }
-               List<String> names = new ArrayList<String>();
-               for (SchemaElement e : elements) {
-                       String name = getElementName(e.getElement());
-                       if (name != null)
-                               names.add(name);
+               else if (elements.size() > 0 && elements.size() <= 3) {
+                       List<String> names = new ArrayList<String>();
+                       for (SchemaElement e : elements) {
+                               String name = getElementName(e.getElement());
+                               if (name != null)
+                                       names.add(name);
+                       }
+                       String name = "";
+                       for (int i = 0; i < names.size(); i++) {
+                               if (i == 0)
+                                       name = names.get(i);
+                               else
+                                       name += "Or"+names.get(i);
+                       }
+                       return name;
                }
-               String name = "";
-               for (int i = 0; i < names.size(); i++) {
-                       if (i == 0)
-                               name = names.get(i);
-                       else
-                               name += "Or"+names.get(i);
+               else {
+                       return "SubElement";
                }
-               return name;
        }
                
        protected void handle(SchemaObject parent, Attribute attribute) {
index 89d8e86b4074b63328aba28e02109f0ceb5b4ea6..9a2243b35a4c1a54fbafdbf99ca03c688ff5d805 100644 (file)
@@ -17,16 +17,17 @@ public interface SchemaConversionComponent {
                \r
        void handleAttributes(SchemaObject simpleTypeObj);\r
        void handleAttributeComposition(SchemaObject obj, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes);\r
-       void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType);\r
+       void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName);\r
        void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any);\r
        //void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements);\r
-       void handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name);\r
+       String handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name);\r
        void handle(SchemaObject parent, Attribute attribute) ;\r
        void handle(SchemaObject parent, AttributeGroup attribute) ;\r
        void handle(SchemaObject parent, NamedGroup attribute);\r
        void handleSimpleType(SchemaObject parent, SchemaObject simpleType);\r
        void handleComplexType(SchemaObject complexTypeObj);\r
        void handleElement(SchemaObject complexTypeObj);\r
+       String getSimpleTypePrefix();\r
        String getComplexTypePrefix();  \r
        String getAttributeGroupPrefix();\r
        String getName(SchemaObject obj);\r
index 1b2b3722606832c8f55fc62cc7c082e97cc1eab6..adab7f2af75112da339adba44dabab01fceb50f5 100644 (file)
@@ -16,6 +16,7 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
 
 import org.simantics.utils.datastructures.MapList;
 import org.simantics.xml.sax.configuration.Configuration;
@@ -221,6 +222,7 @@ public class SchemaConverter {
                header[3] = "Date " + new Date().toString();
                
                schemaNs = schema.getTargetNamespace();
+               
                ontologyUri = schemaNs;
                if (ontologyUri == null) {
                        ontologyUri = getSchemaFile().getName();
@@ -228,6 +230,7 @@ public class SchemaConverter {
                        int index = ontologyUri.lastIndexOf(".");
                        if (index > 0)
                                ontologyUri = ontologyUri.substring(0, index);
+                       schemaNs = "";
                } 
                ontologyUri = ontologyUri.replaceAll(" ", "_");
                String parts[] = ontologyUri.split("/");
@@ -335,7 +338,25 @@ public class SchemaConverter {
        }
        
        public boolean isPrimary() {
-               return getRoot().schemaNSMap.getValues(schemaNs).indexOf(this) == 0;
+               return getRoot() == this;
+       }
+
+       public String getShortName(String namespaceURI) {
+               List<SchemaConverter> converters = getRoot().getConverter(namespaceURI);
+               for (SchemaConverter conv : converters) {
+                       if (conv.shortName != null)
+                               return conv.shortName;
+               }
+               return null;
+       }
+       
+       public String getOntologyClassName(String namespaceURI) {
+               List<SchemaConverter> converters = getRoot().getConverter(namespaceURI);
+               for (SchemaConverter conv : converters) {
+                       if (conv.className != null)
+                               return conv.className;
+               }
+               return null;
        }