1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.layer0.request;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.common.exception.DebugException;
18 import org.simantics.db.common.request.TernaryRead;
19 import org.simantics.db.exception.AdaptionException;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.exception.ResourceNotFoundException;
22 import org.simantics.db.layer0.adapter.Valuations;
23 import org.simantics.layer0.Layer0;
24 import org.simantics.scl.reflection.OntologyVersions;
25 import org.simantics.simulation.ontology.SimulationResource;
27 public class PossibleSessionValuation extends TernaryRead<Resource, String, String, Resource> {
29 public PossibleSessionValuation(Resource resource, String identifier) {
30 super(resource, identifier, "");
33 public PossibleSessionValuation(Resource resource, String identifier, String suffix) {
34 super(resource, identifier, suffix);
38 public Resource perform(ReadGraph graph) throws DatabaseException {
40 Layer0 l0 = Layer0.getInstance(graph);
41 String valuationName = null;
42 Valuations valuations = graph.adapt(parameter, Valuations.class);
44 String uri = OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Modeling-0.0/CompositeToDiagram");
45 Resource map = graph.getResource(uri);
47 Resource diagram = graph.syncRequest(new PossibleDiagram(parameter));
49 Resource d = parameter;
50 while((d = graph.getPossibleObject(d, l0.PartOf)) != null) {
51 diagram = graph.getPossibleObject(d, map);
52 if(diagram != null) break;
57 SimulationResource SIMU = SimulationResource.getInstance(graph);
58 for(Resource run : graph.getObjects(diagram, l0.ConsistsOf)) {
59 String name = graph.getPossibleRelatedValue(run, l0.HasName, Bindings.STRING);
60 if(parameter2.equals(name)) {
61 valuationName = graph.getPossibleRelatedValue(run, SIMU.HasActiveExperiment);
67 Resource value = valuations.getValue(graph, null, valuationName, parameter3);
68 return graph.getSingleObject(value, l0.ConsistsOf);
70 } catch (ResourceNotFoundException e) {
71 if (DebugException.DEBUG)
74 } catch (AdaptionException e) {
75 if (DebugException.DEBUG)