1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.el; |
20 | |
|
21 | |
import java.beans.FeatureDescriptor; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Collections; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.NoSuchElementException; |
27 | |
|
28 | |
import javax.el.ELContext; |
29 | |
import javax.el.ELResolver; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class CompositeELResolver extends javax.el.CompositeELResolver |
36 | |
{ |
37 | 0 | private Collection<ELResolver> _elResolvers = Collections.EMPTY_LIST; |
38 | |
|
39 | |
@Override |
40 | |
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base) |
41 | |
{ |
42 | 0 | return new CompositeIterator(context, base, _elResolvers.iterator()); |
43 | |
} |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public final void add(final ELResolver elResolver) |
49 | |
{ |
50 | 0 | super.add(elResolver); |
51 | |
|
52 | 0 | if (_elResolvers == Collections.EMPTY_LIST) |
53 | |
{ |
54 | 0 | _elResolvers = new ArrayList(); |
55 | |
} |
56 | |
|
57 | 0 | _elResolvers.add(elResolver); |
58 | 0 | } |
59 | |
|
60 | 0 | private static class CompositeIterator implements Iterator<FeatureDescriptor> |
61 | |
{ |
62 | |
private final ELContext _context; |
63 | |
private final Object _base; |
64 | |
private final Iterator<ELResolver> _elResolvers; |
65 | |
|
66 | |
private FeatureDescriptor _nextFD; |
67 | |
|
68 | |
private Iterator<FeatureDescriptor> _currentFDIter; |
69 | |
|
70 | |
public CompositeIterator(final ELContext context, final Object base, final Iterator<ELResolver> elResolvers) |
71 | 0 | { |
72 | 0 | _context = context; |
73 | 0 | _base = base; |
74 | 0 | _elResolvers = elResolvers; |
75 | 0 | } |
76 | |
|
77 | |
public boolean hasNext() |
78 | |
{ |
79 | 0 | if (_nextFD != null) |
80 | 0 | return true; |
81 | 0 | if (_currentFDIter != null) |
82 | |
{ |
83 | 0 | while (_nextFD == null && _currentFDIter.hasNext()) |
84 | |
{ |
85 | 0 | _nextFD = _currentFDIter.next(); |
86 | |
} |
87 | |
} |
88 | 0 | if (_nextFD == null) |
89 | |
{ |
90 | 0 | if (_elResolvers.hasNext()) |
91 | |
{ |
92 | 0 | _currentFDIter = _elResolvers.next().getFeatureDescriptors(_context, _base); |
93 | |
} |
94 | |
else |
95 | |
{ |
96 | 0 | return false; |
97 | |
} |
98 | |
} |
99 | 0 | return hasNext(); |
100 | |
} |
101 | |
|
102 | |
public FeatureDescriptor next() |
103 | |
{ |
104 | 0 | if (!hasNext()) |
105 | 0 | throw new NoSuchElementException(); |
106 | 0 | FeatureDescriptor next = _nextFD; |
107 | 0 | _nextFD = null; |
108 | 0 | return next; |
109 | |
} |
110 | |
|
111 | |
public void remove() |
112 | |
{ |
113 | 0 | throw new UnsupportedOperationException(); |
114 | |
} |
115 | |
|
116 | |
} |
117 | |
} |