1 17 18 package javax.el; 19 20 import java.beans.FeatureDescriptor ; 21 import java.util.Iterator ; 22 23 public class CompositeELResolver extends ELResolver { 24 25 private int size; 26 27 private ELResolver[] resolvers; 28 29 public CompositeELResolver() { 30 this.size = 0; 31 this.resolvers = new ELResolver[2]; 32 } 33 34 public void add(ELResolver elResolver) { 35 if (elResolver == null) { 36 throw new NullPointerException (); 37 } 38 39 if (this.size >= this.resolvers.length) { 40 ELResolver[] nr = new ELResolver[this.size * 2]; 41 System.arraycopy(this.resolvers, 0, nr, 0, this.size); 42 this.resolvers = nr; 43 } 44 this.resolvers[this.size++] = elResolver; 45 } 46 47 public Object getValue(ELContext context, Object base, Object property) 48 throws NullPointerException , PropertyNotFoundException, ELException { 49 context.setPropertyResolved(false); 50 int sz = this.size; 51 Object result = null; 52 for (int i = 0; i < sz; i++) { 53 result = this.resolvers[i].getValue(context, base, property); 54 if (context.isPropertyResolved()) { 55 return result; 56 } 57 } 58 return null; 59 } 60 61 public void setValue(ELContext context, Object base, Object property, 62 Object value) throws NullPointerException , 63 PropertyNotFoundException, PropertyNotWritableException, 64 ELException { 65 context.setPropertyResolved(false); 66 int sz = this.size; 67 for (int i = 0; i < sz; i++) { 68 this.resolvers[i].setValue(context, base, property, value); 69 if (context.isPropertyResolved()) { 70 return; 71 } 72 } 73 } 74 75 public boolean isReadOnly(ELContext context, Object base, Object property) 76 throws NullPointerException , PropertyNotFoundException, ELException { 77 context.setPropertyResolved(false); 78 int sz = this.size; 79 boolean readOnly = false; 80 for (int i = 0; i < sz; i++) { 81 readOnly = this.resolvers[i].isReadOnly(context, base, property); 82 if (context.isPropertyResolved()) { 83 return readOnly; 84 } 85 } 86 return false; 87 } 88 89 public Iterator <FeatureDescriptor > getFeatureDescriptors(ELContext context, Object base) { 90 return new FeatureIterator(context, base, this.resolvers, this.size); 91 } 92 93 public Class <?> getCommonPropertyType(ELContext context, Object base) { 94 int sz = this.size; 95 Class <?> commonType = null, type = null; 96 for (int i = 0; i < sz; i++) { 97 type = this.resolvers[i].getCommonPropertyType(context, base); 98 if (type != null 99 && (commonType == null || commonType.isAssignableFrom(type))) { 100 commonType = type; 101 } 102 } 103 return commonType; 104 } 105 106 public Class <?> getType(ELContext context, Object base, Object property) 107 throws NullPointerException , PropertyNotFoundException, ELException { 108 context.setPropertyResolved(false); 109 int sz = this.size; 110 Class <?> type; 111 for (int i = 0; i < sz; i++) { 112 type = this.resolvers[i].getType(context, base, property); 113 if (context.isPropertyResolved()) { 114 return type; 115 } 116 } 117 return null; 118 } 119 120 private final static class FeatureIterator implements Iterator <FeatureDescriptor > { 121 122 private final ELContext context; 123 124 private final Object base; 125 126 private final ELResolver[] resolvers; 127 128 private final int size; 129 130 private Iterator itr; 131 132 private int idx; 133 134 public FeatureIterator(ELContext context, Object base, 135 ELResolver[] resolvers, int size) { 136 this.context = context; 137 this.base = base; 138 this.resolvers = resolvers; 139 this.size = size; 140 141 this.idx = 0; 142 this.guaranteeIterator(); 143 } 144 145 private void guaranteeIterator() { 146 while (this.itr == null && this.idx < this.size) { 147 this.itr = this.resolvers[this.idx].getFeatureDescriptors( 148 this.context, this.base); 149 this.idx++; 150 } 151 } 152 153 public boolean hasNext() { 154 return this.itr != null; 155 } 156 157 public FeatureDescriptor next() { 158 Object result = null; 159 if (this.itr != null) { 160 if (this.itr.hasNext()) { 161 result = this.itr.next(); 162 if (!this.itr.hasNext()) { 163 this.itr = null; 164 this.guaranteeIterator(); 165 } 166 } 167 } 168 return (FeatureDescriptor ) result; 169 } 170 171 public void remove() { 172 throw new UnsupportedOperationException (); 173 } 174 } 175 176 } 177 | Popular Tags |