]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.java
XML ontology
[simantics/interop.git] / org.simantics.xml.sax.ontology / src / org / simantics / xml / sax / ontology / XMLResource.java
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