1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.el.unified.resolver; |
20 | |
|
21 | |
import java.lang.reflect.Constructor; |
22 | |
import java.lang.reflect.InvocationTargetException; |
23 | |
import java.lang.reflect.Method; |
24 | |
|
25 | |
import javax.el.ELContext; |
26 | |
import javax.el.ELException; |
27 | |
import javax.el.PropertyNotFoundException; |
28 | |
|
29 | |
import org.apache.myfaces.shared.util.ClassUtils; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class ImportHandlerResolver extends ScopedAttributeResolver |
35 | |
{ |
36 | |
private static final Class EL_CLASS; |
37 | |
private static final Constructor EL_CLASS_CONSTRUCTOR; |
38 | |
private static final Method GET_IMPORT_HANDLER_METHOD; |
39 | |
private static final Method IMPORT_HANDLER_RESOLVE_CLASS_METHOD; |
40 | |
|
41 | |
static |
42 | |
{ |
43 | 0 | Class elClass = null; |
44 | 0 | Class importHandlerClass = null; |
45 | 0 | Constructor elClassConstructor = null; |
46 | 0 | Method getImportHandlerMethod = null; |
47 | 0 | Method importHandlerResolveClassMethod = null; |
48 | |
try |
49 | |
{ |
50 | |
|
51 | 0 | elClass = ClassUtils.classForName("javax.el.ELClass"); |
52 | 0 | importHandlerClass = ClassUtils.classForName("javax.el.ImportHandler"); |
53 | 0 | getImportHandlerMethod = ELContext.class.getMethod("getImportHandler"); |
54 | 0 | if (elClass != null && importHandlerClass != null) |
55 | |
{ |
56 | 0 | importHandlerResolveClassMethod = |
57 | |
importHandlerClass.getDeclaredMethod("resolveClass", new Class[] {String.class}); |
58 | 0 | elClassConstructor = elClass.getConstructor(Class.class); |
59 | |
} |
60 | |
} |
61 | 0 | catch (SecurityException ex) |
62 | |
{ |
63 | |
|
64 | |
} |
65 | 0 | catch (ClassNotFoundException ex) |
66 | |
{ |
67 | |
|
68 | |
} |
69 | 0 | catch (NoSuchMethodException e) |
70 | |
{ |
71 | |
|
72 | 0 | } |
73 | 0 | EL_CLASS = elClass; |
74 | 0 | GET_IMPORT_HANDLER_METHOD = getImportHandlerMethod; |
75 | 0 | IMPORT_HANDLER_RESOLVE_CLASS_METHOD = importHandlerResolveClassMethod; |
76 | 0 | EL_CLASS_CONSTRUCTOR = elClassConstructor; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public ImportHandlerResolver() |
83 | 0 | { |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
@Override |
90 | |
public Object getValue(final ELContext context, final Object base, final Object property) |
91 | |
throws NullPointerException, PropertyNotFoundException, ELException |
92 | |
{ |
93 | 0 | if (EL_CLASS != null && EL_CLASS_CONSTRUCTOR != null |
94 | |
&& GET_IMPORT_HANDLER_METHOD != null && IMPORT_HANDLER_RESOLVE_CLASS_METHOD != null ) |
95 | |
{ |
96 | 0 | Object importHandler = null; |
97 | |
try |
98 | |
{ |
99 | |
|
100 | 0 | importHandler = GET_IMPORT_HANDLER_METHOD.invoke(context); |
101 | 0 | if (importHandler != null) |
102 | |
{ |
103 | |
Class<?> clazz; |
104 | 0 | clazz = (Class<?>) IMPORT_HANDLER_RESOLVE_CLASS_METHOD |
105 | |
.invoke(importHandler, property.toString()); |
106 | 0 | if (clazz != null) |
107 | |
{ |
108 | 0 | context.setPropertyResolved(true); |
109 | 0 | return EL_CLASS_CONSTRUCTOR.newInstance(clazz); |
110 | |
} |
111 | |
} |
112 | |
} |
113 | 0 | catch (IllegalAccessException ex) |
114 | |
{ |
115 | |
|
116 | |
} |
117 | 0 | catch (IllegalArgumentException ex) |
118 | |
{ |
119 | |
|
120 | |
} |
121 | 0 | catch (InvocationTargetException ex) |
122 | |
{ |
123 | |
|
124 | |
} |
125 | 0 | catch (SecurityException ex) |
126 | |
{ |
127 | |
|
128 | |
} |
129 | 0 | catch (InstantiationException e) |
130 | |
{ |
131 | |
|
132 | 0 | } |
133 | |
} |
134 | 0 | return null; |
135 | |
} |
136 | |
} |