package org.simantics.interop.stubs; 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 InteropResource { public final Resource HasDestination; public final Resource HasGeneratorID; public final Resource HasGeneratorID_Inverse; public final Resource HasImportData; public final Resource HasInputResource; public final Resource HasSource; public final Resource ImportDataOf; public final Resource ImportLibrary; public static class URIs { public static final String HasDestination = "http://www.simantics.org/Interop-1.0/HasDestination"; public static final String HasGeneratorID = "http://www.simantics.org/Interop-1.0/HasGeneratorID"; public static final String HasGeneratorID_Inverse = "http://www.simantics.org/Interop-1.0/HasGeneratorID/Inverse"; public static final String HasImportData = "http://www.simantics.org/Interop-1.0/HasImportData"; public static final String HasInputResource = "http://www.simantics.org/Interop-1.0/HasInputResource"; public static final String HasSource = "http://www.simantics.org/Interop-1.0/HasSource"; public static final String ImportDataOf = "http://www.simantics.org/Interop-1.0/ImportDataOf"; public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary"; } public static Resource getResourceOrNull(ReadGraph graph, String uri) { try { return graph.getResource(uri); } catch(DatabaseException e) { System.err.println(e.getMessage()); return null; } } public InteropResource(ReadGraph graph) { HasDestination = getResourceOrNull(graph, URIs.HasDestination); HasGeneratorID = getResourceOrNull(graph, URIs.HasGeneratorID); HasGeneratorID_Inverse = getResourceOrNull(graph, URIs.HasGeneratorID_Inverse); HasImportData = getResourceOrNull(graph, URIs.HasImportData); HasInputResource = getResourceOrNull(graph, URIs.HasInputResource); HasSource = getResourceOrNull(graph, URIs.HasSource); ImportDataOf = getResourceOrNull(graph, URIs.ImportDataOf); ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary); } public static InteropResource getInstance(ReadGraph graph) { Session session = graph.getSession(); InteropResource ret = session.peekService(InteropResource.class); if(ret == null) { QueryControl qc = graph.getService(QueryControl.class); ret = new InteropResource(qc.getIndependentGraph(graph)); session.registerService(InteropResource.class, ret); } return ret; } public static InteropResource getInstance(RequestProcessor session) throws DatabaseException { InteropResource ret = session.peekService(InteropResource.class); if(ret == null) { ret = session.syncRequest(new Read() { public InteropResource perform(ReadGraph graph) throws DatabaseException { QueryControl qc = graph.getService(QueryControl.class); return new InteropResource(qc.getIndependentGraph(graph)); } }); session.registerService(InteropResource.class, ret); } return ret; } }