]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph/src/org/simantics/browsing/ui/graph/tester/GraphTesters.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph / src / org / simantics / browsing / ui / graph / tester / GraphTesters.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.browsing.ui.graph.tester;
13
14 import org.simantics.Simantics;
15 import org.simantics.browsing.ui.Tester;
16 import org.simantics.browsing.ui.common.Testers;
17 import org.simantics.db.RequestProcessor;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.simulation.ontology.SimulationResource;
23
24 /**
25  * A facade class for constructing new {@link Tester} instances for standard
26  * graph based testing activities. Please use this class instead of directly
27  * referring to <code>org.simantics.browsing.ui.graph.tester</code> package
28  * classes.
29  * 
30  * @author Tuukka Lehtonen
31  */
32 public final class GraphTesters {
33
34     public static Tester pass() {
35         return Testers.PASS;
36     }
37
38     public static Tester fail() {
39         return Testers.FAIL;
40     }
41
42     /**
43      * @param clazz
44      * @return
45      * 
46      * TODO: throw exceptions, don't catch.
47      */
48     public static Tester type(final String uri) {
49         try {
50             return type(Simantics.getSession(), uri);
51         } catch (DatabaseException e) {
52             e.printStackTrace();
53             return fail();
54         }
55     }
56
57     public static Tester standardContextType(final String uri) {
58         try {
59             return standardContextType(Simantics.getSession(), uri);
60         } catch (DatabaseException e) {
61             e.printStackTrace();
62             return fail();
63         }
64     }
65
66     public static Tester standardContextType(Session s, final String uri) throws DatabaseException {
67         return new StandardContextHasSomeTypeTester(s, uri);
68     }
69
70     public static Tester type(Session s, final String uri) throws DatabaseException {
71         return new HasSomeTypeTester(s, uri);
72     }
73
74     public static Tester type(Resource resource) {
75         return new HasSomeTypeTester(resource);
76     }
77
78     /**
79      * @param uri
80      * @return
81      * 
82      * TODO: throw exceptions, don't catch.
83      */
84     public static Tester resource(final String uri) {
85         try {
86             return resource(Simantics.getSession(), uri);
87         } catch (DatabaseException e) {
88             e.printStackTrace();
89             return fail();
90         }
91     }
92
93     public static Tester resource(Session s, final String uri) throws DatabaseException {
94         return new EqualsResourceTester(s, uri);
95     }
96
97     public static Tester resource(Resource resource) {
98         return new EqualsResourceTester(resource);
99     }
100
101     public static Tester inherits(Resource resource) {
102         return new InheritsSomeTypeTester(resource);
103     }
104
105     public static Tester model() throws DatabaseException {
106         Session s = Simantics.getSession();
107         SimulationResource SIMU = SimulationResource.getInstance(s);
108         return new HasSomeTypeTester(SIMU.Model);
109     }
110
111     public static Tester type() {
112         return new HasSomeTypeTester(Simantics.getSession().getService(Layer0.class).Type);
113     }
114
115     public static Tester orderedSet() {
116         return new OrderedSetTester(Simantics.getSession());
117     }
118
119     public static Tester orderedSet(Session s) {
120         return new OrderedSetTester(s);
121     }
122
123     public static Tester hasRelatedObjects(Resource relation) {
124         return new HasRelatedObjectsTester(relation);
125     }
126
127     public static Tester hasRelatedObjects(RequestProcessor processor, String relationUri) throws DatabaseException {
128         return new HasRelatedObjectsTester(processor, relationUri);
129     }
130
131     public static Tester hasRelatedObjects(String relationUri) {
132         try {
133             return hasRelatedObjects(Simantics.getSession(), relationUri);
134         } catch (DatabaseException e) {
135             e.printStackTrace();
136             return fail();
137         }
138     }
139
140 }