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.ActivityGraphFacade;
011: import org.andromda.metafacades.uml.EventFacade;
012: import org.andromda.metafacades.uml.FrontEndAction;
013: import org.andromda.metafacades.uml.FrontEndUseCase;
014: import org.andromda.metafacades.uml.ModelElementFacade;
015: import org.andromda.metafacades.uml.StateMachineFacade;
016: import org.andromda.metafacades.uml.TransitionFacade;
017: import org.andromda.metafacades.uml.UMLProfile;
018: import org.andromda.metafacades.uml.UseCaseFacade;
019:
020: /**
021: * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndView.
022: *
023: * @see org.andromda.metafacades.uml.FrontEndView
024: */
025: public class FrontEndViewLogicImpl extends FrontEndViewLogic {
026: public FrontEndViewLogicImpl(final Object metaObject,
027: final String context) {
028: super (metaObject, context);
029: }
030:
031: /**
032: * @see org.andromda.metafacades.uml.FrontEndView#isFrontEndView()
033: */
034: protected boolean handleIsFrontEndView() {
035: return this .hasStereotype(UMLProfile.STEREOTYPE_FRONT_END_VIEW);
036: }
037:
038: /**
039: * @see org.andromda.metafacades.uml.FrontEndView#getActions()
040: */
041: protected List handleGetActions() {
042: final List actions = new ArrayList();
043: final Collection outgoing = this .getOutgoing();
044: for (final Iterator iterator = outgoing.iterator(); iterator
045: .hasNext();) {
046: final Object object = iterator.next();
047: if (object instanceof FrontEndAction) {
048: actions.add(object);
049: }
050: }
051: return actions;
052: }
053:
054: /**
055: * @see org.andromda.metafacades.uml.FrontEndView#getUseCase()
056: */
057: protected Object handleGetUseCase() {
058: UseCaseFacade useCase = null;
059: final StateMachineFacade graphContext = this .getStateMachine();
060: if (graphContext instanceof ActivityGraphFacade) {
061: useCase = ((ActivityGraphFacade) graphContext).getUseCase();
062: if (!(useCase instanceof FrontEndUseCase)) {
063: useCase = null;
064: }
065: }
066: return useCase;
067: }
068:
069: /**
070: * Override to create the package of the view.
071: *
072: * @see org.andromda.metafacades.emf.uml2.ModelElementFacadeLogic#handleGetPackageName()
073: */
074: public String handleGetPackageName() {
075: String packageName = null;
076: final StateMachineFacade graphContext = this .getStateMachine();
077:
078: // TODO: Why not use getUseCase ?
079: if (graphContext instanceof ActivityGraphFacade) {
080: final UseCaseFacade graphUseCase = ((ActivityGraphFacade) graphContext)
081: .getUseCase();
082: if (graphUseCase instanceof FrontEndUseCase) {
083: final FrontEndUseCase useCase = (FrontEndUseCase) graphUseCase;
084: packageName = useCase.getPackageName();
085: }
086: }
087: return packageName;
088: }
089:
090: /**
091: * @see org.andromda.metafacades.uml.FrontEndView#getVariables()
092: */
093: protected List handleGetVariables() {
094: final Map variablesMap = new LinkedHashMap();
095: final Collection incoming = this .getIncoming();
096: for (final Iterator iterator = incoming.iterator(); iterator
097: .hasNext();) {
098: final TransitionFacade transition = (TransitionFacade) iterator
099: .next();
100: final EventFacade trigger = transition.getTrigger();
101: if (trigger != null) {
102: for (final Iterator parameterIterator = trigger
103: .getParameters().iterator(); parameterIterator
104: .hasNext();) {
105: final ModelElementFacade modelElement = (ModelElementFacade) parameterIterator
106: .next();
107: variablesMap.put(modelElement.getName(),
108: modelElement);
109: }
110: }
111: }
112: return new ArrayList(variablesMap.values());
113: }
114:
115: /**
116: * @see org.andromda.metafacades.uml.FrontEndView#getAllActionParameters()
117: */
118: protected List handleGetAllActionParameters() {
119: final List actionParameters = new ArrayList();
120: final Collection actions = this .getActions();
121: for (final Iterator iterator = actions.iterator(); iterator
122: .hasNext();) {
123: final FrontEndAction action = (FrontEndAction) iterator
124: .next();
125: actionParameters.addAll(action.getParameters());
126: }
127: return actionParameters;
128: }
129:
130: /**
131: * @see org.andromda.metafacades.uml.FrontEndView#getAllFormFields()
132: */
133: protected List handleGetAllFormFields() {
134: final List actionParameters = new ArrayList();
135: final Collection actions = this .getActions();
136: for (final Iterator iterator = actions.iterator(); iterator
137: .hasNext();) {
138: final FrontEndAction action = (FrontEndAction) iterator
139: .next();
140: actionParameters.addAll(action.getParameters());
141: }
142: return actionParameters;
143: }
144: }
|