]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleExperimentVariable.java
possibleObjectForType utility
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleExperimentVariable.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.request;
13
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.BinaryRead;
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
26 public class PossibleExperimentVariable extends BinaryRead<String, ResourceArray, Variable> {
27
28     public PossibleExperimentVariable(String experiment, ResourceArray resource) {
29         super(experiment, resource);
30     }
31
32     @Override
33     public Variable perform(ReadGraph graph) throws DatabaseException {
34
35         try {
36                 
37                 Resource tail = parameter2.tail();
38                 Resource head = parameter2.head();
39
40                 if(!graph.hasStatement(tail)) return null;
41                 
42                 String valuationName = parameter;
43             
44             Resource model = graph.syncRequest(new PossibleModel(head));
45             if (model == null) return null;
46
47             VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);
48             Variable modelVariable = graph.adapt(model, Variable.class);
49             Variable experimentVariable = modelVariable.browse(graph, valuationName);
50             return variableInterface.getVariable(graph, experimentVariable, parameter2);
51             
52         } catch (MissingVariableException e) {
53             if (DebugException.DEBUG)
54                 e.printStackTrace();
55             return null;
56         } catch (ResourceNotFoundException e) {
57             if (DebugException.DEBUG)
58                 e.printStackTrace();
59             return null;
60         } catch (AdaptionException e) {
61             if (DebugException.DEBUG)
62                 e.printStackTrace();
63             return null;
64         } catch (Throwable e) {
65             if (DebugException.DEBUG)
66                 e.printStackTrace();
67             return null;
68         }
69
70     }
71
72 }