001: package org.andromda.metafacades.emf.uml2;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005: import java.util.LinkedHashSet;
006:
007: import org.andromda.metafacades.uml.DependencyFacade;
008: import org.andromda.metafacades.uml.GeneralizableElementFacade;
009: import org.andromda.metafacades.uml.NameMasker;
010: import org.andromda.metafacades.uml.Service;
011: import org.andromda.metafacades.uml.ServiceOperation;
012: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
013: import org.andromda.metafacades.uml.UMLProfile;
014: import org.apache.commons.collections.CollectionUtils;
015: import org.apache.commons.collections.Predicate;
016: import org.apache.commons.lang.StringUtils;
017: import org.eclipse.uml2.Classifier;
018: import org.eclipse.uml2.UseCase;
019:
020: /**
021: * MetafacadeLogic implementation for org.andromda.metafacades.uml.Role.
022: *
023: * @see org.andromda.metafacades.uml.Role
024: */
025: public class RoleLogicImpl extends RoleLogic {
026: public RoleLogicImpl(final Object metaObject, final String context) {
027: super (metaObject, context);
028: }
029:
030: /**
031: * @see org.andromda.metafacades.emf.uml2.ModelElementFacadeLogic#handleGetName()
032: */
033: public String handleGetName() {
034: String name;
035: Object value = this
036: .findTaggedValue(UMLProfile.TAGGEDVALUE_ROLE_NAME);
037: if (value != null) {
038: name = StringUtils.trimToEmpty(String.valueOf(value));
039: } else {
040: name = super .handleGetName();
041: String mask = StringUtils
042: .trimToEmpty(String
043: .valueOf(this
044: .getConfiguredProperty(UMLMetafacadeProperties.ROLE_NAME_MASK)));
045: name = NameMasker.mask(name, mask);
046: }
047: return name;
048: }
049:
050: /**
051: * @see org.andromda.metafacades.uml.Role#isReferencesPresent()
052: */
053: protected boolean handleIsReferencesPresent() {
054: final Collection allSourceDependencies = new LinkedHashSet(this
055: .getSourceDependencies());
056: for (GeneralizableElementFacade parent = this
057: .getGeneralization(); parent != null; parent = parent
058: .getGeneralization()) {
059: allSourceDependencies
060: .addAll(parent.getSourceDependencies());
061: }
062: boolean present = CollectionUtils.find(allSourceDependencies,
063: new Predicate() {
064: public boolean evaluate(Object object) {
065: DependencyFacade dependency = (DependencyFacade) object;
066: Object target = dependency.getTargetElement();
067: return target instanceof Service
068: || target instanceof ServiceOperation;
069: }
070: }) != null;
071:
072: // - if no references on any services, try the FrontEndUseCases
073: // used like in uml1.4, throws a stack overflow error
074: if (!present) {
075: final Collection associationEnds = UmlUtilities
076: .getAssociationEnds((Classifier) this .metaObject,
077: false);
078: for (final Iterator iterator = associationEnds.iterator(); iterator
079: .hasNext()
080: && !present;) {
081: final AssociationEnd associationEnd = (AssociationEnd) iterator
082: .next();
083: final Object otherEnd = UmlUtilities
084: .getOppositeAssociationEnd(associationEnd)
085: .getType();
086: if (otherEnd instanceof UseCase) {
087: UseCase uc = (UseCase) otherEnd;
088: if (UmlUtilities.containsStereotype(uc,
089: UMLProfile.STEREOTYPE_FRONT_END_USECASE)
090: || UmlUtilities
091: .containsStereotype(
092: uc,
093: UMLProfile.STEREOTYPE_FRONT_END_APPLICATION)) {
094: present = true;
095: }
096: }
097: }
098:
099: // - a generalized role is still a role, and therefore is associated
100: // with the FrontEndUseCase
101: // TODO: The generalized actors have to be Role too, isn't it ?
102: if (!present) {
103: present = !this.getGeneralizedActors().isEmpty();
104: }
105: }
106:
107: return present;
108: }
109: }
|