if (doUpload) {
outboundPayload = PayloadImpl.Outbound.newInstance();
}
StringBuilder uriString = getCommandURI();
ParamModel operandParam = null;
for (ParamModel opt : commandModel.getParameters()) {
if (opt.getParam().primary()) {
operandParam = opt;
continue;
}
String paramName = opt.getName();
// XXX - no multi-value support
String paramValue =
options.getOne(paramName.toLowerCase(Locale.ENGLISH));
if (paramValue == null) {
// is it an alias ?
if (opt.isParamId(paramName)) {
paramValue = options.getOne(
opt.getParam().alias().toLowerCase(Locale.ENGLISH));
}
}
if (paramValue == null) // perhaps it's set in the environment?
paramValue = getFromEnvironment(paramName);
if (paramValue == null) {
/*
* Option still not set. Note that we ignore the default
* value and don't send it explicitly on the assumption
* that the server will supply the default value itself.
*
* If the missing option is required, that's an error,
* which should never happen here because validate()
* should check it first.
*/
if (!opt.getParam().optional())
throw new CommandException(strings.get("missingOption",
paramName));
// optional param not set, skip it
continue;
}
if (opt.getType() == File.class) {
addFileOption(uriString, paramName, paramValue);
} else if (opt.getParam().password()) {
addPasswordOption(uriString, paramName, paramValue);
} else {
addStringOption(uriString, paramName, paramValue);
}
}
// add operands
for (String operand : operands) {
if (operandParam.getType() == File.class ||
operandParam.getType() == File[].class) {
addFileOption(uriString, "DEFAULT", operand);
} else {
addStringOption(uriString, "DEFAULT", operand);
}
}