]> gerrit.simantics Code Review - simantics/interop.git/blob - 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
1 package org.simantics.xml.sax.ontology;\r
2 \r
3 import org.simantics.db.RequestProcessor;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.ReadGraph;\r
6 import org.simantics.db.request.Read;\r
7 import org.simantics.db.Session;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.db.service.QueryControl;\r
10 \r
11 public class XMLResource {\r
12     \r
13     public final Resource AttributeGroup;\r
14     public final Resource ComplexType;\r
15     public final Resource Date;\r
16     public final Resource DateTime;\r
17     public final Resource Element;\r
18     public final Resource ElementList;\r
19     public final Resource Time;\r
20     public final Resource externalReferenceOf;\r
21     public final Resource hasAttribute;\r
22     public final Resource hasAttribute_Inverse;\r
23     public final Resource hasComplexType;\r
24     public final Resource hasComplexType_Inverse;\r
25     public final Resource hasElement;\r
26     public final Resource hasElementList;\r
27     public final Resource hasElementList_Inverse;\r
28     public final Resource hasElement_Inverse;\r
29     public final Resource hasExternalReference;\r
30     public final Resource hasID;\r
31     public final Resource hasID_Inverse;\r
32     public final Resource hasOriginalElementList;\r
33     public final Resource hasOriginalElementList_Inverse;\r
34     public final Resource hasReference;\r
35         \r
36     public static class URIs {\r
37         public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup";\r
38         public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType";\r
39         public static final String Date = "http://www.simantics.org/XML-1.0/Date";\r
40         public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";\r
41         public static final String Element = "http://www.simantics.org/XML-1.0/Element";\r
42         public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";\r
43         public static final String Time = "http://www.simantics.org/XML-1.0/Time";\r
44         public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";\r
45         public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";\r
46         public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse";\r
47         public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType";\r
48         public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse";\r
49         public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement";\r
50         public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList";\r
51         public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse";\r
52         public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse";\r
53         public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference";\r
54         public static final String hasID = "http://www.simantics.org/XML-1.0/hasID";\r
55         public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse";\r
56         public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList";\r
57         public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse";\r
58         public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference";\r
59     }\r
60     \r
61     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
62         try {\r
63             return graph.getResource(uri);\r
64         } catch(DatabaseException e) {\r
65             System.err.println(e.getMessage());\r
66             return null;\r
67         }\r
68     }\r
69     \r
70     public XMLResource(ReadGraph graph) {\r
71         AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup);\r
72         ComplexType = getResourceOrNull(graph, URIs.ComplexType);\r
73         Date = getResourceOrNull(graph, URIs.Date);\r
74         DateTime = getResourceOrNull(graph, URIs.DateTime);\r
75         Element = getResourceOrNull(graph, URIs.Element);\r
76         ElementList = getResourceOrNull(graph, URIs.ElementList);\r
77         Time = getResourceOrNull(graph, URIs.Time);\r
78         externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);\r
79         hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);\r
80         hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse);\r
81         hasComplexType = getResourceOrNull(graph, URIs.hasComplexType);\r
82         hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse);\r
83         hasElement = getResourceOrNull(graph, URIs.hasElement);\r
84         hasElementList = getResourceOrNull(graph, URIs.hasElementList);\r
85         hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse);\r
86         hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse);\r
87         hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference);\r
88         hasID = getResourceOrNull(graph, URIs.hasID);\r
89         hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse);\r
90         hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList);\r
91         hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse);\r
92         hasReference = getResourceOrNull(graph, URIs.hasReference);\r
93     }\r
94     \r
95     public static XMLResource getInstance(ReadGraph graph) {\r
96         Session session = graph.getSession();\r
97         XMLResource ret = session.peekService(XMLResource.class);\r
98         if(ret == null) {\r
99             QueryControl qc = graph.getService(QueryControl.class);\r
100             ret = new XMLResource(qc.getIndependentGraph(graph));\r
101             session.registerService(XMLResource.class, ret);\r
102         }\r
103         return ret;\r
104     }\r
105     \r
106     public static XMLResource getInstance(RequestProcessor session) throws DatabaseException {\r
107         XMLResource ret = session.peekService(XMLResource.class);\r
108         if(ret == null) {\r
109             ret = session.syncRequest(new Read<XMLResource>() {\r
110                 public XMLResource perform(ReadGraph graph) throws DatabaseException {\r
111                     QueryControl qc = graph.getService(QueryControl.class);\r
112                     return new XMLResource(qc.getIndependentGraph(graph));\r
113                 }\r
114             });\r
115             session.registerService(XMLResource.class, ret);\r
116         }\r
117         return ret;\r
118     }\r
119     \r
120 }\r
121 \r