View | Details | Raw Unified | Return to bug 157715
Collapse All | Expand All

(-)src/org/eclipse/uml2/uml/internal/operations/ComponentOperations.java (-114 / +154 lines)
Lines 8-35 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *   IBM - initial API and implementation
9
 *   IBM - initial API and implementation
10
 *
10
 *
11
 * $Id: ComponentOperations.java,v 1.10 2006/03/08 19:03:02 khussey Exp $
11
 * $Id: ComponentOperations.java,v 1.10.2.1 2006/08/16 17:19:40 khussey Exp $
12
 */
12
 */
13
package org.eclipse.uml2.uml.internal.operations;
13
package org.eclipse.uml2.uml.internal.operations;
14
14
15
import java.util.Iterator;
16
15
import org.eclipse.emf.common.util.ECollections;
17
import org.eclipse.emf.common.util.ECollections;
16
import org.eclipse.emf.common.util.EList;
18
import org.eclipse.emf.common.util.EList;
17
18
import java.util.Iterator;
19
import org.eclipse.emf.common.util.UniqueEList;
19
import org.eclipse.emf.common.util.UniqueEList;
20
import org.eclipse.emf.ecore.InternalEObject;
20
import org.eclipse.emf.ecore.InternalEObject;
21
import org.eclipse.emf.ecore.util.InternalEList;
21
import org.eclipse.emf.ecore.util.InternalEList;
22
import org.eclipse.uml2.common.util.UnionEObjectEList;
22
import org.eclipse.uml2.common.util.UnionEObjectEList;
23
import org.eclipse.uml2.uml.BehavioredClassifier;
23
import org.eclipse.uml2.uml.Classifier;
24
import org.eclipse.uml2.uml.Classifier;
24
import org.eclipse.uml2.uml.Component;
25
import org.eclipse.uml2.uml.Component;
25
import org.eclipse.uml2.uml.Enumeration;
26
import org.eclipse.uml2.uml.ComponentRealization;
26
import org.eclipse.uml2.uml.ComponentRealization;
27
import org.eclipse.uml2.uml.Dependency;
27
import org.eclipse.uml2.uml.Dependency;
28
import org.eclipse.uml2.uml.Enumeration;
28
import org.eclipse.uml2.uml.Interface;
29
import org.eclipse.uml2.uml.Interface;
29
import org.eclipse.uml2.uml.PrimitiveType;
30
31
import org.eclipse.uml2.uml.InterfaceRealization;
32
import org.eclipse.uml2.uml.Port;
30
import org.eclipse.uml2.uml.Port;
31
import org.eclipse.uml2.uml.PrimitiveType;
32
import org.eclipse.uml2.uml.Realization;
33
import org.eclipse.uml2.uml.UMLPackage;
33
import org.eclipse.uml2.uml.UMLPackage;
34
import org.eclipse.uml2.uml.Usage;
34
import org.eclipse.uml2.uml.Usage;
35
35
Lines 123-131 Link Here
123
	 * <!-- end-model-doc -->
123
	 * <!-- end-model-doc -->
124
	 * @generated NOT
124
	 * @generated NOT
125
	 */
125
	 */
