]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleExperimentVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleExperimentVariable.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.layer0.request;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.ResourceArray;\r
17 import org.simantics.db.common.exception.DebugException;\r
18 import org.simantics.db.common.request.BinaryRead;\r
19 import org.simantics.db.exception.AdaptionException;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.db.exception.ResourceNotFoundException;\r
22 import org.simantics.db.layer0.exception.MissingVariableException;\r
23 import org.simantics.db.layer0.variable.Variable;\r
24 import org.simantics.db.layer0.variable.VariableInterface;\r
25 \r
26 public class PossibleExperimentVariable extends BinaryRead<String, ResourceArray, Variable> {\r
27 \r
28     public PossibleExperimentVariable(String experiment, ResourceArray resource) {\r
29         super(experiment, resource);\r
30     }\r
31 \r
32     @Override\r
33     public Variable perform(ReadGraph graph) throws DatabaseException {\r
34 \r
35         try {\r
36                 \r
37                 Resource tail = parameter2.tail();\r
38                 Resource head = parameter2.head();\r
39 \r
40                 if(!graph.hasStatement(tail)) return null;\r
41                 \r
42                 String valuationName = parameter;\r
43             \r
44             Resource model = graph.syncRequest(new PossibleModel(head));\r
45             if (model == null) return null;\r
46 \r
47             VariableInterface variableInterface = graph.adapt(model, VariableInterface.class);\r
48             Variable modelVariable = graph.adapt(model, Variable.class);\r
49             Variable experimentVariable = modelVariable.browse(graph, valuationName);\r
50             return variableInterface.getVariable(graph, experimentVariable, parameter2);\r
51             \r
52         } catch (MissingVariableException e) {\r
53             if (DebugException.DEBUG)\r
54                 e.printStackTrace();\r
55             return null;\r
56         } catch (ResourceNotFoundException e) {\r
57             if (DebugException.DEBUG)\r
58                 e.printStackTrace();\r
59             return null;\r
60         } catch (AdaptionException e) {\r
61             if (DebugException.DEBUG)\r
62                 e.printStackTrace();\r
63             return null;\r
64         } catch (Throwable e) {\r
65             if (DebugException.DEBUG)\r
66                 e.printStackTrace();\r
67             return null;\r
68         }\r
69 \r
70     }\r
71 \r
72 }\r