1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.layer0.request;
\r
14 import org.simantics.databoard.Bindings;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.common.ResourceArray;
\r
18 import org.simantics.db.common.exception.DebugException;
\r
19 import org.simantics.db.common.request.BinaryRead;
\r
20 import org.simantics.db.exception.AdaptionException;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
22 import org.simantics.db.exception.ResourceNotFoundException;
\r
23 import org.simantics.db.layer0.exception.MissingVariableException;
\r
24 import org.simantics.db.layer0.variable.Variable;
\r
25 import org.simantics.db.layer0.variable.VariableInterface;
\r
26 import org.simantics.layer0.Layer0;
\r
27 import org.simantics.scl.reflection.OntologyVersions;
\r
28 import org.simantics.simulation.ontology.SimulationResource;
\r
30 public class PossibleSessionVariable extends BinaryRead<ResourceArray, String, Variable> {
\r
32 public PossibleSessionVariable(ResourceArray resource, String identifier) {
\r
33 super(resource, identifier);
\r
37 public Variable perform(ReadGraph graph) throws DatabaseException {
\r
41 String uri = OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Modeling-0.0/CompositeToDiagram");
\r
42 Resource map = graph.getResource(uri);
\r
44 Resource tail = parameter.tail();
\r
45 Resource head = parameter.head();
\r
47 if(!graph.hasStatement(tail)) return null;
\r
49 Layer0 l0 = Layer0.getInstance(graph);
\r
51 String valuationName = null;
\r
53 Resource diagram = graph.syncRequest(new PossibleDiagram(tail));
\r
54 if(diagram == null) {
\r
55 Resource d = diagram;
\r
56 while((d = graph.getPossibleObject(d, l0.PartOf)) != null) {
\r
57 diagram = graph.getPossibleObject(d, map);
\r
58 if(diagram != null) break;
\r
62 if(diagram != null) {
\r
63 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
64 for(Resource run : graph.getObjects(diagram, l0.ConsistsOf)) {
\r
65 String name = graph.getPossibleRelatedValue(run, l0.HasName, Bindings.STRING);
\r
66 if(parameter2.equals(name)) {
\r
67 valuationName = graph.getPossibleRelatedValue(run, SIMU.HasActiveExperiment);
\r
74 Resource model = graph.syncRequest(new PossibleModel(head));
\r
75 if (model == null) return null;
\r
77 // if(valuationName == null) {
\r
78 // String valuation = graph.syncRequest(new PossibleActiveExperiment(model));
\r
79 // if(valuation != null) valuationName = valuation;
\r
82 if (valuationName == null) {
\r
83 valuationName = "/ConfigurationValues";
\r
86 VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
\r
87 Variable modelVariable = graph.adapt(model, Variable.class);
\r
88 Variable experimentVariable = modelVariable.browse(graph, valuationName);
\r
89 return variableInterface.getVariable(graph, experimentVariable, parameter);
\r
91 } catch (MissingVariableException e) {
\r
92 if (DebugException.DEBUG)
\r
93 e.printStackTrace();
\r
95 } catch (ResourceNotFoundException e) {
\r
96 if (DebugException.DEBUG)
\r
97 e.printStackTrace();
\r
99 } catch (AdaptionException e) {
\r
100 if (DebugException.DEBUG)
\r
101 e.printStackTrace();
\r
103 } catch (Throwable e) {
\r
104 if (DebugException.DEBUG)
\r
105 e.printStackTrace();
\r
113 // public Variable perform(ReadGraph graph) throws DatabaseException {
\r
117 // Builtins b = graph.getBuiltins();
\r
118 // String valuationName = null;
\r
119 // //Valuations valuations = graph.adapt(parameter, Valuations.class);
\r
120 // Resource map = graph.getResource("http://www.simantics.org/Modeling-1.1/CompositeToDiagram");
\r
122 // Resource tail = parameter.resources[parameter.size() - 1];
\r
124 // Resource diagram = graph.syncRequest(new PossibleDiagram(tail));
\r
125 // if(diagram == null) {
\r
126 // Resource d = diagram;
\r
127 // while((d = graph.getPossibleObject(d, b.PartOf)) != null) {
\r
128 // diagram = graph.getPossibleObject(d, map);
\r
129 // if(diagram != null) break;
\r
133 // if(diagram != null) {
\r
134 // for(Resource run : graph.getObjects(diagram, b.ConsistsOf)) {
\r
135 // String name = graph.getPossibleRelatedValue(run, b.HasName, StringJavaBinding.INSTANCE);
\r
136 // if(parameter2.equals(name)) {
\r
137 // valuationName = graph.getPossibleRelatedValue(run, b.HasActiveExperiment);
\r
143 // Resource model = graph.syncRequest(new PossibleModel(head));
\r
144 // if (model == null) return null;
\r
146 // if(valuationName == null) {
\r
147 // String valuation = graph.syncRequest(new PossibleActiveExperiment(model));
\r
148 // if(valuation != null) valuationName = valuation;
\r
151 // if (valuationName == null) {
\r
152 // valuationName = "/ConfigurationValues";
\r
155 // VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
\r
156 // Variable modelVariable = graph.adapt(model, Variable.class);
\r
157 // Variable experimentVariable = modelVariable.browse(graph, valuationName);
\r
158 // return variableInterface.getVariable(graph, experimentVariable, parameter);
\r
162 //// Resource value = valuations.getValue(graph, null, valuationName, parameter3);
\r
163 //// return graph.getSingleObject(value, b.ConsistsOf);
\r
165 // } catch (ResourceNotFoundException e) {
\r
166 // if (DebugException.DEBUG)
\r
167 // e.printStackTrace();
\r
169 // } catch (AdaptionException e) {
\r
170 // if (DebugException.DEBUG)
\r
171 // e.printStackTrace();
\r