126
	public static EList realizedInterfaces(Component component,
126
	public static EList realizedInterfaces( Component component,
127
			Classifier classifier) {
127
			Classifier classifier) {
128
		return realizedInterfaces(component, classifier, true);
129
	}
128
130
131
	protected static EList realizedInterfaces(Component component,
132
			Classifier classifier, boolean resolve) {
129
		EList realizedInterfaces = new UniqueEList.FastCompare();
133
		EList realizedInterfaces = new UniqueEList.FastCompare();
130
134
131
		for (Iterator clientDependencies = classifier.getClientDependencies()
135
		for (Iterator clientDependencies = classifier.getClientDependencies()
Lines 133-143 Link Here
133
137
134
			Dependency dependency = (Dependency) clientDependencies.next();
138
			Dependency dependency = (Dependency) clientDependencies.next();
135
139
136
			if (dependency instanceof ComponentRealization) {
140
			if (dependency instanceof Realization) {
137
141
				Iterator suppliers = resolve
138
				for (Iterator suppliers = ((InternalEList) dependency
142
					? dependency.getSuppliers().iterator()
139
					.getSuppliers()).basicIterator(); suppliers.hasNext();) {
143
					: ((InternalEList) dependency.getSuppliers())
144
						.basicIterator();
140
145
146
				while (suppliers.hasNext()) {
141
					Object supplier = suppliers.next();
147
					Object supplier = suppliers.next();
142
148
143
					if (supplier instanceof Interface) {
149
					if (supplier instanceof Interface) {
Lines 163-191 Link Here
163
	 */
169
	 */
164
	public static EList usedInterfaces(Component component,
170
	public static EList usedInterfaces(Component component,
165
			Classifier classifier) {
171
			Classifier classifier) {
166
		EList usedInterfaces = new UniqueEList.FastCompare();
172
		return usedInterfaces(component, classifier, true);
167
173
	}
168
		for (Iterator clientDependencies = classifier.getClientDependencies()
169
			.iterator(); clientDependencies.hasNext();) {
170
171
			Dependency dependency = (Dependency) clientDependencies.next();
172
173
			if (dependency instanceof Usage) {
174
174
175
				for (Iterator suppliers = ((InternalEList) dependency
175
   
176
					.getSuppliers()).basicIterator(); suppliers.hasNext();) {
176
	protected static EList usedInterfaces(Component component, Classifier classifier, boolean resolve) {
177
        EList usedInterfaces = new UniqueEList.FastCompare();
178
179
        for (Iterator clientDependencies = classifier.getClientDependencies()
180
            .iterator(); clientDependencies.hasNext();) {
181
182
            Dependency dependency = (Dependency) clientDependencies.next();
183
184
            if (dependency instanceof Usage) {
185
                Iterator suppliers = resolve ? dependency.getSuppliers()
186
                    .iterator()
187
                    : ((InternalEList) dependency.getSuppliers())
188
                        .basicIterator();
189
190
                while (suppliers.hasNext()) {
191
                    Object supplier = suppliers.next();
192
193
                    if (supplier instanceof Interface) {
194
                        usedInterfaces.add(supplier);
195
                    }
196
                }
197
            }
198
        }
177
199
178
					Object supplier = suppliers.next();
200
        return ECollections.unmodifiableEList(usedInterfaces);
179
201
    }
180
					if (supplier instanceof Interface) {
181
						usedInterfaces.add(supplier);
182
					}
183
				}
184
			}
185
		}
186
187
		return ECollections.unmodifiableEList(usedInterfaces);
188
	}
189
202
190
	/**
203
	/**
191
	 * <!-- begin-user-doc -->
204
	 * <!-- begin-user-doc -->
Lines 204-293 Link Here
204
	 * @generated NOT
217
	 * @generated NOT
205
	 */
218
	 */
206
	public static EList getRequireds(Component component) {
219
	public static EList getRequireds(Component component) {
207
		EList requireds = new UniqueEList.FastCompare(component
220
        EList requireds = new UniqueEList.FastCompare(usedInterfaces(component,
208
			.usedInterfaces(component));
221
            component, false));
209
210
		for (Iterator realizations = component.getRealizations().iterator(); realizations
211
			.hasNext();) {
212
222
213
			Classifier realizingClassifier = ((ComponentRealization) realizations
223
        for (Iterator realizations = component.getRealizations().iterator(); realizations
214
				.next()).getRealizingClassifier();
224
            .hasNext();) {
215
225
            Classifier realizingClassifier = ((ComponentRealization) realizations
216
			if (realizingClassifier != null) {
226
                .next()).getRealizingClassifier();
217
				requireds.addAll(component.usedInterfaces(realizingClassifier));
227
            if (realizingClassifier != null) {
218
			}
228
                requireds.addAll(usedInterfaces(component, realizingClassifier,
219
		}
229
                    false));
220
230
                for (Iterator allParents = realizingClassifier.allParents()
221
		for (Iterator ownedPorts = component.getOwnedPorts().iterator(); ownedPorts
231
                    .iterator(); allParents.hasNext();) {
222
			.hasNext();) {
232
                    requireds.addAll(usedInterfaces(component,
223
233
                        (Classifier) allParents.next(), false));
224
			requireds.addAll(((InternalEList) ((Port) ownedPorts.next())
234
                }
225
				.getRequireds()).basicList());
235
            }
226
		}
236
        }
227
237
        for (Iterator ownedPorts = component.getOwnedPorts().iterator(); ownedPorts
228
		return new UnionEObjectEList((InternalEObject) component,
238
            .hasNext();) {
229
			UMLPackage.Literals.COMPONENT__REQUIRED, requireds.size(),
239
230
			requireds.toArray());
240
            requireds.addAll(((InternalEList) ((Port) ownedPorts.next())
231
	}
241
                .getRequireds()).basicList());
242
        }
243
        return new UnionEObjectEList((InternalEObject) component,
244
            UMLPackage.Literals.COMPONENT__REQUIRED, requireds.size(),
245
            requireds.toArray());
246
    }
232
247
233
	/**
248
	/**
234
	 * <!-- begin-user-doc -->
249
     * <!-- begin-user-doc --> 
235
	 * <!-- end-user-doc -->
250
     * <!-- end-user-doc --> 
236
	 * <!-- begin-model-doc -->
251
     * <!-- begin-model-doc -->
237
	 * result = let implementedInterfaces = self.implementation->collect(impl|impl.contract) and
252
     * result = let implementedInterfaces =
238
	 * 
253
     * self.implementation->collect(impl|impl.contract) and
239
	 *   let realizedInterfaces = RealizedInterfaces(self) and
254
     * 
240
	 * 
255
     * let realizedInterfaces = RealizedInterfaces(self) and
241
	 *   let realizingClassifierInterfaces = RealizedInterfaces(self.realizingClassifier) and
256
     * 
242
	 * 
257
     * let realizingClassifierInterfaces =
243
	 *   let typesOfRequiredPorts = self.ownedPort.provided in
258
     * RealizedInterfaces(self.realizingClassifier) and
244
	 * 
259
     * 
245
	 *     (((implementedInterfaces->union(realizedInterfaces)->union(realizingClassifierInterfaces))->
260
     * let typesOfRequiredPorts = self.ownedPort.provided in
246
	 * 
261
     * 
247
	 *       union(typesOfRequiredPorts))->asSet()
262
     * (((implementedInterfaces->union(realizedInterfaces)->union(realizingClassifierInterfaces))->
248
	 * <!-- end-model-doc -->
263
     * 
249
	 * @generated NOT
264
     * union(typesOfRequiredPorts))->asSet() 
250
	 */
265
     * <!-- end-model-doc -->
266
     * 
267
     * @generated NOT
268
     */
251
	public static EList getProvideds(Component component) {
269
	public static EList getProvideds(Component component) {
252
		EList provideds = new UniqueEList.FastCompare();
270
        EList provideds = new UniqueEList.FastCompare(realizedInterfaces(
253
271
            component, component, false));
254
		for (Iterator interfaceRealizations = component
255
			.getInterfaceRealizations().iterator(); interfaceRealizations
256
			.hasNext();) {
257
258
			Interface contract = (Interface) ((InterfaceRealization) interfaceRealizations
259
				.next()).eGet(
260
				UMLPackage.Literals.INTERFACE_REALIZATION__CONTRACT, false);
261
262
			if (contract != null) {
263
				provideds.add(contract);
264
			}
265
		}
266
267
		provideds.addAll(component.realizedInterfaces(component));
268
269
		for (Iterator realizations = component.getRealizations().iterator(); realizations
270
			.hasNext();) {
271
272
			Classifier realizingClassifier = ((ComponentRealization) realizations
273
				.next()).getRealizingClassifier();
274
272
275
			if (realizingClassifier != null) {
273
        for (Iterator realizations = component.getRealizations().iterator(); realizations
276
				provideds.addAll(component
274
            .hasNext();) {
277
					.realizedInterfaces(realizingClassifier));
275
            Classifier realizingClassifier = ((ComponentRealization) realizations
278
			}
276
                .next()).getRealizingClassifier();
279
		}
277
            if (realizingClassifier != null) {
280
278
                provideds.addAll(realizedInterfaces(component,
281
		for (Iterator ownedPorts = component.getOwnedPorts().iterator(); ownedPorts
279
                    realizingClassifier, false));
282
			.hasNext();) {
280
                for (Iterator allParents = realizingClassifier.allParents()
283
281
                    .iterator(); allParents.hasNext();) {
284
			provideds.addAll(((InternalEList) ((Port) ownedPorts.next())
282
                    provideds.addAll(realizedInterfaces(component,
285
				.getProvideds()).basicList());
283
                        (Classifier) allParents.next(), false));
286
		}
284
                }
287
285
            }
288
		return new UnionEObjectEList((InternalEObject) component,
286
        }
289
			UMLPackage.Literals.COMPONENT__PROVIDED, provideds.size(),
287
        for (Iterator ownedPorts = component.getOwnedPorts().iterator(); ownedPorts
290
			provideds.toArray());
288
            .hasNext();) {
291
	}
289
            provideds.addAll(((InternalEList) ((Port) ownedPorts.next())
290
                .getProvideds()).basicList());
291
        }
292
        return new UnionEObjectEList((InternalEObject) component,
293
            UMLPackage.Literals.COMPONENT__PROVIDED, provideds.size(),
294
            provideds.toArray());
295
    }
296
    
297
    protected static EList getAllProvideds(Component component) {
298
        EList directlyProvidedInterfaces = new UniqueEList.FastCompare(
299
            component.getProvideds());
300
301
        for (Iterator allComponentParents = component.allParents().iterator(); allComponentParents
302
            .hasNext();) {
303
            Classifier parent = (Classifier) allComponentParents.next();
304
            if (parent instanceof Component) {
305
                directlyProvidedInterfaces.addAll(((Component) parent)
306
                    .getProvideds());
307
            } else if (parent instanceof BehavioredClassifier) {
308
                directlyProvidedInterfaces
309
                    .addAll(((BehavioredClassifier) parent)
310
                        .getImplementedInterfaces());
311
            }
312
        }
313
        return ECollections.unmodifiableEList(directlyProvidedInterfaces);
314
    }
315
    
316
    protected static EList getAllRequireds(Component component) {
317
        EList directlyRequiredInterfaces = new UniqueEList.FastCompare(
318
            component.getRequireds());
319
320
        for (Iterator allComponentParents = component.allParents().iterator(); allComponentParents
321
            .hasNext();) {
322
            Classifier parent = (Classifier) allComponentParents.next();
323
            if (parent instanceof Component) {
324
                directlyRequiredInterfaces.addAll(((Component) parent)
325
                    .getRequireds());
326
            } else {
327
                directlyRequiredInterfaces.addAll(parent.getUsedInterfaces());
328
            }
329
        }
330
        return ECollections.unmodifiableEList(directlyRequiredInterfaces);
331
    }
292
332
293
} // ComponentOperations
333
} // ComponentOperations
(-)src/org/eclipse/uml2/uml/internal/operations/ConnectableElementOperations.java (-60 / +53 lines)
Lines 12-23 Link Here
12
 */
12
 */
13
package org.eclipse.uml2.uml.internal.operations;
13
package org.eclipse.uml2.uml.internal.operations;
14
14
15
import java.util.Collection;
16
import java.util.Iterator;
15
import java.util.Iterator;
17
16
18
import org.eclipse.emf.common.util.ECollections;
17
import org.eclipse.emf.common.util.ECollections;
19
import org.eclipse.emf.common.util.EList;
18
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.emf.common.util.UniqueEList;
19
import org.eclipse.emf.common.util.UniqueEList;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.uml2.uml.BehavioredClassifier;
21
import org.eclipse.uml2.uml.BehavioredClassifier;
22
import org.eclipse.uml2.uml.Classifier;
22
import org.eclipse.uml2.uml.Classifier;
23
import org.eclipse.uml2.uml.Component;
23
import org.eclipse.uml2.uml.Component;
Lines 40-108 Link Here
40
	protected static EList getRequiredInterfaces(
40
	protected static EList getRequiredInterfaces(
41
			ConnectableElement connectableElement) {
41
			ConnectableElement connectableElement) {
42
42
43
		if (connectableElement instanceof Port) {
43
        EList directlyRequiredInterfaces = new UniqueEList.FastCompare();
44
			Collection requireds = ((Port) connectableElement).getRequireds();
44
        if (connectableElement instanceof Port) {
45
			EList requiredInterfaces = new UniqueEList.FastCompare(requireds);
45
            directlyRequiredInterfaces.addAll(((Port) connectableElement)
46
46
                .getRequireds());
47
			for (Iterator r = requireds.iterator(); r.hasNext();) {
47
        } else if (connectableElement instanceof Property) {
48
				ClassifierOperations.allParents((Interface) r.next(),
48
            Type type = ((Property) connectableElement).getType();
49
					requiredInterfaces);
49
            if (type instanceof Component) {
50
			}
50
                directlyRequiredInterfaces.addAll(ComponentOperations
51
51
                    .getAllRequireds((Component) type));
52
			return requiredInterfaces;
52
            } else if (type instanceof Classifier) {
53
		} else if (connectableElement instanceof Property) {
53
                directlyRequiredInterfaces.addAll(((Classifier) type)
54
			Type type = ((Property) connectableElement).getType();
54
                    .getAllUsedInterfaces());
55
55
            }
56
			if (type instanceof Component) {
56
        }
57
				return ((Component) type).getRequireds();
57
        EList allRequiredInterfaces = new UniqueEList.FastCompare(
58
			} else if (type instanceof Classifier) {
58
            directlyRequiredInterfaces);
59
				return ((Classifier) type).getAllUsedInterfaces();
59
        for (Iterator r = directlyRequiredInterfaces.iterator(); r.hasNext();) {
60
			}
60
            EObject requiredInterface = (EObject) r.next();
61
		}
61
            if (requiredInterface instanceof Interface) {
62
62
                ClassifierOperations.allParents((Interface) requiredInterface,
63
		return ECollections.EMPTY_ELIST;
63
                    allRequiredInterfaces);
64
	}
64
            }
65
        }
66
        return ECollections.unmodifiableEList(allRequiredInterfaces);
67
    }
65
68
69
    
66
	protected static EList getProvidedInterfaces(
70
	protected static EList getProvidedInterfaces(
67
			ConnectableElement connectableElement) {
71
			ConnectableElement connectableElement) {
68
72
69
		if (connectableElement instanceof Port) {
73
        EList directlyProvidedInterfaces = new UniqueEList.FastCompare();
70
			Collection provideds = ((Port) connectableElement).getProvideds();
74
        if (connectableElement instanceof Port) {
71
			EList providedInterfaces = new UniqueEList.FastCompare(provideds);
75
            directlyProvidedInterfaces.addAll(((Port) connectableElement)
72
76
                .getProvideds());
73
			for (Iterator p = provideds.iterator(); p.hasNext();) {
77
        } else if (connectableElement instanceof Property) {
74
				ClassifierOperations.allParents((Interface) p.next(),
78
            Type type = ((Property) connectableElement).getType();
75
					providedInterfaces);
79
76
			}
80
            if (type instanceof Component) {
77
81
                directlyProvidedInterfaces.addAll(ComponentOperations
78
			return providedInterfaces;
82
                    .getAllProvideds((Component) type));
79
		} else if (connectableElement instanceof Property) {
83
            } else if (type instanceof Interface) {
80
			Type type = ((Property) connectableElement).getType();
84
                directlyProvidedInterfaces.add(type);
81
85
            } else if (type instanceof BehavioredClassifier) {
82
			if (type instanceof Component) {
86
                directlyProvidedInterfaces.addAll(((BehavioredClassifier) type)
83
				Collection provideds = ((Component) type).getProvideds();
87
                    .getAllImplementedInterfaces());
84
				EList providedInterfaces = new UniqueEList.FastCompare(
88
            }
85
					provideds);
89
        }
86
90
        EList allProvidedInterfaces = new UniqueEList.FastCompare(
87
				for (Iterator p = provideds.iterator(); p.hasNext();) {
91
            directlyProvidedInterfaces);
88
					ClassifierOperations.allParents((Interface) p.next(),
92
89
						providedInterfaces);
93
        for (Iterator r = directlyProvidedInterfaces.iterator(); r.hasNext();) {
90
				}
94
            ClassifierOperations.allParents((Interface) r.next(),
91
95
                allProvidedInterfaces);
92
				return providedInterfaces;
96
        }
93
			} else if (type instanceof Interface) {
97
        return ECollections.unmodifiableEList(allProvidedInterfaces);
94
				EList providedInterfaces = new UniqueEList.FastCompare();
95
				providedInterfaces.add(type);
96
				ClassifierOperations.allParents((Interface) type,
97
					providedInterfaces);
98
				return providedInterfaces;
99
			} else if (type instanceof BehavioredClassifier) {
100
				return ((BehavioredClassifier) type)
101
					.getAllImplementedInterfaces();
102
			}
103
		}
104
98
105
		return ECollections.EMPTY_ELIST;
99
    }
106
	}
107
100
108
} // ConnectableElementOperations
101
} // ConnectableElementOperations

Return to bug 157715