X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2FResourceInputs.java;fp=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2FResourceInputs.java;h=039388cb31eb28ce442c6903e3a0a57ae2f30363;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=01d937eb2269f03882834118bceb4dbdfbaf41fa;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceInputs.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceInputs.java index 01d937eb2..039388cb3 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceInputs.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceInputs.java @@ -1,106 +1,106 @@ -/******************************************************************************* - * Copyright (c) 2012 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.ui.workbench; - -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.simantics.Simantics; -import org.simantics.db.RequestProcessor; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.common.ResourceArray; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.RuntimeDatabaseException; -import org.simantics.db.service.LifecycleSupport; -import org.simantics.db.service.SerialisationSupport; - -/** - * @author Tuukka Lehtonen - */ -final class ResourceInputs { - - public static Reference makeReference(T t) { - return new SoftReference(t); - } - - public static Resource resolveResource(RequestProcessor processor, String resourceId) throws DatabaseException { - try { - SerialisationSupport ss = processor.getService(SerialisationSupport.class); - return ss.getResource(Long.parseLong(resourceId)); - } catch (NumberFormatException e) { - throw new DatabaseException(e); - } - } - - public static ResourceArray makeResourceArray(RequestProcessor processor, Collection resourceIds) throws DatabaseException { - try { - SerialisationSupport ss = processor.getService(SerialisationSupport.class); - List rs = new ArrayList(); - for (String id : resourceIds) - rs.add(ss.getResource(Long.parseLong(id))); - return new ResourceArray(rs); - } catch (NumberFormatException e) { - throw new DatabaseException(e); - } - } - - public static String getRandomAccessId(Resource r) { - try { - SerialisationSupport support = getSession().getService(SerialisationSupport.class); - return String.valueOf( support.getRandomAccessId(r) ); - } catch (DatabaseException e) { - throw new RuntimeDatabaseException(e); - } - } - - public static List getRandomAccessIds(ResourceArray ra) { - try { - List randoms = new ArrayList(); - SerialisationSupport support = getSession().getService(SerialisationSupport.class); - for (Resource r : ra.resources) - randoms.add(String.valueOf(support.getRandomAccessId(r))); - return Collections.unmodifiableList(randoms); - } catch (DatabaseException e) { - throw new RuntimeDatabaseException(e); - } - } - - /** - * @return a graph instance if it exists and has not yet been disposed, - * null otherwise - */ - public static Session getSession() { - Session s = Simantics.getSession(); - if (s.getService(LifecycleSupport.class).isClosed()) - throw new IllegalStateException("database session is closed"); - return s; - } - - /** - * @return a graph instance if it exists and has not yet been disposed, - * null otherwise - */ - public static Session peekSession() { - Session s = Simantics.peekSession(); - if (s == null) - return null; - if (s.getService(LifecycleSupport.class).isClosed()) - throw new IllegalStateException("database session is closed"); - return s; - } - -} +/******************************************************************************* + * Copyright (c) 2012 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.ui.workbench; + +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.simantics.Simantics; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.service.SerialisationSupport; + +/** + * @author Tuukka Lehtonen + */ +final class ResourceInputs { + + public static Reference makeReference(T t) { + return new SoftReference(t); + } + + public static Resource resolveResource(RequestProcessor processor, String resourceId) throws DatabaseException { + try { + SerialisationSupport ss = processor.getService(SerialisationSupport.class); + return ss.getResource(Long.parseLong(resourceId)); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + + public static ResourceArray makeResourceArray(RequestProcessor processor, Collection resourceIds) throws DatabaseException { + try { + SerialisationSupport ss = processor.getService(SerialisationSupport.class); + List rs = new ArrayList(); + for (String id : resourceIds) + rs.add(ss.getResource(Long.parseLong(id))); + return new ResourceArray(rs); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + + public static String getRandomAccessId(Resource r) { + try { + SerialisationSupport support = getSession().getService(SerialisationSupport.class); + return String.valueOf( support.getRandomAccessId(r) ); + } catch (DatabaseException e) { + throw new RuntimeDatabaseException(e); + } + } + + public static List getRandomAccessIds(ResourceArray ra) { + try { + List randoms = new ArrayList(); + SerialisationSupport support = getSession().getService(SerialisationSupport.class); + for (Resource r : ra.resources) + randoms.add(String.valueOf(support.getRandomAccessId(r))); + return Collections.unmodifiableList(randoms); + } catch (DatabaseException e) { + throw new RuntimeDatabaseException(e); + } + } + + /** + * @return a graph instance if it exists and has not yet been disposed, + * null otherwise + */ + public static Session getSession() { + Session s = Simantics.getSession(); + if (s.getService(LifecycleSupport.class).isClosed()) + throw new IllegalStateException("database session is closed"); + return s; + } + + /** + * @return a graph instance if it exists and has not yet been disposed, + * null otherwise + */ + public static Session peekSession() { + Session s = Simantics.peekSession(); + if (s == null) + return null; + if (s.getService(LifecycleSupport.class).isClosed()) + throw new IllegalStateException("database session is closed"); + return s; + } + +}