01: package org.andromda.metafacades.emf.uml2;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Iterator;
06: import java.util.List;
07:
08: import org.andromda.metafacades.uml.FrontEndAction;
09: import org.andromda.metafacades.uml.FrontEndUseCase;
10: import org.andromda.metafacades.uml.TransitionFacade;
11: import org.eclipse.uml2.Activity;
12: import org.eclipse.uml2.CallOperationAction;
13: import org.eclipse.uml2.Element;
14: import org.eclipse.uml2.Transition;
15: import org.eclipse.uml2.UseCase;
16:
17: /**
18: * MetafacadeLogic implementation for
19: * org.andromda.metafacades.uml.FrontEndEvent.
20: *
21: * @see org.andromda.metafacades.uml.FrontEndEvent
22: */
23: public class FrontEndEventLogicImpl extends FrontEndEventLogic {
24: public FrontEndEventLogicImpl(final Object metaObject,
25: final String context) {
26: super (metaObject, context);
27: }
28:
29: /**
30: * @see org.andromda.metafacades.uml.FrontEndEvent#isContainedInFrontEndUseCase()
31: */
32: protected boolean handleIsContainedInFrontEndUseCase() {
33: // Be careful. Should return true only when it has an owning transition
34: // contained in frontend usecase
35: // from UML1.4: return this.getTransition() instanceof FrontEndForward;
36: // Causes stack overflow...
37: Element owner = (Element) this .metaObject;
38: if (!(owner.getOwner() instanceof Transition)) {
39: return false;
40: }
41: while (owner != null) {
42: if (owner instanceof UseCase) {
43: if (this .shieldedElement(owner) instanceof FrontEndUseCase) {
44: return true;
45: }
46: }
47: owner = owner.getOwner();
48: }
49: return false;
50: }
51:
52: /**
53: * @see org.andromda.metafacades.uml.FrontEndEvent#getControllerCall()
54: */
55: protected Object handleGetControllerCall() {
56: final List operations = this .getControllerCalls();
57: return operations.isEmpty() ? null : operations.iterator()
58: .next();
59: }
60:
61: /**
62: * @see org.andromda.metafacades.uml.FrontEndEvent#getControllerCalls()
63: */
64: public List handleGetControllerCalls() {
65: // - get every operation from each CallOperationAction instance.
66: // - Note: this is the same implementation as CallEvent.getOperationCall()
67: final Activity activity = (Activity) this .metaObject;
68: final List operations = new ArrayList();
69: Collection nodes = activity.getNodes();
70: for (final Iterator iterator = nodes.iterator(); iterator
71: .hasNext();) {
72: final Object nextNode = iterator.next();
73: if (nextNode instanceof CallOperationAction) {
74: operations.add(((CallOperationAction) nextNode)
75: .getOperation());
76: }
77: }
78: return operations;
79: }
80:
81: /**
82: * @see org.andromda.metafacades.uml.FrontEndEvent#getAction()
83: */
84: protected Object handleGetAction() {
85: FrontEndAction action = null;
86: TransitionFacade transition = this .getTransition();
87: if (transition instanceof FrontEndAction) {
88: action = (FrontEndAction) transition;
89: }
90: return action;
91: }
92: }
|