1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.ontotext.wsmo4j.common;
20
21
22 import java.util.Collections;
23 import java.util.LinkedHashMap;
24 import java.util.LinkedHashSet;
25 import java.util.Set;
26
27 import org.omwg.ontology.Ontology;
28 import org.wsmo.common.IRI;
29 import org.wsmo.common.Identifier;
30 import org.wsmo.common.Namespace;
31 import org.wsmo.common.TopEntity;
32
33
34
35
36
37
38
39
40
41
42 public class TopEntityImpl extends EntityImpl implements TopEntity {
43
44 private String wsmlVariant;
45
46 private Namespace defaultNS;
47
48 private LinkedHashSet <IRI> mediators;
49
50 private LinkedHashMap <String, Namespace> namespaces;
51
52 private LinkedHashMap <Identifier, Ontology> ontologies;
53
54 public TopEntityImpl(Identifier id) {
55 super(id);
56 mediators = new LinkedHashSet <IRI>();
57 namespaces = new LinkedHashMap <String, Namespace> ();
58 ontologies = new LinkedHashMap <Identifier, Ontology> ();
59 }
60
61
62 public String getWsmlVariant() {
63
64
65
66
67
68
69
70
71
72 return this.wsmlVariant;
73
74 }
75
76 public void setWsmlVariant(String variant) {
77 if (variant != null
78 && variant.trim().length() == 0) {
79 variant = null;
80 }
81 this.wsmlVariant = variant;
82 }
83
84 public Set <Namespace> listNamespaces() {
85 return new LinkedHashSet <Namespace>(namespaces.values());
86 }
87
88 public void addNamespace(Namespace ns) {
89 if (ns == null) {
90 throw new IllegalArgumentException();
91 }
92 namespaces.put(ns.getPrefix(), ns);
93 }
94
95 public void removeNamespace(String prefix) {
96 if (prefix == null) {
97 throw new IllegalArgumentException();
98 }
99 namespaces.remove(prefix);
100 }
101
102 public void removeNamespace(Namespace ns) {
103 if (ns == null) {
104 throw new IllegalArgumentException();
105 }
106 removeNamespace(ns.getPrefix());
107 }
108
109 public Namespace findNamespace(String prefix) {
110 if (prefix == null) {
111 throw new IllegalArgumentException();
112 }
113 return namespaces.get(prefix);
114 }
115
116 public Namespace getDefaultNamespace() {
117 return this.defaultNS;
118 }
119
120 public void setDefaultNamespace(Namespace ns) {
121 this.defaultNS = ns;
122 }
123
124
125
126
127
128
129 public void setDefaultNamespace(IRI iri) {
130 if (iri == null) {
131 this.defaultNS = null;
132 }
133 else {
134 this.defaultNS = new NamespaceImpl("", iri);
135 }
136 }
137
138 public void addMediator(IRI mediator) {
139 if (mediator == null) {
140 throw new IllegalArgumentException();
141 }
142 mediators.add(mediator);
143 }
144
145 public void removeMediator(IRI mediator) {
146 if (mediator == null) {
147 throw new IllegalArgumentException();
148 }
149 mediators.remove(mediator);
150 }
151
152
153 public Set <IRI> listMediators() {
154 return Collections.unmodifiableSet(mediators);
155 }
156
157 public void addOntology(Ontology ontology) {
158 if (ontology == null) {
159 throw new IllegalArgumentException();
160 }
161 ontologies.put(ontology.getIdentifier(), ontology);
162 }
163
164 public void removeOntology(IRI iri) {
165 if (iri == null) {
166 throw new IllegalArgumentException();
167 }
168 ontologies.remove(iri);
169 }
170
171 public void removeOntology(Ontology ontology) {
172 if (ontology == null) {
173 throw new IllegalArgumentException();
174 }
175 ontologies.remove(ontology.getIdentifier());
176 }
177
178 public Set <Ontology> listOntologies() {
179 return new LinkedHashSet <Ontology> (ontologies.values());
180 }
181
182 public boolean equals(Object object) {
183 if (object == this) {
184 return true;
185 }
186 if (object == null
187 || false == object instanceof TopEntity) {
188 return false;
189 }
190 return super.equals(object);
191 }
192 }
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233