]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleActiveModelValuation.java
Merge "Documented difference of RuntimeEnvironmentRequest and Runti...quest2" into...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleActiveModelValuation.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.adapter.Valuations;
22
23 public class PossibleActiveModelValuation extends BinaryRead<Resource, String, Resource> {
24
25     public PossibleActiveModelValuation(Resource model) {
26         super(model, "");
27     }
28
29     public PossibleActiveModelValuation(Resource resource, String suffix) {
30         super(resource, suffix);
31     }
32
33     @Override
34     public Resource perform(ReadGraph graph) throws DatabaseException {
35         
36         try {
37
38                 String valuationName = null;
39                 
40                 Valuations valuations = graph.adapt(parameter, Valuations.class);
41
42                 String valuation = graph.syncRequest(new PossibleActiveExperimentPath(parameter));
43                 if(valuation != null) valuationName = valuation;
44
45                 if (valuationName == null) {
46                 valuationName = "BaseRealization";
47             }
48
49 //              System.out.println("possibleactivemodelvaluations uses valuation " + valuationName + " parameter2 = " + parameter2);
50                 
51             return valuations.getValue(graph, null, valuationName, parameter2);
52             
53         } catch (ResourceNotFoundException e) {
54             if (DebugException.DEBUG)
55                 e.printStackTrace();
56             return null;
57         } catch (AdaptionException e) {
58             if (DebugException.DEBUG)
59                 e.printStackTrace();
60             return null;
61         } catch (Throwable e) {
62             if (DebugException.DEBUG)
63                 e.printStackTrace();
64             return null;
65         }
66
67     }
68
69 }