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