protected String process(Job job) throws ExecuteException {
List<String> arguments = new ArrayList<String>(job.getArguments());
// Check this operation is allowed
if (!allowedCommands.isEmpty() && !allowedCommands.contains(arguments.get(0)))
throw new ExecuteException("Command '" + arguments.get(0) + "' is not allowed");
String outFileName = null;
String strAux = null;
MediaPackage mp = null;
Type expectedType = null;
MediaPackageElement element = null;
Operation op = null;
try {
op = Operation.valueOf(job.getOperation());
switch (arguments.size()) {
case 5:
strAux = arguments.remove(4);
expectedType = (strAux == null) ? null : Type.valueOf(strAux);
outFileName = StringUtils.trimToNull(arguments.remove(3));
if (((outFileName != null) && (expectedType == null)) || ((outFileName == null) && (expectedType != null)))
throw new ExecuteException("The output type and filename must be both specified");
outFileName = (outFileName == null) ? null : job.getId() + "_" + outFileName;
case 3:
switch (op) {
case Execute_Mediapackage:
mp = MediaPackageParser.getFromXml(arguments.remove(2));
return doProcess(arguments, mp, outFileName, expectedType);
case Execute_Element:
element = MediaPackageElementParser.getFromXml(arguments.remove(2));
return doProcess(arguments, element, outFileName, expectedType);
default:
throw new IllegalStateException("Don't know how to handle operation '" + job.getOperation() + "'");
}
default:
throw new IndexOutOfBoundsException("Incorrect number of parameters for operation execute_" + op + ": "
+ arguments.size());
}
} catch (MediaPackageException e) {
throw new ExecuteException("Error unmarshalling the input mediapackage/element", e);
} catch (IllegalArgumentException e) {
throw new ExecuteException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ExecuteException("The argument list for operation '" + op + "' does not meet expectations", e);
}
}