package org.simantics.xml.sax.ontology; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.ReadGraph; import org.simantics.db.request.Read; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.db.service.QueryControl; public class XMLResource { public final Resource AttributeGroup; public final Resource ComplexType; public final Resource Date; public final Resource DateTime; public final Resource Element; public final Resource ElementList; public final Resource Entity; public final Resource Time; public final Resource externalReferenceOf; public final Resource hasAttribute; public final Resource hasAttribute_Inverse; public final Resource hasComplexType; public final Resource hasComplexType_Inverse; public final Resource hasElement; public final Resource hasElementList; public final Resource hasElementList_Inverse; public final Resource hasElement_Inverse; public final Resource hasExternalReference; public final Resource hasID; public final Resource hasID_Inverse; public final Resource hasOriginalElementList; public final Resource hasOriginalElementList_Inverse; public final Resource hasReference; public final Resource referredBy; public static class URIs { public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup"; public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType"; public static final String Date = "http://www.simantics.org/XML-1.0/Date"; public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime"; public static final String Element = "http://www.simantics.org/XML-1.0/Element"; public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList"; public static final String Entity = "http://www.simantics.org/XML-1.0/Entity"; public static final String Time = "http://www.simantics.org/XML-1.0/Time"; public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf"; public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute"; public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse"; public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType"; public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse"; public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement"; public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList"; public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse"; public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse"; public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference"; public static final String hasID = "http://www.simantics.org/XML-1.0/hasID"; public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse"; public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList"; public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse"; public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference"; public static final String referredBy = "http://www.simantics.org/XML-1.0/referredBy"; } public static Resource getResourceOrNull(ReadGraph graph, String uri) { try { return graph.getResource(uri); } catch(DatabaseException e) { System.err.println(e.getMessage()); return null; } } public XMLResource(ReadGraph graph) { AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup); ComplexType = getResourceOrNull(graph, URIs.ComplexType); Date = getResourceOrNull(graph, URIs.Date); DateTime = getResourceOrNull(graph, URIs.DateTime); Element = getResourceOrNull(graph, URIs.Element); ElementList = getResourceOrNull(graph, URIs.ElementList); Entity = getResourceOrNull(graph, URIs.Entity); Time = getResourceOrNull(graph, URIs.Time); externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf); hasAttribute = getResourceOrNull(graph, URIs.hasAttribute); hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse); hasComplexType = getResourceOrNull(graph, URIs.hasComplexType); hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse); hasElement = getResourceOrNull(graph, URIs.hasElement); hasElementList = getResourceOrNull(graph, URIs.hasElementList); hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse); hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse); hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference); hasID = getResourceOrNull(graph, URIs.hasID); hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse); hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList); hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse); hasReference = getResourceOrNull(graph, URIs.hasReference); referredBy = getResourceOrNull(graph, URIs.referredBy); } public static XMLResource getInstance(ReadGraph graph) { Session session = graph.getSession(); XMLResource ret = session.peekService(XMLResource.class); if(ret == null) { QueryControl qc = graph.getService(QueryControl.class); ret = new XMLResource(qc.getIndependentGraph(graph)); session.registerService(XMLResource.class, ret); } return ret; } public static XMLResource getInstance(RequestProcessor session) throws DatabaseException { XMLResource ret = session.peekService(XMLResource.class); if(ret == null) { ret = session.syncRequest(new Read() { public XMLResource perform(ReadGraph graph) throws DatabaseException { QueryControl qc = graph.getService(QueryControl.class); return new XMLResource(qc.getIndependentGraph(graph)); } }); session.registerService(XMLResource.class, ret); } return ret; } }