001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.myfaces.el;
020:
021: import java.beans.FeatureDescriptor;
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.Iterator;
026: import java.util.NoSuchElementException;
027:
028: import javax.el.ELContext;
029: import javax.el.ELResolver;
030:
031: /**
032: * @author Mathias Broekelmann (latest modification by $Author: mbr $)
033: * @version $Revision: 527076 $ $Date: 2007-04-10 12:01:32 +0200 (Di, 10 Apr 2007) $
034: */
035: public class CompositeELResolver extends javax.el.CompositeELResolver {
036: private Collection<ELResolver> _elResolvers = Collections.EMPTY_LIST;
037:
038: @Override
039: public Iterator<FeatureDescriptor> getFeatureDescriptors(
040: ELContext context, Object base) {
041: return new CompositeIterator(context, base, _elResolvers
042: .iterator());
043: }
044:
045: /**
046: * @param elResolver
047: */
048: public void add(ELResolver elResolver) {
049: super .add(elResolver);
050:
051: if (_elResolvers == Collections.EMPTY_LIST) {
052: _elResolvers = new ArrayList();
053: }
054:
055: _elResolvers.add(elResolver);
056: }
057:
058: private static class CompositeIterator implements
059: Iterator<FeatureDescriptor> {
060: private final ELContext _context;
061: private final Object _base;
062: private final Iterator<ELResolver> _elResolvers;
063:
064: private FeatureDescriptor _nextFD;
065:
066: private Iterator<FeatureDescriptor> _currentFDIter;
067:
068: public CompositeIterator(ELContext context, Object base,
069: Iterator<ELResolver> elResolvers) {
070: _context = context;
071: _base = base;
072: _elResolvers = elResolvers;
073: }
074:
075: public boolean hasNext() {
076: if (_nextFD != null)
077: return true;
078: if (_currentFDIter != null) {
079: while (_nextFD == null && _currentFDIter.hasNext()) {
080: _nextFD = _currentFDIter.next();
081: }
082: }
083: if (_nextFD == null) {
084: if (_elResolvers.hasNext()) {
085: _currentFDIter = _elResolvers.next()
086: .getFeatureDescriptors(_context, _base);
087: } else {
088: return false;
089: }
090: }
091: return hasNext();
092: }
093:
094: public FeatureDescriptor next() {
095: if (!hasNext())
096: throw new NoSuchElementException();
097: FeatureDescriptor next = _nextFD;
098: _nextFD = null;
099: return next;
100: }
101:
102: public void remove() {
103: throw new UnsupportedOperationException();
104: }
105:
106: }
107: }
|