X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fstubs%2FInteropResource.java;h=53ca523079a89c67429402b7950c85de75c5d42c;hb=dc5ff213540b06b8cb88222837d573bff80abb3d;hp=ffa281f1a95a07e8aecb62935dcee8ad7b32be7d;hpb=eeac6a1f1968b474b24aea1759fcaeca46ec801e;p=simantics%2Finterop.git diff --git a/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java b/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java index ffa281f..53ca523 100644 --- a/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java +++ b/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java @@ -1,65 +1,79 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.interop.stubs; - -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; - -public class InteropResource { - - public final Resource ImportLibrary; - - public static class URIs { - 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) { - ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary); - } - - public static InteropResource getInstance(ReadGraph graph) { - Session session = graph.getSession(); - InteropResource ret = session.peekService(InteropResource.class); - if(ret == null) { - ret = new InteropResource(graph); - session.registerService(InteropResource.class, ret); - } - return ret; - } - - public static InteropResource getInstance(Session session) throws DatabaseException { - InteropResource ret = session.peekService(InteropResource.class); - if(ret == null) { - ret = session.syncRequest(new Read() { - public InteropResource perform(ReadGraph graph) throws DatabaseException { - return new InteropResource(graph); - } - }); - session.registerService(InteropResource.class, ret); - } - return ret; - } - -} - +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; + } + +} +