001: package org.andromda.metafacades.uml14;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.LinkedHashMap;
006: import java.util.Iterator;
007: import java.util.List;
008: import java.util.Map;
009:
010: import org.andromda.metafacades.uml.FrontEndActivityGraph;
011: import org.andromda.metafacades.uml.FrontEndForward;
012: import org.andromda.metafacades.uml.FrontEndUseCase;
013: import org.andromda.metafacades.uml.ModelElementFacade;
014: import org.andromda.metafacades.uml.UMLProfile;
015: import org.andromda.metafacades.uml.UseCaseFacade;
016: import org.apache.commons.lang.StringUtils;
017:
018: /**
019: * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndFinalState.
020: *
021: * @see org.andromda.metafacades.uml.FrontEndFinalState
022: */
023: public class FrontEndFinalStateLogicImpl extends
024: FrontEndFinalStateLogic {
025:
026: public FrontEndFinalStateLogicImpl(Object metaObject, String context) {
027: super (metaObject, context);
028: }
029:
030: /**
031: * @see org.andromda.metafacades.uml.FrontEndFinalState#isContainedInFrontEndUseCase()
032: */
033: protected boolean handleIsContainedInFrontEndUseCase() {
034: return this .getStateMachine() instanceof FrontEndActivityGraph;
035: }
036:
037: public String handleGetName() {
038: String name = super .handleGetName();
039: if (name == null) {
040: FrontEndUseCase useCase = this .getTargetUseCase();
041: if (useCase != null) {
042: name = useCase.getName();
043: }
044: }
045: return name;
046: }
047:
048: /**
049: * @see org.andromda.metafacades.uml.FrontEndFinalState#getTargetUseCase()
050: */
051: protected Object handleGetTargetUseCase() {
052: Object targetUseCase = null;
053:
054: // first check if there is a hyperlink from this final state to a use-case
055: // this works at least in MagicDraw
056: final Object taggedValue = this
057: .findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
058: if (taggedValue != null) {
059: if (taggedValue instanceof FrontEndActivityGraph) {
060: targetUseCase = ((FrontEndActivityGraph) taggedValue)
061: .getUseCase();
062: } else if (taggedValue instanceof FrontEndUseCase) {
063: targetUseCase = taggedValue;
064: }
065: }
066:
067: // maybe the name points to a use-case ?
068: if (targetUseCase == null) {
069: final String name = super .handleGetName();
070: if (StringUtils.isNotBlank(name)) {
071: final UseCaseFacade useCase = getModel()
072: .findUseCaseByName(name);
073: if (useCase instanceof FrontEndUseCase) {
074: targetUseCase = useCase;
075: }
076: }
077: }
078: return targetUseCase;
079: }
080:
081: /**
082: * @see org.andromda.metafacades.uml.FrontEndFinalState#getInterUseCaseParameters()
083: */
084: protected List handleGetInterUseCaseParameters() {
085: // we don't want to list parameters with the same name to we use a hash map
086: final Map parameterMap = new LinkedHashMap();
087:
088: final Collection transitions = getIncoming();
089: for (final Iterator transitionIterator = transitions.iterator(); transitionIterator
090: .hasNext();) {
091: final FrontEndForward forward = (FrontEndForward) transitionIterator
092: .next();
093: final List forwardParameters = forward
094: .getForwardParameters();
095: for (int i = 0; i < forwardParameters.size(); i++) {
096: final ModelElementFacade parameter = (ModelElementFacade) forwardParameters
097: .get(i);
098: parameterMap.put(parameter.getName(), parameter);
099: }
100: }
101:
102: return new ArrayList(parameterMap.values());
103: }
104: }
|