]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleModel.java
possibleObjectForType utility
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleModel.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 java.util.Collection;
15
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.common.request.IndexRoots;
19 import org.simantics.db.common.request.ResourceRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.simulation.ontology.SimulationResource;
22
23 public class PossibleModel extends ResourceRead<Resource> {
24
25     public PossibleModel(Resource resource) {
26         super(resource);
27     }
28
29     @Override
30     public Resource perform(ReadGraph graph) throws DatabaseException {
31
32         SimulationResource SIMU = SimulationResource.getInstance(graph);
33         if (graph.isInstanceOf(resource, SIMU.Model))
34             return resource;
35
36         Collection<Resource> result = graph.sync(new IndexRoots(resource));
37         if(result.size() == 1) {
38             Resource res = result.iterator().next(); 
39             if (graph.isInstanceOf(res, SIMU.Model))
40                 return res;
41         }
42         return null;
43         
44 //      SimulationResource SIMU = SimulationResource.getInstance(graph);
45 //      Layer0 L0 = Layer0.getInstance(graph);
46 //      
47 //        if (graph.isInstanceOf(resource, SIMU.Model))
48 //            return resource;
49 //        
50 //        Resource parent = graph.getPossibleObject(resource, L0.PartOf);
51 //        if (parent == null)
52 //            return null;
53 //        
54 //        else return graph.syncRequest(new PossibleModel(parent));
55
56     }
57
58 }