001package org.andromda.cartridges.bpm4struts.metafacades; 002 003import java.util.ArrayList; 004import java.util.Collection; 005import java.util.Iterator; 006import java.util.LinkedHashMap; 007import java.util.LinkedHashSet; 008import java.util.List; 009import java.util.Map; 010import org.andromda.metafacades.uml.ActivityGraphFacade; 011import org.andromda.metafacades.uml.StateMachineFacade; 012import org.andromda.metafacades.uml.TransitionFacade; 013import org.andromda.metafacades.uml.UseCaseFacade; 014 015/** 016 * MetafacadeLogic implementation. 017 * 018 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsActionState 019 * @author Bob Fields 020 */ 021public class StrutsActionStateLogicImpl 022 extends StrutsActionStateLogic 023{ 024 private static final long serialVersionUID = 34L; 025 /** 026 * @param metaObject 027 * @param context 028 */ 029 public StrutsActionStateLogicImpl( 030 Object metaObject, 031 String context) 032 { 033 super(metaObject, context); 034 } 035 036 /** 037 * Overridden because StrutsAction does not extend FrontEndAction. 038 * 039 * @see org.andromda.metafacades.uml.FrontEndActionState#getContainerActions() 040 */ 041 public List getContainerActions() 042 { 043 final Collection<StrutsAction> actionSet = new LinkedHashSet<StrutsAction>(); 044 045 final StateMachineFacade stateMachineFacade = this.getStateMachine(); 046 if (stateMachineFacade instanceof ActivityGraphFacade) 047 { 048 final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachineFacade; 049 final UseCaseFacade useCase = activityGraph.getUseCase(); 050 051 if (useCase instanceof StrutsUseCase) 052 { 053 final Collection actions = ((StrutsUseCase)useCase).getActions(); 054 for (final Iterator<StrutsAction> actionIterator = actions.iterator(); actionIterator.hasNext();) 055 { 056 final StrutsAction action = actionIterator.next(); 057 if (action.getActionStates().contains(this)) 058 { 059 actionSet.add(action); 060 } 061 } 062 } 063 } 064 return new ArrayList<StrutsAction>(actionSet); 065 } 066 067 /** 068 * @see org.andromda.metafacades.uml.FrontEndActionState#getExceptions() 069 */ 070 public List getExceptions() 071 { 072 final Map<String, TransitionFacade> exceptionsMap = new LinkedHashMap<String, TransitionFacade>(); 073 for (final TransitionFacade transition : getOutgoings()) 074 { 075 if (transition instanceof StrutsExceptionHandler) 076 { 077 exceptionsMap.put(((StrutsExceptionHandler)transition).getExceptionKey(), transition); 078 } 079 } 080 return new ArrayList<TransitionFacade>(exceptionsMap.values()); 081 } 082}