]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
XML ontology
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 9 Nov 2016 14:39:45 +0000 (14:39 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 12:01:34 +0000 (14:01 +0200)
refs #6801

git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@33375 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.xml.sax.ontology/.classpath [new file with mode: 0644]
org.simantics.xml.sax.ontology/.project [new file with mode: 0644]
org.simantics.xml.sax.ontology/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.xml.sax.ontology/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.xml.sax.ontology/build.properties [new file with mode: 0644]
org.simantics.xml.sax.ontology/graph.tg [new file with mode: 0644]
org.simantics.xml.sax.ontology/graph/XML.pgraph [new file with mode: 0644]
org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.java [new file with mode: 0644]

diff --git a/org.simantics.xml.sax.ontology/.classpath b/org.simantics.xml.sax.ontology/.classpath
new file mode 100644 (file)
index 0000000..b862a29
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.xml.sax.ontology/.project b/org.simantics.xml.sax.ontology/.project
new file mode 100644 (file)
index 0000000..362b551
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.xml.sax.ontology</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.simantics.graph.builder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+               <nature>org.simantics.graph.nature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.xml.sax.ontology/.settings/org.eclipse.jdt.core.prefs b/org.simantics.xml.sax.ontology/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..295926d
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.8\r
diff --git a/org.simantics.xml.sax.ontology/META-INF/MANIFEST.MF b/org.simantics.xml.sax.ontology/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..a3b1741
--- /dev/null
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: http://www.simantics.org/XML
+Bundle-SymbolicName: org.simantics.xml.sax.ontology
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Simantics XML base ontology
+Require-Bundle: org.simantics.layer0;bundle-version="1.1.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Export-Package: org.simantics.xml.sax.ontology
diff --git a/org.simantics.xml.sax.ontology/build.properties b/org.simantics.xml.sax.ontology/build.properties
new file mode 100644 (file)
index 0000000..41eb6ad
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .\r
diff --git a/org.simantics.xml.sax.ontology/graph.tg b/org.simantics.xml.sax.ontology/graph.tg
new file mode 100644 (file)
index 0000000..82dd4f2
Binary files /dev/null and b/org.simantics.xml.sax.ontology/graph.tg differ
diff --git a/org.simantics.xml.sax.ontology/graph/XML.pgraph b/org.simantics.xml.sax.ontology/graph/XML.pgraph
new file mode 100644 (file)
index 0000000..000f292
--- /dev/null
@@ -0,0 +1,37 @@
+L0 = <http://www.simantics.org/Layer0-1.1>\r
+\r
+XML = <http://www.simantics.org/XML-1.0> : L0.Ontology\r
+   @L0.new\r
+   L0.HasResourceClass "org.simantics.xml.sax.ontology.XMLResource"\r
+\r
+\r
+// Built-in types\r
+\r
+XML.hasAttribute <R L0.HasProperty\r
+XML.hasID <R XML.hasAttribute : L0.FunctionalRelation\r
+  --> L0.String\r
+XML.ComplexType <T L0.Entity\r
+XML.hasComplexType <R L0.IsComposedOf\r
+XML.AttributeGroup  <T L0.Entity\r
+XML.Element <T L0.Entity\r
+XML.hasElement <R L0.IsComposedOf\r
+XML.ElementList <T L0.List\r
+XML.hasElementList <R L0.IsComposedOf\r
+XML.hasOriginalElementList <R XML.hasElementList\r
+XML.hasReference <R L0.IsRelatedTo\r
+XML.hasExternalReference <R L0.IsRelatedTo\r
+   L0.InverseOf XML.externalReferenceOf <R L0.IsRelatedTo\r
+   \r
+   \r
+XML.DateTime <T L0.Literal\r
+    @L0.assert L0.HasValueType "(Integer,Byte,Byte,Byte,Byte,Byte,Integer)"\r
+    @L0.assert L0.HasDataType ${ year : Integer, month : Byte, date : Byte, hours : Byte, minutes : Byte, seconds : Byte, offset : Integer }\r
+    \r
+XML.Date <T L0.Literal\r
+    @L0.assert L0.HasValueType "(Integer,Byte,Byte,Integer)"\r
+    @L0.assert L0.HasDataType ${ year : Integer, month : Byte, date : Byte, offset : Integer }\r
+\r
+XML.Time <T L0.Literal\r
+    @L0.assert L0.HasValueType "(Byte,Byte,Byte,Integer,)"\r
+    @L0.assert L0.HasDataType ${ hours : Byte, minutes : Byte, seconds : Byte, offset : Integer }\r
+\r
diff --git a/org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.java b/org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.java
new file mode 100644 (file)
index 0000000..48daa59
--- /dev/null
@@ -0,0 +1,121 @@
+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 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 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
+        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