KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > el > ELResolverImpl


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.Iterator JavaDoc;
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.PropertyNotWritableException;
32 import javax.el.ResourceBundleELResolver;
33 import javax.servlet.jsp.el.VariableResolver JavaDoc;
34
35 public final class ELResolverImpl extends ELResolver {
36     
37     public final static ELResolver DefaultResolver = new CompositeELResolver();
38
39     static {
40         ((CompositeELResolver) DefaultResolver).add(new MapELResolver());
41         ((CompositeELResolver) DefaultResolver).add(new ResourceBundleELResolver());
42         ((CompositeELResolver) DefaultResolver).add(new ListELResolver());
43         ((CompositeELResolver) DefaultResolver).add(new ArrayELResolver());
44         ((CompositeELResolver) DefaultResolver).add(new BeanELResolver());
45     }
46
47     private final VariableResolver JavaDoc variableResolver;
48
49     public ELResolverImpl(VariableResolver JavaDoc variableResolver) {
50         this.variableResolver = variableResolver;
51     }
52
53     public Object JavaDoc getValue(ELContext context, Object JavaDoc base, Object JavaDoc property)
54             throws NullPointerException JavaDoc, PropertyNotFoundException, ELException {
55         if (context == null) {
56             throw new NullPointerException JavaDoc();
57         }
58
59         if (base == null) {
60             context.setPropertyResolved(true);
61             if (property != null) {
62                 try {
63                     return this.variableResolver.resolveVariable(property
64                             .toString());
65                 } catch (javax.servlet.jsp.el.ELException JavaDoc e) {
66                     throw new ELException(e.getMessage(), e.getCause());
67                 }
68             }
69         }
70
71         if (!context.isPropertyResolved()) {
72             return DefaultResolver.getValue(context, base, property);
73         }
74         return null;
75     }
76
77     public Class JavaDoc<?> getType(ELContext context, Object JavaDoc base, Object JavaDoc property)
78             throws NullPointerException JavaDoc, PropertyNotFoundException, ELException {
79         if (context == null) {
80             throw new NullPointerException JavaDoc();
81         }
82
83         if (base == null) {
84             context.setPropertyResolved(true);
85             if (property != null) {
86                 try {
87                     Object JavaDoc obj = this.variableResolver.resolveVariable(property
88                             .toString());
89                     return (obj != null) ? obj.getClass() : null;
90                 } catch (javax.servlet.jsp.el.ELException JavaDoc e) {
91                     throw new ELException(e.getMessage(), e.getCause());
92                 }
93             }
94         }
95
96         if (!context.isPropertyResolved()) {
97             return DefaultResolver.getType(context, base, property);
98         }
99         return null;
100     }
101
102     public void setValue(ELContext context, Object JavaDoc base, Object JavaDoc property,
103             Object JavaDoc value) throws NullPointerException JavaDoc,
104             PropertyNotFoundException, PropertyNotWritableException,
105             ELException {
106         if (context == null) {
107             throw new NullPointerException JavaDoc();
108         }
109
110         if (base == null) {
111             context.setPropertyResolved(true);
112             throw new PropertyNotWritableException(
113                     "Legacy VariableResolver wrapped, not writable");
114         }
115
116         if (!context.isPropertyResolved()) {
117             DefaultResolver.setValue(context, base, property, value);
118         }
119     }
120
121     public boolean isReadOnly(ELContext context, Object JavaDoc base, Object JavaDoc property)
122             throws NullPointerException JavaDoc, PropertyNotFoundException, ELException {
123         if (context == null) {
124             throw new NullPointerException JavaDoc();
125         }
126
127         if (base == null) {
128             context.setPropertyResolved(true);
129             return true;
130         }
131
132         return DefaultResolver.isReadOnly(context, base, property);
133     }
134
135     public Iterator JavaDoc<java.beans.FeatureDescriptor JavaDoc> getFeatureDescriptors(ELContext context, Object JavaDoc base) {
136         return DefaultResolver.getFeatureDescriptors(context, base);
137     }
138
139     public Class JavaDoc<?> getCommonPropertyType(ELContext context, Object JavaDoc base) {
140         if (base == null) {
141             return String JavaDoc.class;
142         }
143         return DefaultResolver.getCommonPropertyType(context, base);
144     }
145
146 }
147
Popular Tags