*
* @see org.andromda.metafacades.uml.FrontEndControllerOperation#getFormFields()
*/
public List getFormFields()
{
final Map formFieldsMap = new LinkedHashMap();
// for quick lookup we use a hashset for the argument names, we only consider parameters with a name
// which is also present in this set
final Set argumentNames = new LinkedHashSet();
final Collection arguments = this.getArguments();
for (final Iterator argumentIterator = arguments.iterator(); argumentIterator.hasNext();)
{
final ModelElementFacade element = (ModelElementFacade)argumentIterator.next();
argumentNames.add(element.getName());
}
// get all actions deferring to this operation
final List deferringActions = this.getDeferringActions();
for (int i = 0; i < deferringActions.size(); i++)
{
final StrutsAction action = (StrutsAction)deferringActions.get(i);
// store the action parameters
final List actionFormFields = action.getActionFormFields();
for (int j = 0; j < actionFormFields.size(); j++)
{
final ModelElementFacade parameter = (ModelElementFacade)actionFormFields.get(j);
if (argumentNames.contains(parameter.getName()))
{
formFieldsMap.put(parameter.getName(), parameter);
}
}
// get all forwards and overwrite when we find a table (or add when not yet present)
final List forwards = action.getActionForwards();
for (int j = 0; j < forwards.size(); j++)
{
final StrutsForward forward = (StrutsForward)forwards.get(j);
// only consider forwards directly entering a page
if (forward.isEnteringPage())
{
final List pageVariables = forward.getForwardParameters();
for (int k = 0; k < pageVariables.size(); k++)
{
final StrutsParameter pageVariable = (StrutsParameter)pageVariables.get(k);
if (argumentNames.contains(pageVariable.getName()))
{
if (!formFieldsMap.containsKey(pageVariable.getName()) || pageVariable.isTable())
{
formFieldsMap.put(pageVariable.getName(), pageVariable);
}
}
}
}
}
}
// since all arguments need to be present we add those that haven't yet been stored in the map
for (final Iterator argumentIterator = arguments.iterator(); argumentIterator.hasNext();)
{
final StrutsParameter argument = (StrutsParameter)argumentIterator.next();
if (!formFieldsMap.containsKey(argument.getName()))
{
formFieldsMap.put(argument.getName(), argument);
}
}
return new ArrayList(formFieldsMap.values());
}