01: package org.andromda.metafacades.uml14;
02:
03: import java.util.Collection;
04: import java.util.Iterator;
05: import java.util.LinkedHashSet;
06:
07: import org.andromda.metafacades.uml.AssociationEndFacade;
08: import org.andromda.metafacades.uml.ClassifierFacade;
09: import org.andromda.metafacades.uml.DependencyFacade;
10: import org.andromda.metafacades.uml.FrontEndUseCase;
11: import org.andromda.metafacades.uml.GeneralizableElementFacade;
12: import org.andromda.metafacades.uml.NameMasker;
13: import org.andromda.metafacades.uml.Service;
14: import org.andromda.metafacades.uml.ServiceOperation;
15: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
16: import org.andromda.metafacades.uml.UMLProfile;
17: import org.apache.commons.collections.CollectionUtils;
18: import org.apache.commons.collections.Predicate;
19: import org.apache.commons.lang.StringUtils;
20:
21: /**
22: * MetafacadeLogic implementation for org.andromda.metafacades.uml.Role.
23: *
24: * @see org.andromda.metafacades.uml.Role
25: */
26: public class RoleLogicImpl extends RoleLogic {
27: // ---------------- constructor -------------------------------
28: public RoleLogicImpl(Object metaObject, String context) {
29: super (metaObject, context);
30: }
31:
32: /**
33: * @see org.andromda.metafacades.uml14.ModelElementFacadeLogic#handleGetName()
34: */
35: public String handleGetName() {
36: String name;
37: Object value = this
38: .findTaggedValue(UMLProfile.TAGGEDVALUE_ROLE_NAME);
39: if (value != null) {
40: name = StringUtils.trimToEmpty(String.valueOf(value));
41: } else {
42: name = super .handleGetName();
43: String mask = StringUtils
44: .trimToEmpty(String
45: .valueOf(this
46: .getConfiguredProperty(UMLMetafacadeProperties.ROLE_NAME_MASK)));
47: name = NameMasker.mask(name, mask);
48: }
49: return name;
50: }
51:
52: /**
53: * @see org.andromda.metafacades.uml.Role#isReferencesPresent()
54: */
55: protected boolean handleIsReferencesPresent() {
56: final Collection allSourceDependencies = new LinkedHashSet(this
57: .getSourceDependencies());
58: for (GeneralizableElementFacade parent = this
59: .getGeneralization(); parent != null; parent = parent
60: .getGeneralization()) {
61: allSourceDependencies
62: .addAll(parent.getSourceDependencies());
63: }
64: boolean present = CollectionUtils.find(allSourceDependencies,
65: new Predicate() {
66: public boolean evaluate(Object object) {
67: DependencyFacade dependency = (DependencyFacade) object;
68: Object target = dependency.getTargetElement();
69: return target instanceof Service
70: || target instanceof ServiceOperation;
71: }
72: }) != null;
73:
74: // - if no references on any services, try the FrontEndUseCases
75: if (!present) {
76: final Collection associationEnds = this
77: .getAssociationEnds();
78: for (final Iterator iterator = associationEnds.iterator(); iterator
79: .hasNext()
80: && !present;) {
81: final AssociationEndFacade associationEnd = (AssociationEndFacade) iterator
82: .next();
83: final ClassifierFacade classifier = associationEnd
84: .getOtherEnd().getType();
85: present = classifier instanceof FrontEndUseCase;
86: }
87:
88: // - a generalized role is still a role, and therefore is associated with the FrontEndUseCase
89: if (!present) {
90: present = !this.getGeneralizedActors().isEmpty();
91: }
92: }
93:
94: return present;
95: }
96: }
|