01: package org.andromda.metafacades.emf.uml2;
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
17: * org.andromda.metafacades.uml.ServiceOperation.
18: *
19: * @see org.andromda.metafacades.uml.ServiceOperation
20: */
21: public class ServiceOperationLogicImpl extends ServiceOperationLogic {
22: public ServiceOperationLogicImpl(final Object metaObject,
23: final String context) {
24: super (metaObject, context);
25: }
26:
27: /**
28: * @see org.andromda.metafacades.uml.ServiceOperation#getRoles()
29: */
30: protected java.util.Collection handleGetRoles() {
31: // Taken from UML 1.4 Facade
32: final Collection roles = new LinkedHashSet();
33: if (this .getOwner() instanceof Service) {
34: roles.addAll(((Service) this .getOwner()).getRoles());
35: }
36: final Collection operationRoles = new ArrayList(this
37: .getTargetDependencies());
38: CollectionUtils.filter(operationRoles, new Predicate() {
39: public boolean evaluate(final Object object) {
40: DependencyFacade dependency = (DependencyFacade) object;
41: return dependency != null
42: && dependency.getSourceElement() != null
43: && Role.class.isAssignableFrom(dependency
44: .getSourceElement().getClass());
45: }
46: });
47: CollectionUtils.transform(operationRoles, new Transformer() {
48: public Object transform(final Object object) {
49: return ((DependencyFacade) object).getSourceElement();
50: }
51: });
52: roles.addAll(operationRoles);
53: final Collection allRoles = new LinkedHashSet(roles);
54:
55: // add all roles which are specializations of this one
56: CollectionUtils.forAllDo(roles, new Closure() {
57: public void execute(final Object object) {
58: if (object instanceof Role) {
59: allRoles.addAll(((Role) object)
60: .getAllSpecializations());
61: }
62: }
63: });
64: return allRoles;
65: }
66:
67: /**
68: * @see org.andromda.metafacades.uml.ServiceOperation#getService()
69: */
70: protected java.lang.Object handleGetService() {
71: Service owner = null;
72: if (this .getOwner() instanceof Service) {
73: owner = (Service) this.getOwner();
74: }
75: return owner;
76: }
77: }
|