1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidadbuild.test;
20
21 import java.beans.FeatureDescriptor;
22
23 import java.util.Iterator;
24 import java.util.List;
25
26 import javax.el.ELResolver;
27 import javax.el.ELContext;
28
29 import javax.faces.context.FacesContext;
30 import javax.faces.el.VariableResolver;
31 import javax.faces.el.PropertyResolver;
32
33
34
35
36 public class MockELResolver extends ELResolver
37 {
38 public MockELResolver(VariableResolver vr, PropertyResolver pr)
39 {
40 _vr = vr;
41 _pr = pr;
42 }
43
44 public Class<?> getCommonPropertyType(ELContext context, Object base)
45 {
46 if (base == null)
47 return Object.class;
48
49 if (base instanceof List || base.getClass().isArray())
50 return Integer.class;
51
52 return String.class;
53 }
54
55 public Iterator<FeatureDescriptor> getFeatureDescriptors(
56 ELContext context, Object base)
57 {
58
59 throw new UnsupportedOperationException();
60 }
61
62 public Class<?> getType(ELContext context, Object base, Object property)
63 {
64 FacesContext fc = FacesContext.getCurrentInstance();
65 if (base == null)
66 {
67 if (property != null)
68 {
69 Object o = _vr.resolveVariable(fc, property.toString());
70 if (o != null)
71 {
72 context.setPropertyResolved(true);
73 return o.getClass();
74 }
75 }
76 }
77 else
78 {
79 if (property != null)
80 {
81 context.setPropertyResolved(true);
82 if (property instanceof Number)
83 return _pr.getType(base, ((Number) property).intValue());
84 return _pr.getType(base, property);
85 }
86 }
87
88 return null;
89 }
90
91 public Object getValue(ELContext context, Object base, Object property)
92 {
93 FacesContext fc = FacesContext.getCurrentInstance();
94 if (base == null)
95 {
96 if (property != null)
97 {
98 Object o = _vr.resolveVariable(fc, property.toString());
99 if (o != null)
100 {
101 context.setPropertyResolved(true);
102 return o;
103 }
104 }
105 }
106 else
107 {
108 if (property != null)
109 {
110 context.setPropertyResolved(true);
111 if (property instanceof Number)
112 return _pr.getValue(base, ((Number) property).intValue());
113 return _pr.getValue(base, property);
114 }
115 }
116
117 return null;
118 }
119
120 public boolean isReadOnly(ELContext context, Object base, Object property)
121 {
122 FacesContext fc = FacesContext.getCurrentInstance();
123 if (base == null)
124 {
125
126 return false;
127 }
128 else
129 {
130 if (property != null)
131 {
132 context.setPropertyResolved(true);
133 if (property instanceof Number)
134 return _pr.isReadOnly(base, ((Number) property).intValue());
135 return _pr.isReadOnly(base, property);
136 }
137 }
138
139 return false;
140 }
141
142 public void setValue(ELContext context, Object base, Object property, Object value)
143 {
144 FacesContext fc = FacesContext.getCurrentInstance();
145 if (base == null)
146 {
147
148 }
149 else
150 {
151 if (property != null)
152 {
153 context.setPropertyResolved(true);
154 if (property instanceof Number)
155 _pr.setValue(base, ((Number) property).intValue(), value);
156 _pr.setValue(base, property, value);
157 }
158 }
159 }
160
161 private final PropertyResolver _pr;
162 private final VariableResolver _vr;
163 }