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.ResourceArray;
18 import org.simantics.db.common.exception.DebugException;
19 import org.simantics.db.common.request.TernaryRead;
20 import org.simantics.db.exception.AdaptionException;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.exception.ResourceNotFoundException;
23 import org.simantics.db.layer0.exception.MissingVariableException;
24 import org.simantics.db.layer0.variable.Variable;
25 import org.simantics.db.layer0.variable.VariableInterface;
26 import org.simantics.layer0.Layer0;
27 import org.simantics.scl.reflection.OntologyVersions;
28 import org.simantics.simulation.ontology.SimulationResource;
30 public class PossibleSessionVariableFromURI extends TernaryRead<ResourceArray, String, String, Variable> {
32 public PossibleSessionVariableFromURI(ResourceArray resource, String identifier, String sessionId) {
33 super(resource, identifier, sessionId);
37 public Variable perform(ReadGraph graph) throws DatabaseException {
41 String uri = OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Modeling-0.0/CompositeToDiagram");
42 Resource map = graph.getResource(uri);
44 Resource tail = parameter.tail();
45 Resource head = parameter.head();
47 if(!graph.hasStatement(tail)) return null;
49 Layer0 l0 = Layer0.getInstance(graph);
51 String valuationName = null;
53 Resource diagram = graph.syncRequest(new PossibleDiagram(tail));
56 while((d = graph.getPossibleObject(d, l0.PartOf)) != null) {
57 diagram = graph.getPossibleObject(d, map);
58 if(diagram != null) break;
63 SimulationResource SIMU = SimulationResource.getInstance(graph);
64 for(Resource run : graph.getObjects(diagram, l0.ConsistsOf)) {
65 String name = graph.getPossibleRelatedValue(run, l0.HasName, Bindings.STRING);
66 if(parameter2.equals(name)) {
67 valuationName = graph.getPossibleRelatedValue(run, SIMU.HasActiveExperiment);
73 Resource model = graph.syncRequest(new PossibleModel(head));
74 if (model == null) return null;
75 if (valuationName == null) {
76 valuationName = "/ConfigurationValues";
79 VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
80 Variable modelVariable = graph.adapt(model, Variable.class);
81 Variable experimentVariable = modelVariable.browse(graph, valuationName+parameter2);
82 return variableInterface.getVariable(graph, experimentVariable, parameter3);
83 } catch (MissingVariableException e) {
84 if (DebugException.DEBUG)
87 } catch (ResourceNotFoundException e) {
88 if (DebugException.DEBUG)
91 } catch (AdaptionException e) {
92 if (DebugException.DEBUG)
95 } catch (Throwable e) {
96 if (DebugException.DEBUG)