1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.repository.ordi;
26
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30
31 import org.omwg.ontology.Ontology;
32 import org.wsmo.common.Entity;
33 import org.wsmo.common.IRI;
34 import org.wsmo.common.Identifier;
35 import org.wsmo.common.exception.SynchronisationException;
36 import org.wsmo.datastore.WsmoRepository;
37 import org.wsmo.mediator.Mediator;
38 import org.wsmo.service.Goal;
39 import org.wsmo.service.WebService;
40 import org.wsmostudio.runtime.extension.Initialisable;
41
42 import com.ontotext.ordi.exception.ORDIException;
43 import com.ontotext.ordi.wsmo4rdf.WsmoConnection;
44 import com.ontotext.ordi.wsmo4rdf.WsmoSource;
45
46 public class ORDIRepository implements WsmoRepository, Initialisable {
47
48 protected String description;
49
50 protected WsmoSource source;
51 protected WsmoConnection connection;
52 protected Map<Object, Object> params;
53
54 public void addGoal(Goal goal) throws SynchronisationException {
55 openConnectionToSource();
56 connection.addGoal(goal);
57 try {
58 connection.commit();
59 closeConnectionToSource();
60 } catch (ORDIException ordiEx) {
61 throw new SynchronisationException(ordiEx);
62 }
63 }
64
65 public void addMediator(Mediator med) throws SynchronisationException {
66 openConnectionToSource();
67 connection.addMediator(med);
68 try {
69 connection.commit();
70 closeConnectionToSource();
71 } catch (ORDIException ordiEx) {
72 throw new SynchronisationException(ordiEx);
73 }
74 }
75
76 public void addOntology(Ontology ont) throws SynchronisationException {
77 openConnectionToSource();
78 connection.addOntology(ont);
79 try {
80 connection.commit();
81 closeConnectionToSource();
82 } catch (ORDIException ordiEx) {
83 throw new SynchronisationException(ordiEx);
84 }
85 }
86
87 public void addWebService(WebService ws) throws SynchronisationException {
88 openConnectionToSource();
89 connection.addWebService(ws);
90 try {
91 connection.commit();
92 closeConnectionToSource();
93 } catch (ORDIException ordiEx) {
94 throw new SynchronisationException(ordiEx);
95 }
96 }
97
98 public void deleteGoal(IRI id) throws SynchronisationException {
99 openConnectionToSource();
100 connection.deleteGoal(id);
101 try {
102 connection.commit();
103 closeConnectionToSource();
104 } catch (ORDIException ordiEx) {
105 throw new SynchronisationException(ordiEx);
106 }
107 }
108
109 public void deleteMediator(IRI id) throws SynchronisationException {
110 openConnectionToSource();
111 connection.deleteMediator(id);
112 try {
113 connection.commit();
114 closeConnectionToSource();
115 } catch (ORDIException ordiEx) {
116 throw new SynchronisationException(ordiEx);
117 }
118 }
119
120 public void deleteOntology(IRI id) throws SynchronisationException {
121 openConnectionToSource();
122 connection.deleteOntology(id);
123 try {
124 connection.commit();
125 closeConnectionToSource();
126 } catch (ORDIException ordiEx) {
127 throw new SynchronisationException(ordiEx);
128 }
129 }
130
131 public void deleteWebService(IRI id) throws SynchronisationException {
132 openConnectionToSource();
133 connection.deleteWebService(id);
134 try {
135 connection.commit();
136 closeConnectionToSource();
137 } catch (ORDIException ordiEx) {
138 throw new SynchronisationException(ordiEx);
139 }
140 }
141
142 public Goal getGoal(IRI id) throws SynchronisationException {
143 openConnectionToSource();
144 Goal result = connection.getGoal(id);
145 closeConnectionToSource();
146 return result;
147 }
148
149 public Mediator getMediator(IRI id) throws SynchronisationException {
150 if (connection == null)
151 throw new SynchronisationException("Repository is not configured!");
152 openConnectionToSource();
153 Mediator mediator = connection.getMediator(id);
154 closeConnectionToSource();
155 return mediator;
156 }
157
158 public Ontology getOntology(IRI id) throws SynchronisationException {
159 openConnectionToSource();
160 Ontology ontology = connection.getOntology(id);
161 closeConnectionToSource();
162 return ontology;
163 }
164
165 public String getVersion() throws SynchronisationException {
166 return "pre-alfa";
167 }
168
169 public WebService getWebService(IRI id) throws SynchronisationException {
170 openConnectionToSource();
171 WebService webService = connection.getWebService(id);
172 closeConnectionToSource();
173 return webService;
174 }
175
176 public List<IRI> listGoals() throws SynchronisationException {
177 openConnectionToSource();
178 List<IRI> listGoals = connection.listGoals();
179 closeConnectionToSource();
180 return listGoals;
181 }
182
183 public List<IRI> listMediators() throws SynchronisationException {
184 openConnectionToSource();
185 List<IRI> listMediators = connection.listMediators();
186 closeConnectionToSource();
187 return listMediators;
188 }
189
190 public List<IRI> listOntologies() throws SynchronisationException {
191 openConnectionToSource();
192 List<IRI> listOntologies = connection.listOntologies();
193 closeConnectionToSource();
194 return listOntologies;
195 }
196
197 public List<IRI> listWebServices() throws SynchronisationException {
198 openConnectionToSource();
199 List<IRI> listWebServices = connection.listWebServices();
200 closeConnectionToSource();
201 return listWebServices;
202 }
203
204 public void saveGoal(Goal ont) throws SynchronisationException {
205 openConnectionToSource();
206 connection.saveGoal(ont);
207 try {
208 connection.commit();
209 closeConnectionToSource();
210 } catch (ORDIException ordiEx) {
211 throw new SynchronisationException(ordiEx);
212 }
213 }
214
215 public void saveMediator(Mediator med) throws SynchronisationException {
216 openConnectionToSource();
217 connection.saveMediator(med);
218 try {
219 connection.commit();
220 closeConnectionToSource();
221 } catch (ORDIException ordiEx) {
222 throw new SynchronisationException(ordiEx);
223 }
224 }
225
226 public void saveOntology(Ontology ont) throws SynchronisationException {
227 openConnectionToSource();
228 connection.saveOntology(ont);
229 try {
230 connection.commit();
231 closeConnectionToSource();
232 } catch (ORDIException ordiEx) {
233 throw new SynchronisationException(ordiEx);
234 }
235 }
236
237 public void saveWebService(WebService ws) throws SynchronisationException {
238 openConnectionToSource();
239 connection.saveWebService(ws);
240 try {
241 connection.commit();
242 closeConnectionToSource();
243 } catch (ORDIException ordiEx) {
244 throw new SynchronisationException(ordiEx);
245 }
246 }
247
248 public String getDescription() {
249 return description;
250 }
251
252 public void setDescription(String desc) {
253 description = desc;
254 }
255
256 @SuppressWarnings("unchecked")
257 public Entity load(Identifier id, Class clazz) {
258 openConnectionToSource();
259 Entity load = connection.load(id, clazz);
260 closeConnectionToSource();
261 return load;
262 }
263
264 public Set<Entity> load(Identifier id) {
265 openConnectionToSource();
266 Set<Entity> load = connection.load(id);
267 closeConnectionToSource();
268 return load;
269 }
270
271 @SuppressWarnings("unchecked")
272 public void remove(Identifier id, Class clazz) {
273 openConnectionToSource();
274 connection.remove(id, clazz);
275 try {
276 connection.commit();
277 closeConnectionToSource();
278 } catch (ORDIException ordiEx) {
279 throw new SynchronisationException(ordiEx);
280 }
281 }
282
283 public void remove(Identifier id) {
284 openConnectionToSource();
285 connection.remove(id);
286 try {
287 connection.commit();
288 closeConnectionToSource();
289 } catch (ORDIException ordiEx) {
290 throw new SynchronisationException(ordiEx);
291 }
292 }
293
294 public void save(Entity item) {
295 openConnectionToSource();
296 connection.save(item);
297 try {
298 connection.commit();
299 closeConnectionToSource();
300 } catch (ORDIException ordiEx) {
301 throw new SynchronisationException(ordiEx);
302 }
303 }
304
305 @SuppressWarnings("unchecked")
306 public void initialise(Map params) throws Exception {
307 this.params = params;
308 }
309
310 private void openConnectionToSource() {
311 params.put(WsmoSource.ORDI_SOURCE, this.source);
312 this.source = com.ontotext.ordi.Factory.create(WsmoSource.class, this.params);
313 this.connection = this.source.getConnection();
314 }
315
316 private void closeConnectionToSource() {
317 try {
318 this.connection.close();
319 this.connection = null;
320 } catch (ORDIException e) {
321 e.printStackTrace();
322 }
323 this.source.shutdown();
324 this.source = null;
325 }
326
327 }
328
329
330
331
332
333
334
335
336
337
338