001: package org.andromda.cartridges.bpm4struts.metafacades;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006: import java.util.LinkedHashSet;
007: import java.util.List;
008: import java.util.Set;
009:
010: import org.andromda.metafacades.uml.FrontEndUseCase;
011: import org.andromda.metafacades.uml.UMLProfile;
012: import org.andromda.metafacades.uml.UseCaseFacade;
013: import org.apache.commons.lang.StringUtils;
014:
015: /**
016: * MetafacadeLogic implementation.
017: *
018: * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalState
019: */
020: public class StrutsFinalStateLogicImpl extends StrutsFinalStateLogic {
021: public StrutsFinalStateLogicImpl(java.lang.Object metaObject,
022: java.lang.String context) {
023: super (metaObject, context);
024: }
025:
026: /**
027: * @see org.andromda.metafacades.uml.ModelElementFacad#getValue()
028: */
029: public String getName() {
030: String name = super .getName();
031:
032: if (name == null) {
033: final UseCaseFacade useCase = this .getTargetUseCase();
034: if (useCase != null) {
035: name = useCase.getName();
036: }
037: }
038:
039: return name;
040: }
041:
042: protected String handleGetFullPath() {
043: String fullPath = null;
044:
045: final StrutsUseCase useCase = (StrutsUseCase) this
046: .getTargetUseCase();
047: if (useCase == null) {
048: // perhaps this final state links outside of the UML model
049: final Object taggedValue = this
050: .findTaggedValue(UMLProfile.TAGGEDVALUE_EXTERNAL_HYPERLINK);
051: if (taggedValue == null) {
052: String name = getName();
053: if (name != null
054: && (name.startsWith("/") || name
055: .startsWith("http://"))) {
056: fullPath = name;
057: }
058: } else {
059: fullPath = String.valueOf(taggedValue);
060: }
061: } else {
062: fullPath = useCase.getActionPath() + ".do";
063: }
064: return fullPath;
065: }
066:
067: /**
068: * Overridden for now (@todo need to figure out why it doesn't work correctly when using
069: * the one from the FrontEndFinalState).
070: *
071: * @see org.andromda.metafacades.uml.FrontEndFinalState#getTargetUseCase()
072: */
073: public FrontEndUseCase getTargetUseCase() {
074: FrontEndUseCase targetUseCase = null;
075: // first check if there is a hyperlink from this final state to a use-case
076: // this works at least in MagicDraw
077: final Object taggedValue = this
078: .findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
079: if (taggedValue != null) {
080: if (taggedValue instanceof StrutsActivityGraph) {
081: targetUseCase = (FrontEndUseCase) ((StrutsActivityGraph) taggedValue)
082: .getUseCase();
083: } else if (taggedValue instanceof StrutsUseCase) {
084: targetUseCase = (FrontEndUseCase) taggedValue;
085: }
086: }
087:
088: // maybe the name points to a use-case ?
089: if (targetUseCase == null) {
090: final String name = super .getName();
091: if (StringUtils.isNotBlank(name)) {
092: UseCaseFacade useCase = getModel().findUseCaseByName(
093: name);
094: if (useCase instanceof FrontEndUseCase) {
095: targetUseCase = (FrontEndUseCase) useCase;
096: }
097: }
098: }
099: return targetUseCase;
100: }
101:
102: protected List handleGetActions() {
103: Set actions = new LinkedHashSet();
104: Collection incoming = this .getIncoming();
105:
106: for (final Iterator incomingIterator = incoming.iterator(); incomingIterator
107: .hasNext();) {
108: StrutsForward forward = (StrutsForward) incomingIterator
109: .next();
110: actions.addAll(forward.getActions());
111: }
112: return new ArrayList(actions);
113: }
114: }
|