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