KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > operation > MethodInvocationOperation


1 package org.jicengine.operation;
2
3 import java.util.Collection JavaDoc;
4
5 /**
6  * <p>
7  * Copyright (C) 2004 Timo Laitinen
8  * </p>
9  * @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 JavaDoc methodName;
18
19     public MethodInvocationOperation(String JavaDoc signature, Operation actor, String JavaDoc methodName, Operation[] parameters)
20     {
21         super(signature, actor, parameters);
22         this.methodName = methodName;
23     }
24
25     public Object JavaDoc execute(Object JavaDoc actor, Object JavaDoc[] arguments) throws OperationException
26     {
27         try {
28             if( actor instanceof Class JavaDoc ){
29                 // invoke a static method.
30
return ReflectionUtils.invokeStaticMethod((Class JavaDoc)actor, this.methodName, arguments);
31             }
32             else {
33                 // invoke a method of the actor-instance.
34
return ReflectionUtils.invokeMethod(actor, this.methodName, arguments);
35             }
36         } catch (java.lang.reflect.InvocationTargetException JavaDoc e){
37             // InvocationTargetException means that the invoked method threw an exception
38
// catch it and throw a CDLElementException that has the correct application-exception..
39
throw new OperationException("'" + toString() + "' resulted in exception", e.getTargetException());
40         } catch (Exception JavaDoc e2){
41             throw new OperationException("'" + toString() + "': " + e2.getMessage(), e2);
42         }
43     }
44
45 }
46
Popular Tags