01: package org.jicengine.operation;
02:
03: import java.util.Collection;
04:
05: /**
06: * <p>
07: * Copyright (C) 2004 Timo Laitinen
08: * </p>
09: * @author Timo Laitinen
10: * @created 2004-09-20
11: * @since JICE-0.10
12: *
13: */
14:
15: public class MethodInvocationOperation extends InvocationOperation {
16:
17: private String methodName;
18:
19: public MethodInvocationOperation(String signature, Operation actor,
20: String methodName, Operation[] parameters) {
21: super (signature, actor, parameters);
22: this .methodName = methodName;
23: }
24:
25: public Object execute(Object actor, Object[] arguments)
26: throws OperationException {
27: try {
28: if (actor instanceof Class) {
29: // invoke a static method.
30: return ReflectionUtils.invokeStaticMethod(
31: (Class) actor, this .methodName, arguments);
32: } else {
33: // invoke a method of the actor-instance.
34: return ReflectionUtils.invokeMethod(actor,
35: this .methodName, arguments);
36: }
37: } catch (java.lang.reflect.InvocationTargetException e) {
38: // InvocationTargetException means that the invoked method threw an exception
39: // catch it and throw a CDLElementException that has the correct application-exception..
40: throw new OperationException("'" + toString()
41: + "' resulted in exception", e.getTargetException());
42: } catch (Exception e2) {
43: throw new OperationException("'" + toString() + "': "
44: + e2.getMessage(), e2);
45: }
46: }
47:
48: }
|