Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
*/ |
17 |
|
18 |
package org.apache.jasper.el; |
19 |
|
20 |
import java.util.List; |
21 |
|
22 |
import javax.el.ArrayELResolver; |
23 |
import javax.el.BeanELResolver; |
24 |
import javax.el.CompositeELResolver; |
25 |
import javax.el.ELContext; |
26 |
import javax.el.ELException; |
27 |
import javax.el.ELResolver; |
28 |
import javax.el.ListELResolver; |
29 |
import javax.el.MapELResolver; |
30 |
import javax.el.PropertyNotFoundException; |
31 |
import javax.el.ResourceBundleELResolver; |
32 |
import javax.servlet.jsp.el.ImplicitObjectELResolver; |
33 |
import javax.servlet.jsp.el.ScopedAttributeELResolver; |
34 |
|
35 |
import org.apache.el.lang.ELSupport; |
36 |
|
37 |
/* |
38 |
* Jasper-specific CompositeELResolver that optimizes certain functions to avoid unnecessary resolver calls. |
39 |
*/ |
40 |
public class JasperELResolver extends CompositeELResolver { |
41 |
|
42 |
private int size; |
43 |
private ELResolver[] resolvers; |
44 |
private int appResolversSize; |
45 |
|
46 |
public JasperELResolver(List<ELResolver> appResolvers) { |
47 |
appResolversSize = appResolvers.size(); |
48 |
resolvers = new ELResolver[0]; |
49 |
size = resolvers.length; |
50 |
|
51 |
add(new ImplicitObjectELResolver()); |
52 |
for (ELResolver appResolver : appResolvers) { |
53 |
add(appResolver); |
54 |
} |
55 |
add(new MapELResolver()); |
56 |
add(new ResourceBundleELResolver()); |
57 |
add(new ListELResolver()); |
58 |
add(new ArrayELResolver()); |
59 |
add(new BeanELResolver()); |
60 |
add(new ScopedAttributeELResolver()); |
61 |
} |
62 |
|
63 |
@Override |
64 |
public synchronized void add(ELResolver elResolver) { |
65 |
super.add(elResolver); |
66 |
|
67 |
ELResolver[] nr = new ELResolver[size + 1]; |
68 |
System.arraycopy(resolvers, 0, nr, 0, size); |
69 |
nr[size] = elResolver; |
70 |
|
71 |
resolvers = nr; |
72 |
size ++; |
73 |
} |
74 |
|
75 |
@Override |
76 |
public Object getValue(ELContext context, Object base, Object property) |
77 |
throws NullPointerException, PropertyNotFoundException, ELException { |
78 |
context.setPropertyResolved(false); |
79 |
|
80 |
int start; |
81 |
Object result = null; |
82 |
|
83 |
if (base == null) { |
84 |
// call implicit and app resolvers |
85 |
int index = 1 /* implicit */ + appResolversSize; |
86 |
for (int i = 0; i < index; i++) { |
87 |
result = resolvers[i].getValue(context, base, property); |
88 |
if (context.isPropertyResolved()) { |
89 |
return result; |
90 |
} |
91 |
} |
92 |
// skip collection-based resolvers (map, resource, list, array, and bean) |
93 |
start = index + 5; |
94 |
} else { |
95 |
// skip implicit resolver only |
96 |
start = 1; |
97 |
} |
98 |
|
99 |
for (int i = start; i < size; i++) { |
100 |
result = resolvers[i].getValue(context, base, property); |
101 |
if (context.isPropertyResolved()) { |
102 |
return result; |
103 |
} |
104 |
} |
105 |
|
106 |
return null; |
107 |
} |
108 |
|
109 |
@Override |
110 |
public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) { |
111 |
String targetMethod = ELSupport.coerceToString(method); |
112 |
if (targetMethod.length() == 0) { |
113 |
throw new ELException(new NoSuchMethodException()); |
114 |
} |
115 |
|
116 |
context.setPropertyResolved(false); |
117 |
|
118 |
Object result = null; |
119 |
|
120 |
// skip implicit and call app resolvers |
121 |
int index = 1 /* implicit */ + appResolversSize; |
122 |
for (int i = 1; i < index; i++) { |
123 |
result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params); |
124 |
if (context.isPropertyResolved()) { |
125 |
return result; |
126 |
} |
127 |
} |
128 |
|
129 |
// skip map, resource, list, and array resolvers |
130 |
index += 4; |
131 |
// call bean and the rest of resolvers |
132 |
for (int i = index; i < size; i++) { |
133 |
result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params); |
134 |
if (context.isPropertyResolved()) { |
135 |
return result; |
136 |
} |
137 |
} |
138 |
|
139 |
return null; |
140 |
} |
141 |
|
142 |
} |
0 |
+ text/plain |
143 |
+ text/plain |
1 |
+ Date Revision |
144 |
+ Date Revision |
2 |
+ native |
145 |
+ native |