1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.interop.stubs;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.request.Read;
\r
17 import org.simantics.db.Session;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
20 public class InteropResource {
\r
22 public final Resource ImportLibrary;
\r
23 public final Resource InteropFeature;
\r
25 public static class URIs {
\r
26 public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary";
\r
27 public static final String InteropFeature = "http://www.simantics.org/Interop-1.0/InteropFeature";
\r
30 public static Resource getResourceOrNull(ReadGraph graph, String uri) {
\r
32 return graph.getResource(uri);
\r
33 } catch(DatabaseException e) {
\r
34 System.err.println(e.getMessage());
\r
39 public InteropResource(ReadGraph graph) {
\r
40 ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);
\r
41 InteropFeature = getResourceOrNull(graph, URIs.InteropFeature);
\r
44 public static InteropResource getInstance(ReadGraph graph) {
\r
45 Session session = graph.getSession();
\r
46 InteropResource ret = session.peekService(InteropResource.class);
\r
48 ret = new InteropResource(graph);
\r
49 session.registerService(InteropResource.class, ret);
\r
54 public static InteropResource getInstance(Session session) throws DatabaseException {
\r
55 InteropResource ret = session.peekService(InteropResource.class);
\r
57 ret = session.syncRequest(new Read<InteropResource>() {
\r
58 public InteropResource perform(ReadGraph graph) throws DatabaseException {
\r
59 return new InteropResource(graph);
\r
62 session.registerService(InteropResource.class, ret);
\r