1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.ontotext.wsmo4j.ontology;
20
21
22
23
24
25
26
27
28
29
30
31 import java.util.*;
32
33 import org.omwg.ontology.*;
34 import org.wsmo.common.*;
35 import org.wsmo.common.exception.*;
36
37 import com.ontotext.wsmo4j.common.*;
38
39
40 public class OntologyImpl
41 extends TopEntityImpl
42 implements Ontology {
43
44 private LinkedHashMap <Identifier, Concept> concepts;
45
46 private LinkedHashMap <Identifier, Relation> relations;
47
48 private LinkedHashMap <Identifier, Instance> instances;
49
50 private LinkedHashMap <Identifier, Axiom> axioms;
51
52 private LinkedHashMap <Identifier, RelationInstance> relationInstances;
53
54 public OntologyImpl(IRI thisID) {
55 super(thisID);
56
57 concepts = new LinkedHashMap <Identifier, Concept> ();
58 relations = new LinkedHashMap <Identifier, Relation> ();
59 instances = new LinkedHashMap <Identifier, Instance> ();
60 axioms = new LinkedHashMap <Identifier, Axiom> ();
61 relationInstances = new LinkedHashMap <Identifier, RelationInstance> ();
62 }
63
64 public Set <Concept> listConcepts()
65 throws SynchronisationException {
66 return new LinkedHashSet <Concept> (concepts.values());
67 }
68
69 public void addConcept(Concept concept)
70 throws SynchronisationException, InvalidModelException {
71 if (concept == null) {
72 throw new IllegalArgumentException();
73 }
74 concepts.put(concept.getIdentifier(), concept);
75 if (false == this.equals(concept.getOntology())) {
76 concept.setOntology(this);
77 }
78 }
79
80 public void removeConcept(Concept concept)
81 throws SynchronisationException, InvalidModelException {
82 if (concept == null) {
83 throw new IllegalArgumentException();
84 }
85 concepts.remove(concept.getIdentifier());
86 concept.setOntology(null);
87 }
88
89 public void removeConcept(Identifier conceptID)
90 throws SynchronisationException, InvalidModelException {
91 if (conceptID == null) {
92 throw new IllegalArgumentException();
93 }
94 Concept concept = concepts.get(conceptID);
95 if (concept != null) {
96 concept.setOntology(null);
97 }
98 concepts.remove(conceptID);
99 }
100
101 public Set <Relation> listRelations()
102 throws SynchronisationException {
103 return new LinkedHashSet <Relation> (relations.values());
104 }
105
106 public void addRelation(Relation relation)
107 throws SynchronisationException, InvalidModelException {
108 if (relation == null) {
109 throw new IllegalArgumentException();
110 }
111 relations.put(relation.getIdentifier(), relation);
112 if (false == this.equals(relation.getOntology())) {
113 relation.setOntology(this);
114 }
115 }
116
117 public void removeRelation(Relation relation)
118 throws SynchronisationException, InvalidModelException {
119 if (relation == null) {
120 throw new IllegalArgumentException();
121 }
122 relations.remove(relation.getIdentifier());
123 relation.setOntology(null);
124 }
125
126 public void removeRelation(Identifier relationID)
127 throws SynchronisationException, InvalidModelException {
128 if (relationID == null) {
129 throw new IllegalArgumentException();
130 }
131 Relation relation = relations.get(relationID);
132 if (relation != null) {
133 relation.setOntology(null);
134 }
135 relations.remove(relationID);
136 }
137
138 public Set <Instance> listInstances()
139 throws SynchronisationException {
140 return new LinkedHashSet <Instance> (instances.values());
141 }
142
143 public void addInstance(Instance instance)
144 throws SynchronisationException, InvalidModelException {
145 if (instance == null) {
146 throw new IllegalArgumentException();
147 }
148 instances.put(instance.getIdentifier(), instance);
149 if (false == this.equals(instance.getOntology())) {
150 instance.setOntology(this);
151 }
152 }
153
154 public void removeInstance(Instance instance)
155 throws SynchronisationException, InvalidModelException {
156 if (instance == null) {
157 throw new IllegalArgumentException();
158 }
159 instance.setOntology(null);
160 instances.remove(instance.getIdentifier());
161 }
162
163 public void removeInstance(Identifier instanceID)
164 throws SynchronisationException, InvalidModelException {
165 if (instanceID == null) {
166 throw new IllegalArgumentException();
167 }
168 Instance instance = instances.get(instanceID);
169 if (instance != null) {
170 instance.setOntology(null);
171 }
172 instances.remove(instanceID);
173 }
174
175 public Set <Axiom> listAxioms()
176 throws SynchronisationException {
177 return new LinkedHashSet <Axiom> (axioms.values());
178 }
179
180 public void addAxiom(Axiom axiom)
181 throws SynchronisationException, InvalidModelException {
182 if (axiom == null) {
183 throw new IllegalArgumentException();
184 }
185 axioms.put(axiom.getIdentifier(), axiom);
186 if (false == this.equals(axiom.getOntology())) {
187 axiom.setOntology(this);
188 }
189 }
190
191 public void removeAxiom(Axiom axiom)
192 throws SynchronisationException, InvalidModelException {
193 if (axiom == null) {
194 throw new IllegalArgumentException();
195 }
196 axioms.remove(axiom.getIdentifier());
197 axiom.setOntology(null);
198 }
199
200 public void removeAxiom(Identifier axiomID)
201 throws SynchronisationException, InvalidModelException {
202 if (axiomID == null) {
203 throw new IllegalArgumentException();
204 }
205 Axiom axiom = axioms.get(axiomID);
206 if (axiom != null) {
207 axiom.setOntology(null);
208 }
209 axioms.remove(axiomID);
210 }
211
212 public Set <RelationInstance> listRelationInstances()
213 throws SynchronisationException {
214 return new LinkedHashSet <RelationInstance> (relationInstances.values());
215 }
216
217 public void addRelationInstance(RelationInstance instance)
218 throws SynchronisationException, InvalidModelException {
219 if (instance == null) {
220 throw new IllegalArgumentException();
221 }
222 relationInstances.put(instance.getIdentifier(), instance);
223 if (false == this.equals(instance.getOntology())) {
224 instance.setOntology(this);
225 }
226 }
227
228 public void removeRelationInstance(RelationInstance instance)
229 throws SynchronisationException, InvalidModelException {
230 if (instance == null) {
231 throw new IllegalArgumentException();
232 }
233 relationInstances.remove(instance.getIdentifier());
234 instance.setOntology(null);
235 }
236
237 public void removeRelationInstance(Identifier instanceID)
238 throws SynchronisationException, InvalidModelException {
239 if (instanceID == null) {
240 throw new IllegalArgumentException();
241 }
242 RelationInstance instance = relationInstances.get(instanceID);
243 if (instance != null) {
244 instance.setOntology(null);
245 }
246
247 relationInstances.remove(instanceID);
248 }
249
250 public Concept findConcept(Identifier id)
251 throws SynchronisationException {
252
253 if (null == id) {
254 throw new IllegalArgumentException();
255 }
256 return concepts.get(id);
257 }
258
259 public Relation findRelation(Identifier id)
260 throws SynchronisationException {
261
262 if (null == id) {
263 throw new IllegalArgumentException();
264 }
265 return relations.get(id);
266 }
267
268 public Instance findInstance(Identifier id)
269 throws SynchronisationException {
270
271 if (null == id) {
272 throw new IllegalArgumentException();
273 }
274
275 return instances.get(id);
276 }
277
278 public Axiom findAxiom(Identifier id)
279 throws SynchronisationException {
280
281 if (null == id) {
282 throw new IllegalArgumentException();
283 }
284 return axioms.get(id);
285 }
286
287 public RelationInstance findRelationInstance(Identifier id)
288 throws SynchronisationException {
289
290 if (null == id) {
291 throw new IllegalArgumentException();
292 }
293 return relationInstances.get(id);
294 }
295
296 public Set <Entity> findEntity(Identifier id)
297 throws SynchronisationException {
298
299 if (null == id) {
300 throw new IllegalArgumentException();
301 }
302
303 Set <Entity> entities = new LinkedHashSet <Entity> ();
304 Entity entity = findAxiom(id);
305 if (entity != null)
306 entities.add(entity);
307 entity = findConcept(id);
308 if (entity != null)
309 entities.add(entity);
310 entity = findInstance(id);
311 if (entity != null)
312 entities.add(entity);
313 entity = findRelation(id);
314 if (entity != null)
315 entities.add(entity);
316 entity = findRelationInstance(id);
317 if (entity != null)
318 entities.add(entity);
319
320
321 return entities;
322 }
323
324 public boolean equals(Object object) {
325 if (object == this) {
326 return true;
327 }
328 if (object == null
329 || false == object instanceof Ontology) {
330 return false;
331 }
332 return super.equals(object);
333 }
334
335 }
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365