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