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