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.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.ResourceArray;
17 import org.simantics.db.common.exception.DebugException;
18 import org.simantics.db.common.request.UnaryRead;
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.exception.MissingVariableException;
23 import org.simantics.db.layer0.variable.Variable;
24 import org.simantics.db.layer0.variable.VariableInterface;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.simulation.ontology.SimulationResource;
28 public class PossibleActiveVariable extends UnaryRead<ResourceArray, Variable> {
30 public PossibleActiveVariable(ResourceArray resource) {
35 public Variable perform(ReadGraph graph) throws DatabaseException {
39 Resource tail = parameter.tail();
40 Resource head = parameter.head();
42 if(!graph.hasStatement(tail)) return null;
44 Layer0 L0 = Layer0.getInstance(graph);
45 SimulationResource SIMU = SimulationResource.getInstance(graph);
47 String valuationName = null;
49 //Valuations valuations = graph.adapt(parameter, Valuations.class);
51 Resource diagram = graph.syncRequest(new PossibleDiagram(tail));
54 String valuation = graph.getPossibleRelatedValue(diagram, SIMU.HasActiveExperiment);
55 if(valuation != null) valuationName = valuation;
59 Resource model = graph.syncRequest(new PossibleModel(head));
60 if (model == null) return null;
62 if(valuationName == null) {
63 String valuation = graph.syncRequest(new PossibleActiveExperimentPath(model));
64 if(valuation != null) valuationName = valuation;
67 if (valuationName == null) {
68 valuationName = "/BaseRealization";
71 VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
72 Variable modelVariable = graph.adapt(model, Variable.class);
73 Variable experimentVariable = modelVariable.browse(graph, valuationName);
74 return variableInterface.getVariable(graph, experimentVariable, parameter);
76 } catch (MissingVariableException e) {
77 if (DebugException.DEBUG)
80 } catch (ResourceNotFoundException e) {
81 if (DebugException.DEBUG)
84 } catch (AdaptionException e) {
85 if (DebugException.DEBUG)
88 } catch (Throwable e) {
89 if (DebugException.DEBUG)