/******************************************************************************* * 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; } }