final IConfigurationElement configurationElement,
final List warningsToLog, final Command command) {
final IConfigurationElement[] parameterElements = configurationElement
.getChildren(TAG_PARAMETER);
if ((parameterElements == null) || (parameterElements.length == 0)) {
return new ParameterizedCommand(command, null);
}
final Collection parameters = new ArrayList();
for (int i = 0; i < parameterElements.length; i++) {
final IConfigurationElement parameterElement = parameterElements[i];
// Read out the id.
final String id = parameterElement.getAttribute(ATT_ID);
if ((id == null) || (id.length() == 0)) {
// The name should never be null. This is invalid.
addWarning(warningsToLog, "Parameters need a name", //$NON-NLS-1$
configurationElement);
continue;
}
// Find the parameter on the command.
IParameter parameter = null;
try {
final IParameter[] commandParameters = command.getParameters();
if (parameters != null) {
for (int j = 0; j < commandParameters.length; j++) {
final IParameter currentParameter = commandParameters[j];
if (Util.equals(currentParameter.getId(), id)) {
parameter = currentParameter;
break;
}
}
}
} catch (final NotDefinedException e) {
// This should not happen.
}
if (parameter == null) {
// The name should never be null. This is invalid.
addWarning(warningsToLog,
"Could not find a matching parameter", //$NON-NLS-1$
configurationElement, id);
continue;
}
// Read out the value.
final String value = parameterElement.getAttribute(ATT_VALUE);
if ((value == null) || (value.length() == 0)) {
// The name should never be null. This is invalid.
addWarning(warningsToLog, "Parameters need a value", //$NON-NLS-1$
configurationElement, id);
continue;
}
parameters.add(new Parameterization(parameter, value));
}
if (parameters.isEmpty()) {
return new ParameterizedCommand(command, null);
}
return new ParameterizedCommand(command,
(Parameterization[]) parameters
.toArray(new Parameterization[parameters.size()]));
}