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.BinaryRead;
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 PossibleSessionVariable extends BinaryRead<ResourceArray, String, Variable> {
32 public PossibleSessionVariable(ResourceArray resource, String identifier) {
33 super(resource, identifier);
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);
74 Resource model = graph.syncRequest(new PossibleModel(head));
75 if (model == null) return null;
77 // if(valuationName == null) {
78 // String valuation = graph.syncRequest(new PossibleActiveExperiment(model));
79 // if(valuation != null) valuationName = valuation;
82 if (valuationName == null) {
83 valuationName = "/ConfigurationValues";
86 VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
87 Variable modelVariable = graph.adapt(model, Variable.class);
88 Variable experimentVariable = modelVariable.browse(graph, valuationName);
89 return variableInterface.getVariable(graph, experimentVariable, parameter);
91 } catch (MissingVariableException e) {
92 if (DebugException.DEBUG)
95 } catch (ResourceNotFoundException e) {
96 if (DebugException.DEBUG)
99 } catch (AdaptionException e) {
100 if (DebugException.DEBUG)
103 } catch (Throwable e) {
104 if (DebugException.DEBUG)
113 // public Variable perform(ReadGraph graph) throws DatabaseException {
117 // Builtins b = graph.getBuiltins();
118 // String valuationName = null;
119 // //Valuations valuations = graph.adapt(parameter, Valuations.class);
120 // Resource map = graph.getResource("http://www.simantics.org/Modeling-1.1/CompositeToDiagram");
122 // Resource tail = parameter.resources[parameter.size() - 1];
124 // Resource diagram = graph.syncRequest(new PossibleDiagram(tail));
125 // if(diagram == null) {
126 // Resource d = diagram;
127 // while((d = graph.getPossibleObject(d, b.PartOf)) != null) {
128 // diagram = graph.getPossibleObject(d, map);
129 // if(diagram != null) break;
133 // if(diagram != null) {
134 // for(Resource run : graph.getObjects(diagram, b.ConsistsOf)) {
135 // String name = graph.getPossibleRelatedValue(run, b.HasName, StringJavaBinding.INSTANCE);
136 // if(parameter2.equals(name)) {
137 // valuationName = graph.getPossibleRelatedValue(run, b.HasActiveExperiment);
143 // Resource model = graph.syncRequest(new PossibleModel(head));
144 // if (model == null) return null;
146 // if(valuationName == null) {
147 // String valuation = graph.syncRequest(new PossibleActiveExperiment(model));
148 // if(valuation != null) valuationName = valuation;
151 // if (valuationName == null) {
152 // valuationName = "/ConfigurationValues";
155 // VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
156 // Variable modelVariable = graph.adapt(model, Variable.class);
157 // Variable experimentVariable = modelVariable.browse(graph, valuationName);
158 // return variableInterface.getVariable(graph, experimentVariable, parameter);
162 //// Resource value = valuations.getValue(graph, null, valuationName, parameter3);
163 //// return graph.getSingleObject(value, b.ConsistsOf);
165 // } catch (ResourceNotFoundException e) {
166 // if (DebugException.DEBUG)
167 // e.printStackTrace();
169 // } catch (AdaptionException e) {
170 // if (DebugException.DEBUG)
171 // e.printStackTrace();