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.LinkedHashSet;
007: import java.util.List;
008: import java.util.Set;
009:
010: import org.andromda.metafacades.uml.ActivityGraphFacade;
011: import org.andromda.metafacades.uml.CallEventFacade;
012: import org.andromda.metafacades.uml.EventFacade;
013: import org.andromda.metafacades.uml.FrontEndAction;
014: import org.andromda.metafacades.uml.FrontEndActivityGraph;
015: import org.andromda.metafacades.uml.FrontEndEvent;
016: import org.andromda.metafacades.uml.FrontEndExceptionHandler;
017: import org.andromda.metafacades.uml.FrontEndUseCase;
018: import org.andromda.metafacades.uml.FrontEndView;
019: import org.andromda.metafacades.uml.StateMachineFacade;
020: import org.andromda.metafacades.uml.TransitionFacade;
021: import org.andromda.metafacades.uml.UseCaseFacade;
022: import org.andromda.utils.StringUtilsHelper;
023:
024: /**
025: * MetafacadeLogic implementation for
026: * org.andromda.metafacades.uml.FrontEndActionState.
027: *
028: * @see org.andromda.metafacades.uml.FrontEndActionState
029: */
030: public class FrontEndActionStateLogicImpl extends
031: FrontEndActionStateLogic {
032:
033: public FrontEndActionStateLogicImpl(final Object metaObject,
034: final String context) {
035: super (metaObject, context);
036: }
037:
038: /**
039: * @see org.andromda.metafacades.uml.FrontEndActionState#isServerSide()
040: */
041: protected boolean handleIsServerSide() {
042: return !(this .THIS() instanceof FrontEndView);
043: }
044:
045: /**
046: * @see org.andromda.metafacades.uml.FrontEndActionState#getActionMethodName()
047: */
048: protected java.lang.String handleGetActionMethodName() {
049: return '_' + StringUtilsHelper.lowerCamelCaseName(this
050: .getName());
051: }
052:
053: /**
054: * @see org.andromda.metafacades.uml.FrontEndActionState#isContainedInFrontEndUseCase()
055: */
056: protected boolean handleIsContainedInFrontEndUseCase() {
057: return this .getStateMachine() instanceof FrontEndActivityGraph;
058: }
059:
060: /**
061: * @see org.andromda.metafacades.uml.FrontEndActionState#getForward()
062: */
063: protected Object handleGetForward() {
064: Object forward = null;
065:
066: for (final Iterator iterator = this .getOutgoing().iterator(); iterator
067: .hasNext()
068: && forward == null;) {
069: final TransitionFacade transition = (TransitionFacade) iterator
070: .next();
071: if (!(transition instanceof FrontEndExceptionHandler)) {
072: forward = transition;
073: }
074: }
075: return forward;
076: }
077:
078: /**
079: * @see org.andromda.metafacades.uml.FrontEndActionState#getControllerCalls()
080: */
081: protected List handleGetControllerCalls() {
082: final List controllerCallsList = new ArrayList();
083: final Collection deferrableEvents = this .getDeferrableEvents();
084: for (final Iterator iterator = deferrableEvents.iterator(); iterator
085: .hasNext();) {
086: final EventFacade event = (EventFacade) iterator.next();
087: if (event instanceof CallEventFacade) {
088: controllerCallsList.addAll(((CallEventFacade) event)
089: .getOperations());
090: } else if (event instanceof FrontEndEvent) {
091: controllerCallsList.addAll(((FrontEndEvent) event)
092: .getControllerCalls());
093: }
094: }
095: return controllerCallsList;
096: }
097:
098: /**
099: * @see org.andromda.metafacades.uml.FrontEndActionState#getExceptions()
100: */
101: protected List handleGetExceptions() {
102: final Set exceptions = new LinkedHashSet();
103: final Collection outgoing = this .getOutgoing();
104: for (final Iterator iterator = outgoing.iterator(); iterator
105: .hasNext();) {
106: final TransitionFacade transition = (TransitionFacade) iterator
107: .next();
108: if (transition instanceof FrontEndExceptionHandler) {
109: exceptions.add(transition);
110: }
111: }
112: return new ArrayList(exceptions);
113: }
114:
115: /**
116: * @see org.andromda.metafacades.uml.FrontEndActionState#getContainerActions()
117: */
118: protected List handleGetContainerActions() {
119: final Collection actionSet = new LinkedHashSet();
120:
121: final StateMachineFacade stateMachineFacade = this
122: .getStateMachine();
123: if (stateMachineFacade instanceof ActivityGraphFacade) {
124: final ActivityGraphFacade activityGraph = (ActivityGraphFacade) stateMachineFacade;
125: final UseCaseFacade useCase = activityGraph.getUseCase();
126:
127: if (useCase instanceof FrontEndUseCase) {
128: final Collection actions = ((FrontEndUseCase) useCase)
129: .getActions();
130: for (final Iterator actionIterator = actions.iterator(); actionIterator
131: .hasNext();) {
132: final FrontEndAction action = (FrontEndAction) actionIterator
133: .next();
134: if (action.getActionStates().contains(this )) {
135: actionSet.add(action);
136: }
137: }
138: }
139: }
140: return new ArrayList(actionSet);
141: }
142:
143: }
|