001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jasper.el;
019:
020: import java.util.Iterator;
021:
022: import javax.el.ArrayELResolver;
023: import javax.el.BeanELResolver;
024: import javax.el.CompositeELResolver;
025: import javax.el.ELContext;
026: import javax.el.ELException;
027: import javax.el.ELResolver;
028: import javax.el.ListELResolver;
029: import javax.el.MapELResolver;
030: import javax.el.PropertyNotFoundException;
031: import javax.el.PropertyNotWritableException;
032: import javax.el.ResourceBundleELResolver;
033: import javax.servlet.jsp.el.VariableResolver;
034:
035: public final class ELResolverImpl extends ELResolver {
036:
037: public final static ELResolver DefaultResolver = new CompositeELResolver();
038:
039: static {
040: ((CompositeELResolver) DefaultResolver)
041: .add(new MapELResolver());
042: ((CompositeELResolver) DefaultResolver)
043: .add(new ResourceBundleELResolver());
044: ((CompositeELResolver) DefaultResolver)
045: .add(new ListELResolver());
046: ((CompositeELResolver) DefaultResolver)
047: .add(new ArrayELResolver());
048: ((CompositeELResolver) DefaultResolver)
049: .add(new BeanELResolver());
050: }
051:
052: private final VariableResolver variableResolver;
053:
054: public ELResolverImpl(VariableResolver variableResolver) {
055: this .variableResolver = variableResolver;
056: }
057:
058: public Object getValue(ELContext context, Object base,
059: Object property) throws NullPointerException,
060: PropertyNotFoundException, ELException {
061: if (context == null) {
062: throw new NullPointerException();
063: }
064:
065: if (base == null) {
066: context.setPropertyResolved(true);
067: if (property != null) {
068: try {
069: return this .variableResolver
070: .resolveVariable(property.toString());
071: } catch (javax.servlet.jsp.el.ELException e) {
072: throw new ELException(e.getMessage(), e.getCause());
073: }
074: }
075: }
076:
077: if (!context.isPropertyResolved()) {
078: return DefaultResolver.getValue(context, base, property);
079: }
080: return null;
081: }
082:
083: public Class<?> getType(ELContext context, Object base,
084: Object property) throws NullPointerException,
085: PropertyNotFoundException, ELException {
086: if (context == null) {
087: throw new NullPointerException();
088: }
089:
090: if (base == null) {
091: context.setPropertyResolved(true);
092: if (property != null) {
093: try {
094: Object obj = this .variableResolver
095: .resolveVariable(property.toString());
096: return (obj != null) ? obj.getClass() : null;
097: } catch (javax.servlet.jsp.el.ELException e) {
098: throw new ELException(e.getMessage(), e.getCause());
099: }
100: }
101: }
102:
103: if (!context.isPropertyResolved()) {
104: return DefaultResolver.getType(context, base, property);
105: }
106: return null;
107: }
108:
109: public void setValue(ELContext context, Object base,
110: Object property, Object value) throws NullPointerException,
111: PropertyNotFoundException, PropertyNotWritableException,
112: ELException {
113: if (context == null) {
114: throw new NullPointerException();
115: }
116:
117: if (base == null) {
118: context.setPropertyResolved(true);
119: throw new PropertyNotWritableException(
120: "Legacy VariableResolver wrapped, not writable");
121: }
122:
123: if (!context.isPropertyResolved()) {
124: DefaultResolver.setValue(context, base, property, value);
125: }
126: }
127:
128: public boolean isReadOnly(ELContext context, Object base,
129: Object property) throws NullPointerException,
130: PropertyNotFoundException, ELException {
131: if (context == null) {
132: throw new NullPointerException();
133: }
134:
135: if (base == null) {
136: context.setPropertyResolved(true);
137: return true;
138: }
139:
140: return DefaultResolver.isReadOnly(context, base, property);
141: }
142:
143: public Iterator<java.beans.FeatureDescriptor> getFeatureDescriptors(
144: ELContext context, Object base) {
145: return DefaultResolver.getFeatureDescriptors(context, base);
146: }
147:
148: public Class<?> getCommonPropertyType(ELContext context, Object base) {
149: if (base == null) {
150: return String.class;
151: }
152: return DefaultResolver.getCommonPropertyType(context, base);
153: }
154:
155: }
|