public Value process(URI simpleProcessorUri, Object input, String resultKey, Context context) throws Exception {
Processor processor = getProcessor(simpleProcessorUri);
ParameterDescriptor[] parameterDescriptors = processor.getParameterDescriptors();
if ( parameterDescriptors.length > 1 && countRequiredParameters(parameterDescriptors) > 1 ) {
throw new ProcessException(new ErrorMessage("valueProcessorNeedsTooManyParametersException"));
}
if ( resultKey == null ) {
ResultDescriptor resultDescriptor = processor.getResultDescriptor();
if ( resultDescriptor.getResultEntryDescriptors().length == 0 ) {
throw new ProcessException(new ErrorMessage("parameterProcessingException", new String[] { simpleProcessorUri.toString() }));
} else {
resultKey = resultDescriptor.getResultEntryDescriptors()[0].getName();
}
}
if ( input == null && parameterDescriptors.length == 1 && parameterDescriptors[0].isRequired()) {
throw new ProcessException(new ErrorMessage("requiredParameterMissing", new String[]{parameterDescriptors[0].getName()}));
} else if ( input == null && parameterDescriptors.length > 1 ) {
ParameterDescriptor requiredParameter = getRequiredParameter(parameterDescriptors);
if ( requiredParameter != null ) throw new ProcessException(new ErrorMessage("requiredParameterMissing", new String[]{ requiredParameter.getName()}));
} else {
try {
// check for SimpleProcessor to avoid HashMap creation
if ( processor instanceof EnvironmentConsumer ) {
Process.checkRequirements((EnvironmentConsumer)processor, context);
}
if ( processor instanceof SimpleProcessor ) {
Value preparedValue = prepareValue(parameterDescriptors[0], input, context);
input = ((SimpleProcessor)processor).process(preparedValue, context);
} else {
Map parameters = new HashMap();
if ( parameterDescriptors.length == 1 ) {
parameters.put(parameterDescriptors[0].getName(), prepareValue(parameterDescriptors[0], input, context));
} else {
for ( int i = 0; i < parameterDescriptors.length; i++ ) {
if ( parameterDescriptors[i].isRequired() ) {
parameters.put(parameterDescriptors[i].getName(), prepareValue(parameterDescriptors[i], input, context));
} else {
parameters.put(parameterDescriptors[i].getName(), parameterDescriptors[i].getDefaultValue());
}
}
}
Result processorResult = processor.process(parameters, context);
input = processorResult.getResultEntries().get(resultKey);
}
} catch ( Exception exception ) {
throw new ProcessException(new ErrorMessage("parameterProcessingException", new String[] { simpleProcessorUri.toString(), exception.getMessage() }), exception);
}
}
return (Value)input;
}