001package org.andromda.metafacades.uml14; 002 003import java.util.ArrayList; 004import java.util.Collection; 005import java.util.Iterator; 006import java.util.LinkedHashMap; 007import java.util.List; 008import java.util.Map; 009import org.andromda.metafacades.uml.ActivityGraphFacade; 010import org.andromda.metafacades.uml.EventFacade; 011import org.andromda.metafacades.uml.FrontEndAction; 012import org.andromda.metafacades.uml.FrontEndParameter; 013import org.andromda.metafacades.uml.FrontEndUseCase; 014import org.andromda.metafacades.uml.ModelElementFacade; 015import org.andromda.metafacades.uml.StateMachineFacade; 016import org.andromda.metafacades.uml.TransitionFacade; 017import org.andromda.metafacades.uml.UMLProfile; 018import 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 * @author Bob Fields 025 */ 026public class FrontEndViewLogicImpl 027 extends FrontEndViewLogic 028{ 029 private static final long serialVersionUID = 3878476296052353951L; 030 031 /** 032 * @param metaObject 033 * @param context 034 */ 035 public FrontEndViewLogicImpl( 036 Object metaObject, 037 String context) 038 { 039 super(metaObject, context); 040 } 041 042 /** 043 * @see org.andromda.metafacades.uml.FrontEndView#isFrontEndView() 044 */ 045 @Override 046 protected boolean handleIsFrontEndView() 047 { 048 return this.hasStereotype(UMLProfile.STEREOTYPE_FRONT_END_VIEW); 049 } 050 051 // TODO StrutsFinalStateLogicImpl uses getIncomings instead of getOutgoings - why? 052 /* Moved to StateVertexFacade 053 * @see org.andromda.metafacades.uml.FrontEndView#getActions() 054 @Override 055 protected List<FrontEndAction> handleGetActions() 056 { 057 final List<FrontEndAction> actions = new ArrayList<FrontEndAction>(); 058 final Collection<TransitionFacade> outgoing = getOutgoings(); 059 for (final Iterator iterator = outgoing.iterator(); iterator.hasNext();) 060 { 061 final Object object = iterator.next(); 062 if (object instanceof FrontEndAction) 063 { 064 actions.add((FrontEndAction)object); 065 } 066 } 067 return actions; 068 } 069 */ 070 071 /** 072 * @see org.andromda.metafacades.uml.FrontEndView#getUseCase() 073 */ 074 @Override 075 protected FrontEndUseCase handleGetUseCase() 076 { 077 UseCaseFacade useCase = null; 078 final StateMachineFacade graphContext = this.getStateMachine(); 079 if (graphContext instanceof ActivityGraphFacade) 080 { 081 useCase = ((ActivityGraphFacade)graphContext).getUseCase(); 082 if (!(useCase instanceof FrontEndUseCase)) 083 { 084 useCase = null; 085 } 086 } 087 return (FrontEndUseCase)useCase; 088 } 089 090 /** 091 * Override to create the package of the view. 092 * 093 * @see org.andromda.metafacades.uml14.ModelElementFacadeLogic#handleGetPackageName() 094 */ 095 @Override 096 public String handleGetPackageName() 097 { 098 String packageName = null; 099 final StateMachineFacade graphContext = this.getStateMachine(); 100 if (graphContext instanceof ActivityGraphFacade) 101 { 102 final UseCaseFacade graphUseCase = ((ActivityGraphFacade)graphContext).getUseCase(); 103 if (graphUseCase instanceof FrontEndUseCase) 104 { 105 final FrontEndUseCase useCase = (FrontEndUseCase)graphUseCase; 106 packageName = useCase.getPackageName(); 107 } 108 } 109 return packageName; 110 } 111 112 /** 113 * @see org.andromda.metafacades.uml.FrontEndView#getVariables() 114 */ 115 @Override 116 protected List<ModelElementFacade> handleGetVariables() 117 { 118 final Map<String, ModelElementFacade> variablesMap = new LinkedHashMap<String, ModelElementFacade>(); 119 final Collection<TransitionFacade> incoming = getIncomings(); 120 for (final Iterator iterator = incoming.iterator(); iterator.hasNext();) 121 { 122 final TransitionFacade transition = (TransitionFacade)iterator.next(); 123 final EventFacade trigger = transition.getTrigger(); 124 if (trigger != null) 125 { 126 for (final Iterator parameterIterator = trigger.getParameters().iterator(); parameterIterator.hasNext();) 127 { 128 final ModelElementFacade modelElement = (ModelElementFacade)parameterIterator.next(); 129 variablesMap.put(modelElement.getName(), modelElement); 130 } 131 } 132 } 133 return new ArrayList<ModelElementFacade>(variablesMap.values()); 134 } 135 136 /** 137 * @see org.andromda.metafacades.uml.FrontEndView#getAllActionParameters() 138 */ 139 @Override 140 protected List<FrontEndParameter> handleGetAllActionParameters() 141 { 142 final List<FrontEndParameter> actionParameters = new ArrayList(); 143 final Collection<FrontEndAction> actions = this.getActions(); 144 for (final Iterator<FrontEndAction> iterator = actions.iterator(); iterator.hasNext();) 145 { 146 final FrontEndAction action = iterator.next(); 147 actionParameters.addAll(action.getParameters()); 148 } 149 return actionParameters; 150 } 151 152 /** 153 * @see org.andromda.metafacades.uml.FrontEndView#getAllFormFields() 154 */ 155 @Override 156 protected List<FrontEndParameter> handleGetAllFormFields() 157 { 158 final List<FrontEndParameter> actionParameters = new ArrayList<FrontEndParameter>(); 159 final Collection<FrontEndAction> actions = getActions(); 160 for (final Iterator<FrontEndAction> iterator = actions.iterator(); iterator.hasNext();) 161 { 162 final FrontEndAction action = iterator.next(); 163 actionParameters.addAll(action.getParameters()); 164 } 165 return actionParameters; 166 } 167 168 /** 169 * @see org.andromda.metafacades.uml.FrontEndView#getTables() 170 */ 171 @Override 172 protected List<FrontEndParameter> handleGetTables() 173 { 174 final List<FrontEndParameter> variables = new ArrayList<FrontEndParameter>(this.getVariables()); 175 for (final Iterator<FrontEndParameter> iterator = variables.iterator(); iterator.hasNext();) 176 { 177 final FrontEndParameter parameter = iterator.next(); 178 if (!parameter.isTable()) 179 { 180 iterator.remove(); 181 } 182 } 183 return variables; 184 } 185 186 /** 187 * @return Outgoings FrontEndActions 188 * @see org.andromda.metafacades.uml.FrontEndView#getActions() 189 */ 190 @Override 191 protected List<FrontEndAction> handleGetActions() 192 { 193 final List<FrontEndAction> actions = new ArrayList<FrontEndAction>(); 194 final Collection<TransitionFacade> outgoings = getOutgoings(); 195 for (final Iterator<TransitionFacade> iterator = outgoings.iterator(); iterator.hasNext();) 196 { 197 final TransitionFacade object = iterator.next(); 198 if (object instanceof FrontEndAction) 199 { 200 actions.add((FrontEndAction)object); 201 } 202 } 203 // TODO StrutsFinalStateLogicImpl uses getIncomings INSTEAD OF getOutgoings - why? 204 /*final Collection<TransitionFacade> incomings = getIncomings(); 205 for (final Iterator<TransitionFacade> iterator = incomings.iterator(); iterator.hasNext();) 206 { 207 final TransitionFacade object = iterator.next(); 208 if (object instanceof FrontEndAction) 209 { 210 actions.add((FrontEndAction)object); 211 } 212 }*/ 213 return actions; 214 } 215}