001package org.andromda.cartridges.bpm4struts.metafacades; 002 003import java.util.ArrayList; 004import java.util.LinkedHashSet; 005import java.util.List; 006import java.util.Set; 007import org.andromda.metafacades.uml.ActivityGraphFacade; 008import org.andromda.metafacades.uml.StateMachineFacade; 009import org.andromda.metafacades.uml.UseCaseFacade; 010import org.andromda.utils.StringUtilsHelper; 011 012/** 013 * MetafacadeLogic implementation. 014 * 015 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsPseudostate 016 */ 017public class StrutsPseudostateLogicImpl 018 extends StrutsPseudostateLogic 019{ 020 private static final long serialVersionUID = 34L; 021 /** 022 * @param metaObject 023 * @param context 024 */ 025 public StrutsPseudostateLogicImpl( 026 Object metaObject, 027 String context) 028 { 029 super(metaObject, context); 030 } 031 032 /** 033 * @return getStateMachine() instanceof StrutsActivityGraph 034 */ 035 protected boolean handleIsContainedInFrontEndUseCase() 036 { 037 return this.getStateMachine() instanceof StrutsActivityGraph; 038 } 039 040 /** 041 * @return actionMethodName 042 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsPseudostate#getActionMethodName() 043 */ 044 protected String handleGetActionMethodName() 045 { 046 final String methodName = getName(); 047 return (methodName == null) ? 048 "a" + System.currentTimeMillis() : StringUtilsHelper.lowerCamelCaseName(methodName); 049 } 050 051 /** 052 * Overridden and not typesafe since StrutsAction does not extend FrontEndAction 053 * 054 * @see org.andromda.metafacades.uml.FrontEndPseudostate#getContainerActions() 055 */ 056 public List getContainerActions() 057 { 058 final Set<StrutsAction> actionSet = new LinkedHashSet<StrutsAction>(); 059 final StateMachineFacade graphContext = getStateMachine(); 060 061 if (graphContext instanceof ActivityGraphFacade) 062 { 063 final UseCaseFacade useCase = ((ActivityGraphFacade)graphContext).getUseCase(); 064 065 if (useCase instanceof StrutsUseCase) 066 { 067 // StrutsUseCase.getActions returns StrutsAction which cannot be cast to FrontEndAction 068 for (final Object action : ((StrutsUseCaseLogicImpl)useCase).getActions()) 069 { 070 for (final StrutsForward transition : ((StrutsAction)action).getTransitions()) 071 { 072 if (this.equals(transition.getTarget())) 073 { 074 actionSet.add((StrutsAction)action); 075 } 076 } 077 } 078 } 079 } 080 // Cannot make return type List<StrutsAction> because StrutsAction does not extend FrontEndAction 081 return new ArrayList<StrutsAction>(actionSet); 082 } 083}