001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package javax.el;
031:
032: import java.beans.FeatureDescriptor;
033: import java.util.ArrayList;
034: import java.util.Iterator;
035:
036: /**
037: * Resolves properties based on arrays.
038: */
039: public class CompositeELResolver extends ELResolver {
040: public final ArrayList<ELResolver> _resolvers = new ArrayList<ELResolver>();
041:
042: public CompositeELResolver() {
043: }
044:
045: public void add(ELResolver elResolver) {
046: if (elResolver == null)
047: throw new NullPointerException();
048:
049: _resolvers.add(elResolver);
050: }
051:
052: @Override
053: public Class<?> getCommonPropertyType(ELContext env, Object base) {
054: Class commonClass = null;
055:
056: int size = _resolvers.size();
057: for (int i = 0; i < size; i++) {
058: ELResolver resolver = _resolvers.get(i);
059:
060: Class cl = resolver.getCommonPropertyType(env, base);
061:
062: if (cl == null)
063: continue;
064:
065: commonClass = cl;
066: }
067:
068: return commonClass;
069: }
070:
071: @Override
072: public Iterator<FeatureDescriptor> getFeatureDescriptors(
073: ELContext env, Object base) {
074: ArrayList<FeatureDescriptor> descriptors = new ArrayList<FeatureDescriptor>();
075:
076: int size = _resolvers.size();
077: for (int i = 0; i < size; i++) {
078: ELResolver resolver = _resolvers.get(i);
079:
080: Iterator<FeatureDescriptor> iter = resolver
081: .getFeatureDescriptors(env, base);
082:
083: if (iter == null)
084: continue;
085:
086: while (iter.hasNext()) {
087: FeatureDescriptor desc = iter.next();
088:
089: descriptors.add(desc);
090: }
091: }
092:
093: return descriptors.iterator();
094: }
095:
096: @Override
097: public Class<?> getType(ELContext env, Object base, Object property) {
098: env.setPropertyResolved(false);
099:
100: int size = _resolvers.size();
101: for (int i = 0; i < size; i++) {
102: ELResolver resolver = _resolvers.get(i);
103:
104: Class type = resolver.getType(env, base, property);
105:
106: if (env.isPropertyResolved())
107: return type;
108: }
109:
110: return null;
111: }
112:
113: @Override
114: public Object getValue(ELContext context, Object base,
115: Object property) {
116: context.setPropertyResolved(false);
117:
118: int size = _resolvers.size();
119: for (int i = 0; i < size; i++) {
120: ELResolver resolver = _resolvers.get(i);
121:
122: Object value = resolver.getValue(context, base, property);
123:
124: if (context.isPropertyResolved())
125: return value;
126: }
127:
128: return null;
129: }
130:
131: @Override
132: public boolean isReadOnly(ELContext context, Object base,
133: Object property) {
134: context.setPropertyResolved(false);
135:
136: int size = _resolvers.size();
137: for (int i = 0; i < size; i++) {
138: ELResolver resolver = _resolvers.get(i);
139:
140: boolean value = resolver
141: .isReadOnly(context, base, property);
142:
143: if (context.isPropertyResolved())
144: return value;
145: }
146:
147: return true;
148: }
149:
150: @Override
151: public void setValue(ELContext context, Object base,
152: Object property, Object value) {
153: context.setPropertyResolved(false);
154:
155: int size = _resolvers.size();
156: for (int i = 0; i < size; i++) {
157: ELResolver resolver = _resolvers.get(i);
158:
159: resolver.setValue(context, base, property, value);
160:
161: if (context.isPropertyResolved())
162: return;
163: }
164: }
165: }
|