1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.deri.wsmo4j.common; |
19 |
| |
20 |
| import java.util.*; |
21 |
| |
22 |
| import org.omwg.logicalexpression.*; |
23 |
| import org.omwg.ontology.*; |
24 |
| import org.wsmo.common.*; |
25 |
| import org.wsmo.common.exception.*; |
26 |
| import org.wsmo.mediator.*; |
27 |
| import org.wsmo.service.*; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| public class ClearTopEntity { |
44 |
| |
45 |
| |
46 |
0
| public static void clearTopEntity(Mediator m) throws SynchronisationException, InvalidModelException{
|
47 |
0
| if (m == null){
|
48 |
0
| return;
|
49 |
| } |
50 |
0
| clearCommonElements(m);
|
51 |
0
| if (m.listSources()!=null){
|
52 |
0
| for (Iterator <IRI> mediatorI = new ArrayList <IRI>(m.listSources()).iterator(); mediatorI.hasNext();){
|
53 |
0
| m.removeSource(mediatorI.next());
|
54 |
| } |
55 |
| } |
56 |
0
| m.setTarget(null);
|
57 |
0
| m.setMediationService(null);
|
58 |
| } |
59 |
| |
60 |
0
| public static void clearTopEntity(ServiceDescription s) throws SynchronisationException, InvalidModelException{
|
61 |
0
| if (s == null){
|
62 |
0
| return;
|
63 |
| } |
64 |
0
| clearCommonElements(s);
|
65 |
0
| if (s.listInterfaces() != null){
|
66 |
0
| for (Iterator <Interface> interfaceI = new ArrayList <Interface> (s.listInterfaces()).iterator(); interfaceI.hasNext();){
|
67 |
0
| Interface i = interfaceI.next();
|
68 |
0
| clearNfp(i.getChoreography());
|
69 |
0
| clearNfp(i.getOrchestration());
|
70 |
0
| i.setChoreography(null);
|
71 |
0
| i.setOrchestration(null);
|
72 |
| |
73 |
0
| s.removeInterface(i);
|
74 |
| } |
75 |
| } |
76 |
0
| Capability cap = s.getCapability();
|
77 |
0
| if (cap==null){
|
78 |
0
| return;
|
79 |
| } |
80 |
0
| clearCommonElements(cap);
|
81 |
| |
82 |
0
| if (cap.listSharedVariables()!=null){
|
83 |
0
| for (Iterator <Variable> varI = new ArrayList <Variable>(cap.listSharedVariables()).iterator();varI.hasNext();){
|
84 |
0
| cap.removeSharedVariable(varI.next());
|
85 |
| } |
86 |
| } |
87 |
| |
88 |
0
| if (cap.listAssumptions()!=null){
|
89 |
0
| for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listAssumptions()).iterator();i.hasNext();){
|
90 |
0
| Axiom a = i.next();
|
91 |
0
| clearNfp(a);
|
92 |
0
| cap.removeAssumption(a);
|
93 |
| } |
94 |
| } |
95 |
0
| if (cap.listEffects()!=null){
|
96 |
0
| for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listEffects()).iterator();i.hasNext();){
|
97 |
0
| Axiom a = i.next();
|
98 |
0
| clearNfp(a);
|
99 |
0
| cap.removeEffect(a);
|
100 |
| } |
101 |
| } |
102 |
0
| if (cap.listPostConditions()!=null){
|
103 |
0
| for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listPostConditions()).iterator();i.hasNext();){
|
104 |
0
| Axiom a = i.next();
|
105 |
0
| clearNfp(a);
|
106 |
0
| cap.removePostCondition(a);
|
107 |
| } |
108 |
| } |
109 |
0
| if (cap.listPreConditions()!=null){
|
110 |
0
| for (Iterator <Axiom> i = new ArrayList <Axiom>(cap.listPreConditions()).iterator();i.hasNext();){
|
111 |
0
| Axiom a = i.next();
|
112 |
0
| clearNfp(a);
|
113 |
0
| cap.removePreCondition(a);
|
114 |
| } |
115 |
| } |
116 |
0
| s.setCapability(null);
|
117 |
| } |
118 |
| |
119 |
0
| public static void clearTopEntity(Ontology ont) throws SynchronisationException, InvalidModelException{
|
120 |
0
| if (ont == null){
|
121 |
0
| return;
|
122 |
| } |
123 |
| |
124 |
0
| if (ont.listConcepts()!=null){
|
125 |
0
| for (Iterator <Concept> conceptI = new ArrayList <Concept>(ont.listConcepts()).iterator(); conceptI.hasNext(); ){
|
126 |
0
| Concept concept = conceptI.next();
|
127 |
0
| if (concept.listSuperConcepts()!=null){
|
128 |
0
| for (Iterator <Concept> superI = new ArrayList <Concept>(concept.listSuperConcepts()).iterator(); superI.hasNext(); ){
|
129 |
0
| concept.removeSuperConcept(superI.next());
|
130 |
| } |
131 |
| } |
132 |
0
| if (concept.listAttributes()!=null){
|
133 |
0
| for (Iterator <Attribute> attrI = new ArrayList <Attribute>(concept.listAttributes()).iterator(); attrI.hasNext(); ){
|
134 |
0
| Attribute attr = attrI.next();
|
135 |
0
| attr.setConstraining(false);
|
136 |
0
| attr.setInverseOf(null);
|
137 |
0
| attr.setReflexive(false);
|
138 |
0
| attr.setSymmetric(false);
|
139 |
0
| attr.setReflexive(false);
|
140 |
0
| attr.setTransitive(false);
|
141 |
0
| attr.setMaxCardinality(Integer.MAX_VALUE);
|
142 |
0
| attr.setMinCardinality(0);
|
143 |
0
| for (Iterator <Type> typesI = new ArrayList <Type>(attr.listTypes()).iterator(); typesI.hasNext();){
|
144 |
0
| attr.removeType(typesI.next());
|
145 |
| } |
146 |
0
| concept.removeAttribute(attr);
|
147 |
0
| clearNfp(attr);
|
148 |
| } |
149 |
| } |
150 |
0
| clearNfp(concept);
|
151 |
0
| concept.setOntology(null);
|
152 |
| } |
153 |
| } |
154 |
| |
155 |
0
| if (ont.listInstances()!=null){
|
156 |
0
| for (Iterator <Instance> instanceI = new ArrayList <Instance>(ont.listInstances()).iterator(); instanceI.hasNext();){
|
157 |
0
| Instance instance = instanceI.next();
|
158 |
0
| if (instance.listConcepts()!=null){
|
159 |
0
| for (Iterator <Concept> memberOfI = new ArrayList <Concept>(instance.listConcepts()).iterator(); memberOfI.hasNext();){
|
160 |
0
| instance.removeConcept(memberOfI.next());
|
161 |
| } |
162 |
| } |
163 |
0
| if (instance.listAttributeValues()!=null){
|
164 |
0
| for (Iterator <Identifier> attributeI = new ArrayList <Identifier> (instance.listAttributeValues().keySet()).iterator(); attributeI.hasNext();){
|
165 |
0
| instance.removeAttributeValues(attributeI.next());
|
166 |
| } |
167 |
| } |
168 |
0
| clearNfp(instance);
|
169 |
0
| instance.setOntology(null);
|
170 |
| } |
171 |
| } |
172 |
| |
173 |
| |
174 |
0
| if (ont.listRelationInstances()!=null){
|
175 |
0
| for (Iterator <RelationInstance> instanceI = new ArrayList <RelationInstance> (ont.listRelationInstances()).iterator();instanceI.hasNext();){
|
176 |
0
| RelationInstance instance = instanceI.next();
|
177 |
0
| if (instance.listParameterValues()!=null){
|
178 |
0
| for (byte i = (byte)(instance.listParameterValues().size()-1); i>=0; i--){
|
179 |
0
| instance.setParameterValue(i,null);
|
180 |
| } |
181 |
| } |
182 |
0
| clearNfp(instance);
|
183 |
0
| instance.setOntology(null);
|
184 |
| } |
185 |
| } |
186 |
| |
187 |
| |
188 |
0
| if (ont.listRelations()!=null){
|
189 |
0
| for (Iterator <Relation> relI = new ArrayList <Relation> (ont.listRelations()).iterator();relI.hasNext();){
|
190 |
0
| Relation rel = relI.next();
|
191 |
0
| if (rel.listParameters()!=null){
|
192 |
0
| for (byte i = (byte)(rel.listParameters().size()-1); i>=0; i--){
|
193 |
0
| rel.removeParameter(i);
|
194 |
| } |
195 |
| } |
196 |
0
| if (rel.listSuperRelations()!=null){
|
197 |
0
| for (Iterator <Relation> superI = new ArrayList <Relation> (rel.listSuperRelations()).iterator();superI.hasNext();){
|
198 |
0
| rel.removeSuperRelation(superI.next());
|
199 |
| } |
200 |
| } |
201 |
0
| if (rel.listRelationInstances()!= null) {
|
202 |
0
| for (Iterator <RelationInstance> relInstI = new ArrayList <RelationInstance> (rel.listRelationInstances()).iterator();relInstI.hasNext();) {
|
203 |
0
| rel.removeRelationInstance(relInstI.next());
|
204 |
| } |
205 |
| } |
206 |
0
| clearNfp(rel);
|
207 |
0
| rel.setOntology(null);
|
208 |
| } |
209 |
| } |
210 |
| |
211 |
| |
212 |
0
| if(ont.listAxioms()!=null){
|
213 |
0
| for (Iterator <Axiom> axiomI = new ArrayList <Axiom> (ont.listAxioms()).iterator();axiomI.hasNext();){
|
214 |
0
| Axiom a = axiomI.next();
|
215 |
0
| for (Iterator <LogicalExpression> defI = new ArrayList <LogicalExpression> (a.listDefinitions()).iterator(); defI.hasNext();){
|
216 |
0
| a.removeDefinition(defI.next());
|
217 |
| } |
218 |
0
| clearNfp(a);
|
219 |
0
| a.setOntology(null);
|
220 |
| } |
221 |
| } |
222 |
| |
223 |
| |
224 |
0
| clearCommonElements(ont);
|
225 |
| } |
226 |
| |
227 |
0
| private static void clearNfp(Entity e) throws SynchronisationException, InvalidModelException{
|
228 |
0
| if (e!=null && e.listNFPValues()!=null){
|
229 |
0
| for (Iterator <IRI> nfpI = new ArrayList <IRI> (e.listNFPValues().keySet()).iterator(); nfpI.hasNext(); ){
|
230 |
0
| e.removeNFP(nfpI.next());
|
231 |
| } |
232 |
| } |
233 |
| |
234 |
| } |
235 |
| |
236 |
0
| private static void clearCommonElements(TopEntity te) throws SynchronisationException, InvalidModelException{
|
237 |
| |
238 |
0
| if (te==null){
|
239 |
0
| return;
|
240 |
| } |
241 |
0
| if (te.listMediators()!=null){
|
242 |
0
| for (Iterator <IRI> medI = new ArrayList <IRI> (te.listMediators()).iterator(); medI.hasNext();){
|
243 |
0
| te.removeMediator(medI.next());
|
244 |
| } |
245 |
| } |
246 |
| |
247 |
0
| if (te.listNamespaces()!=null){
|
248 |
0
| for (Iterator <Namespace> nsI = new ArrayList <Namespace>(te.listNamespaces()).iterator(); nsI.hasNext();){
|
249 |
0
| te.removeNamespace(nsI.next());
|
250 |
| } |
251 |
| } |
252 |
| |
253 |
0
| if(te.listOntologies()!=null){
|
254 |
0
| for (Iterator <Ontology> ontI = new ArrayList <Ontology> (te.listOntologies()).iterator(); ontI.hasNext();){
|
255 |
0
| te.removeOntology(ontI.next());
|
256 |
| } |
257 |
| } |
258 |
0
| te.setWsmlVariant(null);
|
259 |
0
| te.setDefaultNamespace((IRI)null);
|
260 |
0
| clearNfp(te);
|
261 |
| } |
262 |
| |
263 |
| |
264 |
| } |
265 |
| |
266 |
| |
267 |
| |
268 |
| |
269 |
| |
270 |
| |
271 |
| |
272 |
| |
273 |
| |
274 |
| |
275 |
| |
276 |
| |
277 |
| |
278 |
| |
279 |
| |
280 |
| |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
| |
289 |
| |
290 |
| |
291 |
| |
292 |
| |