1 29 30 package com.caucho.el; 31 32 import javax.el.ELContext; 33 import javax.el.ELResolver; 34 import java.beans.FeatureDescriptor ; 35 import java.util.ArrayList ; 36 import java.util.Iterator ; 37 38 41 public class StackELResolver extends ELResolver { 42 public final ArrayList <ELResolver> _resolverStack 43 = new ArrayList <ELResolver>(); 44 45 public StackELResolver() 46 { 47 } 48 49 public void push(ELResolver elResolver) 50 { 51 if (elResolver == null) 52 throw new NullPointerException (); 53 54 _resolverStack.add(elResolver); 55 } 56 57 public ELResolver pop() 58 { 59 if (_resolverStack.size() > 0) 60 return _resolverStack.remove(_resolverStack.size() - 1); 61 else 62 return null; 63 } 64 65 @Override 66 public Class <?> getCommonPropertyType(ELContext env, Object base) 67 { 68 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 69 ELResolver resolver = _resolverStack.get(i); 70 71 return getCommonPropertyType(env, base); 72 } 73 74 return null; 75 } 76 77 @Override 78 public Iterator <FeatureDescriptor > getFeatureDescriptors(ELContext env, 79 Object base) 80 { 81 ArrayList <FeatureDescriptor > descriptors = null; 82 83 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 84 ELResolver resolver = _resolverStack.get(i); 85 86 Iterator <FeatureDescriptor > iter 87 = resolver.getFeatureDescriptors(env, base); 88 89 if (iter == null) 90 continue; 91 92 if (descriptors == null) 93 descriptors = new ArrayList <FeatureDescriptor >(); 94 95 while (iter.hasNext()) { 96 FeatureDescriptor desc = iter.next(); 97 98 descriptors.add(desc); 99 } 100 } 101 102 if (descriptors != null) 103 return descriptors.iterator(); 104 else 105 return null; 106 } 107 108 @Override 109 public Class <?> getType(ELContext context, 110 Object base, 111 Object property) 112 { 113 context.setPropertyResolved(false); 114 115 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 116 ELResolver resolver = _resolverStack.get(i); 117 118 Class type = resolver.getType(context, base, property); 119 120 if (context.isPropertyResolved()) 121 return type; 122 } 123 124 return null; 125 } 126 127 @Override 128 public Object getValue(ELContext context, 129 Object base, 130 Object property) 131 { 132 context.setPropertyResolved(false); 133 134 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 135 ELResolver resolver = _resolverStack.get(i); 136 137 Object value = resolver.getValue(context, base, property); 138 139 if (context.isPropertyResolved()) { 140 return value; 141 } 142 } 143 144 return null; 145 } 146 147 @Override 148 public boolean isReadOnly(ELContext context, 149 Object base, 150 Object property) 151 { 152 context.setPropertyResolved(false); 153 154 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 155 ELResolver resolver = _resolverStack.get(i); 156 157 boolean isReadOnly = resolver.isReadOnly(context, base, property); 158 159 if (context.isPropertyResolved()) 160 return isReadOnly; 161 } 162 163 return false; 164 } 165 166 @Override 167 public void setValue(ELContext context, 168 Object base, 169 Object property, 170 Object value) 171 { 172 context.setPropertyResolved(false); 173 174 for (int i = _resolverStack.size() - 1; i >= 0; i--) { 175 ELResolver resolver = _resolverStack.get(i); 176 177 resolver.setValue(context, base, property, value); 178 179 if (context.isPropertyResolved()) { 180 return; 181 } 182 } 183 } 184 } 185 | Popular Tags |