1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.myfaces.orchestra.viewController;
22
23 import org.apache.myfaces.orchestra.lib.OrchestraException;
24
25 import java.lang.reflect.InvocationTargetException;
26 import java.lang.reflect.Method;
27
28 /***
29 * <p>Invokes ViewController events using reflection.</p>
30 * <p/>
31 * Your beans can optionally provide one of the following methods
32 * <ul>
33 * <li>public void initView()</li>
34 * <li>public void preRenderView()</li>
35 * </ul>
36 * </p>
37 */
38 public class ReflectiveViewControllerExecutor extends AbstractViewControllerExecutor
39 {
40
41
42
43
44 /***
45 * Helper method to find the method which should get invoked.
46 */
47 protected boolean invokeOnViewController(Object bean, String methodName)
48 {
49 try
50 {
51 Method method = bean.getClass().getMethod(methodName, (Class[]) null);
52 method.invoke(bean, (Object[]) null);
53 }
54 catch (NoSuchMethodException e)
55 {
56 return false;
57 }
58 catch (IllegalAccessException e)
59 {
60 throw new OrchestraException(e);
61 }
62 catch (InvocationTargetException e)
63 {
64 throw new OrchestraException(e);
65 }
66
67 return true;
68 }
69
70
71 public boolean invokeInitView(String beanName, Object bean)
72 {
73 return invokeOnViewController(bean, "initView");
74 }
75
76 public boolean invokePreRenderView(String beanName, Object bean)
77 {
78 return invokeOnViewController(bean, "preRenderView");
79 }
80
81 public boolean invokePreProcess(String beanName, Object bean)
82 {
83 return invokeOnViewController(bean, "preProcess");
84 }
85 }