--- /dev/null
+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
--- /dev/null
+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