]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleActiveVariableFromURI.java
Merge "Removed extra modules OntologyModule imported to namespace" into release/1...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleActiveVariableFromURI.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.exception.DebugException;
17 import org.simantics.db.common.request.BinaryRead;
18 import org.simantics.db.exception.AdaptionException;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.exception.ResourceNotFoundException;
21 import org.simantics.db.layer0.exception.MissingVariableException;
22 import org.simantics.db.layer0.variable.Variable;
23
24 public class PossibleActiveVariableFromURI extends BinaryRead<Resource, String, Variable> {
25
26     public PossibleActiveVariableFromURI(Resource model, String uri) {
27         super(model, uri);
28     }
29
30     @Override
31     public Variable perform(ReadGraph graph) throws DatabaseException {
32         try {
33                 String valuationName = null;
34             
35             Resource model = parameter;
36             if (model == null) return null;
37
38                 String valuation = graph.syncRequest(new PossibleActiveExperimentPath(model));
39                 if(valuation != null) valuationName = valuation;
40
41             if (valuationName == null) {
42                 valuationName = "/BaseRealization";
43             }
44
45             Variable modelVariable = graph.adapt(model, Variable.class);
46             Variable experimentVariable = modelVariable.browse(graph, valuationName+parameter2);
47             return experimentVariable;            
48         } catch (MissingVariableException e) {
49             if (DebugException.DEBUG)
50                 e.printStackTrace();
51             return null;
52         } catch (ResourceNotFoundException e) {
53             if (DebugException.DEBUG)
54                 e.printStackTrace();
55             return null;
56         } catch (AdaptionException e) {
57             if (DebugException.DEBUG)
58                 e.printStackTrace();
59             return null;
60         } catch (Throwable e) {
61             if (DebugException.DEBUG)
62                 e.printStackTrace();
63             return null;
64         }
65
66     }
67
68 }