1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.util; |
17 | |
|
18 | |
import javax.faces.context.FacesContext; |
19 | |
import javax.faces.el.EvaluationException; |
20 | |
import javax.faces.el.MethodBinding; |
21 | |
import javax.faces.event.AbortProcessingException; |
22 | |
|
23 | |
import org.seasar.framework.util.AssertionUtil; |
24 | |
|
25 | |
public class MethodBindingUtil { |
26 | |
|
27 | 0 | private MethodBindingUtil() { |
28 | 0 | } |
29 | |
|
30 | |
public static String getComponentName(final String fromAction) { |
31 | 0 | if (fromAction == null) { |
32 | 0 | return null; |
33 | |
} |
34 | 0 | if (!BindingUtil.isValueReference(fromAction)) { |
35 | 0 | return null; |
36 | |
} |
37 | 0 | int index = fromAction.indexOf('.'); |
38 | 0 | if (index > 0) { |
39 | 0 | return fromAction.substring(2, index); |
40 | |
} |
41 | 0 | return null; |
42 | |
} |
43 | |
|
44 | |
public static String getMethodName(final String fromAction) { |
45 | 0 | if (fromAction == null) { |
46 | 0 | return null; |
47 | |
} |
48 | 0 | if (!BindingUtil.isValueReference(fromAction)) { |
49 | 0 | return null; |
50 | |
} |
51 | 0 | int index = fromAction.lastIndexOf('.'); |
52 | 0 | if (index > 0) { |
53 | 0 | return fromAction.substring(index + 1, fromAction.length() - 1); |
54 | |
} |
55 | 0 | return null; |
56 | |
} |
57 | |
|
58 | |
public static String getFromAction(String componentName, String methodName) { |
59 | 1 | AssertionUtil.assertNotNull("componentName", componentName); |
60 | 1 | AssertionUtil.assertNotNull("methodName", methodName); |
61 | 1 | return "#{" + componentName + "." + methodName + "}"; |
62 | |
} |
63 | |
|
64 | |
public static String invoke(MethodBinding methodBinding, |
65 | |
FacesContext context) { |
66 | |
try { |
67 | 0 | return (String) methodBinding.invoke(context, null); |
68 | 0 | } catch (EvaluationException e) { |
69 | 0 | Throwable cause = e.getCause(); |
70 | 0 | if (cause != null && cause instanceof AbortProcessingException) { |
71 | 0 | throw (AbortProcessingException) cause; |
72 | |
} |
73 | 0 | throw e; |
74 | |
} |
75 | |
} |
76 | |
} |