01: package org.andromda.metafacades.uml14;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.LinkedHashSet;
06:
07: import org.andromda.metafacades.uml.DependencyFacade;
08: import org.andromda.metafacades.uml.Role;
09: import org.andromda.metafacades.uml.Service;
10: import org.apache.commons.collections.Closure;
11: import org.apache.commons.collections.CollectionUtils;
12: import org.apache.commons.collections.Predicate;
13: import org.apache.commons.collections.Transformer;
14:
15: /**
16: * MetafacadeLogic implementation for org.andromda.metafacades.uml.ServiceOperation.
17: *
18: * @see org.andromda.metafacades.uml.ServiceOperation
19: */
20: public class ServiceOperationLogicImpl extends ServiceOperationLogic {
21: // ---------------- constructor -------------------------------
22: public ServiceOperationLogicImpl(Object metaObject, String context) {
23: super (metaObject, context);
24: }
25:
26: /**
27: * @see org.andromda.metafacades.uml.ServiceOperation#getRoles()
28: */
29: public java.util.Collection handleGetRoles() {
30: final Collection roles = new LinkedHashSet();
31: if (this .getOwner() instanceof Service) {
32: roles.addAll(((Service) this .getOwner()).getRoles());
33: }
34: final Collection operationRoles = new ArrayList(this
35: .getTargetDependencies());
36: CollectionUtils.filter(operationRoles, new Predicate() {
37: public boolean evaluate(Object object) {
38: DependencyFacade dependency = (DependencyFacade) object;
39: return dependency != null
40: && dependency.getSourceElement() != null
41: && Role.class.isAssignableFrom(dependency
42: .getSourceElement().getClass());
43: }
44: });
45: CollectionUtils.transform(operationRoles, new Transformer() {
46: public Object transform(Object object) {
47: return ((DependencyFacade) object).getSourceElement();
48: }
49: });
50: roles.addAll(operationRoles);
51: final Collection allRoles = new LinkedHashSet(roles);
52:
53: // add all roles which are specializations of this one
54: CollectionUtils.forAllDo(roles, new Closure() {
55: public void execute(Object object) {
56: if (object instanceof Role) {
57: allRoles.addAll(((Role) object)
58: .getAllSpecializations());
59: }
60: }
61: });
62: return allRoles;
63: }
64:
65: /**
66: * @see org.andromda.metafacades.uml.ServiceOperation#getService()
67: */
68: protected Object handleGetService() {
69: Service owner = null;
70: if (this .getOwner() instanceof Service) {
71: owner = (Service) this.getOwner();
72: }
73: return owner;
74: }
75: }
|