// If descriptor is missing invokable method, find this VM's descriptor
// give name and types from fd
Method method = getInvocationMethod();
if(method == null) {
throw new FunctionExecutionException("ERR.015.001.0002", QueryPlugin.Util.getString("ERR.015.001.0002", getName())); //$NON-NLS-1$ //$NON-NLS-2$
}
if (getDeterministic().compareTo(Determinism.USER_DETERMINISTIC) <= 0 && values.length > 0 && values[0] instanceof CommandContext) {
CommandContext cc = (CommandContext)values[0];
cc.setDeterminismLevel(getDeterministic());
}
// Invoke the method and return the result
try {
if (method.isVarArgs()) {
int i = method.getParameterTypes().length;
Object[] newValues = Arrays.copyOf(values, i);
newValues[i - 1] = Arrays.copyOfRange(values, i - 1, values.length);
values = newValues;
}
Object result = method.invoke(null, values);
return importValue(result, getReturnType());
} catch(ArithmeticException e) {
throw new FunctionExecutionException(e, "ERR.015.001.0003", QueryPlugin.Util.getString("ERR.015.001.0003", getName())); //$NON-NLS-1$ //$NON-NLS-2$
} catch(InvocationTargetException e) {
throw new FunctionExecutionException(e.getTargetException(), "ERR.015.001.0003", QueryPlugin.Util.getString("ERR.015.001.0003", getName())); //$NON-NLS-1$ //$NON-NLS-2$
} catch(IllegalAccessException e) {
throw new FunctionExecutionException(e, "ERR.015.001.0004", QueryPlugin.Util.getString("ERR.015.001.0004", method.toString())); //$NON-NLS-1$ //$NON-NLS-2$
} catch (TransformationException e) {
throw new FunctionExecutionException(e, e.getMessage());
}
}