1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.mapping;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.request.Read;
\r
17 import org.simantics.db.Session;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
20 public class MappingResource {
\r
22 public final Resource BinaryPredicateConstraint;
\r
23 public final Resource ClaimRule;
\r
24 public final Resource CompositeRule;
\r
25 public final Resource Constraint;
\r
26 public final Resource ConstraintConjunction;
\r
27 public final Resource ConstraintDisjunction;
\r
28 public final Resource ConstraintGroup;
\r
29 public final Resource DenyRule;
\r
30 public final Resource Domain;
\r
31 public final Resource ExistsConstraint;
\r
32 public final Resource HasBinaryPredicate;
\r
33 public final Resource HasChildRule;
\r
34 public final Resource HasCondition;
\r
35 public final Resource HasConstraint;
\r
36 public final Resource HasDomain;
\r
37 public final Resource HasElseRule;
\r
38 public final Resource HasMappingDescription;
\r
39 public final Resource HasParameter;
\r
40 public final Resource HasParameterRelation;
\r
41 public final Resource HasPredicate;
\r
42 public final Resource HasPredicateSuperrelation;
\r
43 public final Resource HasPrimaryConstraintGroup;
\r
44 public final Resource HasResource;
\r
45 public final Resource HasRule;
\r
46 public final Resource HasSubject;
\r
47 public final Resource HasThenRule;
\r
48 public final Resource HasUnaryPredicate;
\r
49 public final Resource IfRule;
\r
50 public final Resource Mapping;
\r
51 public final Resource MappingDescription;
\r
52 public final Resource MappingDomain;
\r
53 public final Resource MappingParameter;
\r
54 public final Resource MappingRule;
\r
55 public final Resource ResourceVariable;
\r
56 public final Resource Rule;
\r
57 public final Resource SourceDomain;
\r
58 public final Resource StaticDomain;
\r
59 public final Resource TargetDomain;
\r
60 public final Resource TripletConstraint;
\r
61 public final Resource UnaryPredicateConstraint;
\r
62 public final Resource UnlessRule;
\r
64 public static class URIs {
\r
65 public static final String BinaryPredicateConstraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/BinaryPredicateConstraint";
\r
66 public static final String ClaimRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/ClaimRule";
\r
67 public static final String CompositeRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/CompositeRule";
\r
68 public static final String Constraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/Constraint";
\r
69 public static final String ConstraintConjunction = "http://Projects/TypeSystemProject/MappingOntology/Constraints/ConstraintConjunction";
\r
70 public static final String ConstraintDisjunction = "http://Projects/TypeSystemProject/MappingOntology/Constraints/ConstraintDisjunction";
\r
71 public static final String ConstraintGroup = "http://Projects/TypeSystemProject/MappingOntology/Mappings/ConstraintGroup";
\r
72 public static final String DenyRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/DenyRule";
\r
73 public static final String Domain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/Domain";
\r
74 public static final String ExistsConstraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/ExistsConstraint";
\r
75 public static final String HasBinaryPredicate = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasBinaryPredicate";
\r
76 public static final String HasChildRule = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasChildRule";
\r
77 public static final String HasCondition = "http://Projects/TypeSystemProject/MappingOntology/Rules/HasCondition";
\r
78 public static final String HasConstraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasConstraint";
\r
79 public static final String HasDomain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasDomain";
\r
80 public static final String HasElseRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/HasElseRule";
\r
81 public static final String HasMappingDescription = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasMappingDescription";
\r
82 public static final String HasParameter = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasParameter";
\r
83 public static final String HasParameterRelation = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasParameterRelation";
\r
84 public static final String HasPredicate = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasPredicate";
\r
85 public static final String HasPredicateSuperrelation = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasPredicateSuperrelation";
\r
86 public static final String HasPrimaryConstraintGroup = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasPrimaryConstraintGroup";
\r
87 public static final String HasResource = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasResource";
\r
88 public static final String HasRule = "http://Projects/TypeSystemProject/MappingOntology/Mappings/HasRule";
\r
89 public static final String HasSubject = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasSubject";
\r
90 public static final String HasThenRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/HasThenRule";
\r
91 public static final String HasUnaryPredicate = "http://Projects/TypeSystemProject/MappingOntology/Constraints/HasUnaryPredicate";
\r
92 public static final String IfRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/IfRule";
\r
93 public static final String Mapping = "http://Projects/TypeSystemProject/MappingOntology/Mappings/Mapping";
\r
94 public static final String MappingDescription = "http://Projects/TypeSystemProject/MappingOntology/Mappings/MappingDescription";
\r
95 public static final String MappingDomain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/MappingDomain";
\r
96 public static final String MappingParameter = "http://Projects/TypeSystemProject/MappingOntology/Mappings/MappingParameter";
\r
97 public static final String MappingRule = "http://Projects/TypeSystemProject/MappingOntology/Mappings/MappingRule";
\r
98 public static final String ResourceVariable = "http://Projects/TypeSystemProject/MappingOntology/Constraints/ResourceVariable";
\r
99 public static final String Rule = "http://Projects/TypeSystemProject/MappingOntology/Rules/Rule";
\r
100 public static final String SourceDomain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/SourceDomain";
\r
101 public static final String StaticDomain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/StaticDomain";
\r
102 public static final String TargetDomain = "http://Projects/TypeSystemProject/MappingOntology/Mappings/TargetDomain";
\r
103 public static final String TripletConstraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/TripletConstraint";
\r
104 public static final String UnaryPredicateConstraint = "http://Projects/TypeSystemProject/MappingOntology/Constraints/UnaryPredicateConstraint";
\r
105 public static final String UnlessRule = "http://Projects/TypeSystemProject/MappingOntology/Rules/UnlessRule";
\r
108 public static Resource getResourceOrNull(ReadGraph graph, String uri) {
\r
110 return graph.getResource(uri);
\r
111 } catch(DatabaseException e) {
\r
112 System.err.println(e.getMessage());
\r
117 public MappingResource(ReadGraph graph) {
\r
118 BinaryPredicateConstraint = getResourceOrNull(graph, URIs.BinaryPredicateConstraint);
\r
119 ClaimRule = getResourceOrNull(graph, URIs.ClaimRule);
\r
120 CompositeRule = getResourceOrNull(graph, URIs.CompositeRule);
\r
121 Constraint = getResourceOrNull(graph, URIs.Constraint);
\r
122 ConstraintConjunction = getResourceOrNull(graph, URIs.ConstraintConjunction);
\r
123 ConstraintDisjunction = getResourceOrNull(graph, URIs.ConstraintDisjunction);
\r
124 ConstraintGroup = getResourceOrNull(graph, URIs.ConstraintGroup);
\r
125 DenyRule = getResourceOrNull(graph, URIs.DenyRule);
\r
126 Domain = getResourceOrNull(graph, URIs.Domain);
\r
127 ExistsConstraint = getResourceOrNull(graph, URIs.ExistsConstraint);
\r
128 HasBinaryPredicate = getResourceOrNull(graph, URIs.HasBinaryPredicate);
\r
129 HasChildRule = getResourceOrNull(graph, URIs.HasChildRule);
\r
130 HasCondition = getResourceOrNull(graph, URIs.HasCondition);
\r
131 HasConstraint = getResourceOrNull(graph, URIs.HasConstraint);
\r
132 HasDomain = getResourceOrNull(graph, URIs.HasDomain);
\r
133 HasElseRule = getResourceOrNull(graph, URIs.HasElseRule);
\r
134 HasMappingDescription = getResourceOrNull(graph, URIs.HasMappingDescription);
\r
135 HasParameter = getResourceOrNull(graph, URIs.HasParameter);
\r
136 HasParameterRelation = getResourceOrNull(graph, URIs.HasParameterRelation);
\r
137 HasPredicate = getResourceOrNull(graph, URIs.HasPredicate);
\r
138 HasPredicateSuperrelation = getResourceOrNull(graph, URIs.HasPredicateSuperrelation);
\r
139 HasPrimaryConstraintGroup = getResourceOrNull(graph, URIs.HasPrimaryConstraintGroup);
\r
140 HasResource = getResourceOrNull(graph, URIs.HasResource);
\r
141 HasRule = getResourceOrNull(graph, URIs.HasRule);
\r
142 HasSubject = getResourceOrNull(graph, URIs.HasSubject);
\r
143 HasThenRule = getResourceOrNull(graph, URIs.HasThenRule);
\r
144 HasUnaryPredicate = getResourceOrNull(graph, URIs.HasUnaryPredicate);
\r
145 IfRule = getResourceOrNull(graph, URIs.IfRule);
\r
146 Mapping = getResourceOrNull(graph, URIs.Mapping);
\r
147 MappingDescription = getResourceOrNull(graph, URIs.MappingDescription);
\r
148 MappingDomain = getResourceOrNull(graph, URIs.MappingDomain);
\r
149 MappingParameter = getResourceOrNull(graph, URIs.MappingParameter);
\r
150 MappingRule = getResourceOrNull(graph, URIs.MappingRule);
\r
151 ResourceVariable = getResourceOrNull(graph, URIs.ResourceVariable);
\r
152 Rule = getResourceOrNull(graph, URIs.Rule);
\r
153 SourceDomain = getResourceOrNull(graph, URIs.SourceDomain);
\r
154 StaticDomain = getResourceOrNull(graph, URIs.StaticDomain);
\r
155 TargetDomain = getResourceOrNull(graph, URIs.TargetDomain);
\r
156 TripletConstraint = getResourceOrNull(graph, URIs.TripletConstraint);
\r
157 UnaryPredicateConstraint = getResourceOrNull(graph, URIs.UnaryPredicateConstraint);
\r
158 UnlessRule = getResourceOrNull(graph, URIs.UnlessRule);
\r
161 public static MappingResource getInstance(ReadGraph graph) {
\r
162 Session session = graph.getSession();
\r
163 MappingResource ret = session.getService(MappingResource.class);
\r
165 ret = new MappingResource(graph);
\r
166 session.registerService(MappingResource.class, ret);
\r
171 public static MappingResource getInstance(Session session) throws DatabaseException {
\r
172 MappingResource ret = session.getService(MappingResource.class);
\r
174 ret = session.syncRequest(new Read<MappingResource>() {
\r
175 public MappingResource perform(ReadGraph graph) throws DatabaseException {
\r
176 return new MappingResource(graph);
\r
179 session.registerService(MappingResource.class, ret);
\r