1 package org.andromda.metafacades.emf.uml22;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.LinkedHashSet;
6 import org.andromda.metafacades.uml.DependencyFacade;
7 import org.andromda.metafacades.uml.Destination;
8 import org.andromda.metafacades.uml.ModelElementFacade;
9 import org.andromda.metafacades.uml.Role;
10 import org.andromda.metafacades.uml.Service;
11 import org.apache.commons.collections.Closure;
12 import org.apache.commons.collections.CollectionUtils;
13 import org.apache.commons.collections.Predicate;
14 import org.apache.commons.collections.Transformer;
15
16
17
18
19
20
21
22
23 public class ServiceOperationLogicImpl
24 extends ServiceOperationLogic
25 {
26 private static final long serialVersionUID = -6674110092557611089L;
27
28
29
30
31
32 public ServiceOperationLogicImpl(
33 final Object metaObject,
34 final String context)
35 {
36 super(metaObject, context);
37 }
38
39
40
41
42 @Override
43 protected Collection<Role> handleGetRoles()
44 {
45
46
47 final Collection roles = new LinkedHashSet();
48 if (this.getOwner() instanceof Service)
49 {
50 roles.addAll(((Service)this.getOwner()).getRoles());
51 }
52 final Collection<DependencyFacade> operationRoles = new ArrayList<DependencyFacade>(this.getTargetDependencies());
53 CollectionUtils.filter(
54 operationRoles,
55 new Predicate()
56 {
57 public boolean evaluate(final Object object)
58 {
59 final DependencyFacade dependency = (DependencyFacade)object;
60 return dependency != null && dependency.getSourceElement() != null &&
61 Role.class.isAssignableFrom(dependency.getSourceElement().getClass());
62 }
63 });
64 CollectionUtils.transform(
65 operationRoles,
66 new Transformer()
67 {
68 public Object transform(final Object object)
69 {
70 return ((DependencyFacade)object).getSourceElement();
71 }
72 });
73 roles.addAll(operationRoles);
74 final Collection allRoles = new LinkedHashSet(roles);
75
76
77 CollectionUtils.forAllDo(
78 roles,
79 new Closure()
80 {
81 public void execute(final Object object)
82 {
83 if (object instanceof Role)
84 {
85 allRoles.addAll(((Role)object).getAllSpecializations());
86 }
87 }
88 });
89 return allRoles;
90 }
91
92
93
94
95 @Override
96 protected Service handleGetService()
97 {
98 Service owner = null;
99 if (this.getOwner() instanceof Service)
100 {
101 owner = (Service)this.getOwner();
102 }
103 return owner;
104 }
105
106
107
108
109 @Override
110 public boolean handleIsMessageOperation()
111 {
112 return this.isIncomingMessageOperation() || this.isOutgoingMessageOperation();
113 }
114
115
116
117
118 @Override
119 public boolean handleIsIncomingMessageOperation()
120 {
121 return this.getIncomingDestination() != null;
122 }
123
124
125
126
127 @Override
128 public boolean handleIsOutgoingMessageOperation()
129 {
130 return this.getOutgoingDestination() != null;
131 }
132
133
134
135
136 @Override
137 public ModelElementFacade handleGetIncomingDestination()
138 {
139 final Collection<DependencyFacade> dependencies = this.getTargetDependencies();
140 final DependencyFacade dependency = (DependencyFacade)
141 CollectionUtils.find(dependencies,
142 new Predicate() {
143 public boolean evaluate(final Object object)
144 {
145 return ((DependencyFacade)object).getSourceElement() instanceof Destination;
146 }});
147 return (dependency == null ? null : dependency.getSourceElement());
148 }
149
150
151
152
153 @Override
154 public Destination handleGetOutgoingDestination()
155 {
156 final Collection<DependencyFacade> dependencies = this.getSourceDependencies();
157 final DependencyFacade dependency = (DependencyFacade)
158 CollectionUtils.find(dependencies,
159 new Predicate() {
160 public boolean evaluate(final Object object)
161 {
162 return ((DependencyFacade)object).getTargetElement() instanceof Destination;
163 }});
164 return (Destination)(dependency == null ? null : dependency.getTargetElement());
165 }
166 }