/**
* @see org.andromda.metafacades.uml.FrontEndAction#getFormFields()
*/
protected List handleGetFormFields()
{
final Map formFieldMap = new LinkedHashMap();
// - For an action that starts the use case, we need to detect all
// usecases forwarding to the one
// belonging to this action if there are any parameters in those
// transitions we need to have
// them included in this action's form
if (this.isUseCaseStart())
{
final FrontEndUseCase useCase = this.getUseCase();
if (useCase != null)
{
final Collection finalStates = useCase.getReferencingFinalStates();
for (final Iterator finalStateIterator = finalStates.iterator(); finalStateIterator.hasNext();)
{
final Object finalStateObject = finalStateIterator.next();
// we need to test for the type because a non
// struts-use-case final state might accidently
// we linking to this use-case (for example: the user
// temporarily wants to disable code generation
// for a specific use-case and is not removing the
// final-state to use-case link(s))
if (finalStateObject instanceof FrontEndFinalState)
{
final FrontEndFinalState finalState = (FrontEndFinalState)finalStateObject;
final Collection parameters = finalState.getInterUseCaseParameters();
for (final Iterator parameterIterator = parameters.iterator(); parameterIterator.hasNext();)
{
final ParameterFacade parameter = (ParameterFacade)parameterIterator.next();
formFieldMap.put(
parameter.getName(),
parameter);
}
}
}
}
}
// if any action encountered by the execution of the complete
// action-graph path emits a forward
// containing one or more parameters they need to be included as a form
// field too
final Collection actionStates = this.getActionStates();
for (final Iterator iterator = actionStates.iterator(); iterator.hasNext();)
{
final FrontEndActionState actionState = (FrontEndActionState)iterator.next();
final FrontEndForward forward = actionState.getForward();
if (forward != null)
{
final Collection forwardParameters = forward.getForwardParameters();
for (final Iterator parameterIterator = forwardParameters.iterator(); parameterIterator.hasNext();)
{
final ModelElementFacade forwardParameter = (ModelElementFacade)parameterIterator.next();
formFieldMap.put(
forwardParameter.getName(),
forwardParameter);
}
}
}
// add page variables for all pages/final-states targetted
// also add the fields of the target page's actions (for preloading)
final Collection forwards = this.getActionForwards();
for (final Iterator iterator = forwards.iterator(); iterator.hasNext();)
{
final FrontEndForward forward = (FrontEndForward)iterator.next();
final StateVertexFacade target = forward.getTarget();
if (target instanceof FrontEndView)
{
final FrontEndView view = (FrontEndView)target;
final Collection viewVariables = view.getVariables();
for (final Iterator pageVariableIterator = viewVariables.iterator(); pageVariableIterator.hasNext();)
{
final ModelElementFacade facade = (ModelElementFacade)pageVariableIterator.next();
formFieldMap.put(
facade.getName(),
facade);
}
final Collection allActionParameters = view.getAllFormFields();
for (final Iterator actionParameterIterator = allActionParameters.iterator();
actionParameterIterator.hasNext();)
{
// - don't allow existing parameters that are tables be
// overwritten (since they take
// precedence
final Object parameter = actionParameterIterator.next();
if (parameter instanceof FrontEndParameter)
{
FrontEndParameter variable = (FrontEndParameter)parameter;
final String name = variable.getName();
final Object existingParameter = formFieldMap.get(name);
if (existingParameter instanceof FrontEndParameter)
{
final FrontEndParameter existingVariable = (FrontEndParameter)existingParameter;
if (existingVariable != null)
{
if (existingVariable.isTable())
{
variable = existingVariable;
}
}
}
formFieldMap.put(
name,
variable);
}
}
}
else if (target instanceof FrontEndFinalState)
{
// only add these if there is no parameter recorded yet with the
// same name
final Collection forwardParameters = forward.getForwardParameters();
for (final Iterator parameterIterator = forwardParameters.iterator(); parameterIterator.hasNext();)
{
final ModelElementFacade facade = (ModelElementFacade)parameterIterator.next();
if (!formFieldMap.containsKey(facade.getName()))
{
formFieldMap.put(
facade.getName(),
facade);
}
}
}
}
// we do the action parameters in the end because they are allowed to
// overwrite existing properties
final Collection actionParameters = this.getParameters();
for (final Iterator parameterIterator = actionParameters.iterator(); parameterIterator.hasNext();)
{
final Object parameter = parameterIterator.next();
if (parameter instanceof FrontEndParameter)
{
final FrontEndParameter variable = (FrontEndParameter)parameter;
formFieldMap.put(
variable.getName(),
variable);
}
}
// - if we don't have any fields defined on this action and there are no
// action forwards,
// take the parameters from the deferred operations (since we would want
// to stay on the same view)
if (formFieldMap.isEmpty() && this.getActionForwards().isEmpty())
{
for (final Iterator iterator = this.getDeferredOperations().iterator(); iterator.hasNext();)
{
final OperationFacade operation = (OperationFacade)iterator.next();
for (final Iterator parameterIterator = operation.getArguments().iterator();
parameterIterator.hasNext();)
{
final ParameterFacade parameter = (ParameterFacade)parameterIterator.next();
formFieldMap.put(
parameter.getName(),
parameter);
}
}
}
return new ArrayList(formFieldMap.values());
}