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