1 14 15 package com.sun.facelets.tag; 16 17 import javax.el.ELException; 18 import javax.el.ExpressionFactory; 19 import javax.el.MethodExpression; 20 import javax.el.ValueExpression; 21 22 import com.sun.facelets.FaceletContext; 23 import com.sun.facelets.el.ELText; 24 import com.sun.facelets.el.TagMethodExpression; 25 import com.sun.facelets.el.TagValueExpression; 26 27 33 public final class TagAttribute { 34 35 private final boolean literal; 36 37 private final String localName; 38 39 private final Location location; 40 41 private final String namespace; 42 43 private final String qName; 44 45 private final String value; 46 47 private String string; 48 49 public TagAttribute(Location location, String ns, String localName, 50 String qName, String value) { 51 this.location = location; 52 this.namespace = ns; 53 this.localName = localName; 54 this.qName = qName; 55 this.value = value; 56 try { 57 this.literal = ELText.isLiteral(this.value); 58 } catch (ELException e) { 59 throw new TagAttributeException(this, e); 60 } 61 } 62 63 75 public boolean getBoolean(FaceletContext ctx) { 76 if (this.literal) { 77 return Boolean.valueOf(this.value).booleanValue(); 78 } else { 79 return ((Boolean ) this.getObject(ctx, Boolean .class)) 80 .booleanValue(); 81 } 82 } 83 84 96 public int getInt(FaceletContext ctx) { 97 if (this.literal) { 98 return Integer.parseInt(this.value); 99 } else { 100 return ((Number ) this.getObject(ctx, Number .class)).intValue(); 101 } 102 } 103 104 109 public String getLocalName() { 110 return this.localName; 111 } 112 113 118 public Location getLocation() { 119 return this.location; 120 } 121 122 137 public MethodExpression getMethodExpression(FaceletContext ctx, Class type, 138 Class [] paramTypes) { 139 try { 140 ExpressionFactory f = ctx.getExpressionFactory(); 141 return new TagMethodExpression(this, f.createMethodExpression(ctx, 142 this.value, type, paramTypes)); 143 } catch (Exception e) { 144 throw new TagAttributeException(this, e); 145 } 146 } 147 148 153 public String getNamespace() { 154 return this.namespace; 155 } 156 157 165 public Object getObject(FaceletContext ctx) { 166 return this.getObject(ctx, Object .class); 167 } 168 169 174 public String getQName() { 175 return this.qName; 176 } 177 178 183 public String getValue() { 184 return this.value; 185 } 186 187 196 public String getValue(FaceletContext ctx) { 197 if (this.literal) { 198 return this.value; 199 } else { 200 return (String ) this.getObject(ctx, String .class); 201 } 202 } 203 204 218 public Object getObject(FaceletContext ctx, Class type) { 219 if (this.literal) { 220 if (String .class.equals(type)) { 221 return this.value; 222 } else { 223 try { 224 return ctx.getExpressionFactory().coerceToType(this.value, 225 type); 226 } catch (Exception e) { 227 throw new TagAttributeException(this, e); 228 } 229 } 230 } else { 231 ValueExpression ve = this.getValueExpression(ctx, type); 232 try { 233 return ve.getValue(ctx); 234 } catch (Exception e) { 235 throw new TagAttributeException(this, e); 236 } 237 } 238 } 239 240 253 public ValueExpression getValueExpression(FaceletContext ctx, Class type) { 254 try { 255 ExpressionFactory f = ctx.getExpressionFactory(); 256 return new TagValueExpression(this, f.createValueExpression(ctx, 257 this.value, type)); 258 } catch (Exception e) { 259 throw new TagAttributeException(this, e); 260 } 261 } 262 263 268 public boolean isLiteral() { 269 return this.literal; 270 } 271 272 277 public String toString() { 278 if (this.string == null) { 279 this.string = this.location + " " + this.qName + "=\"" + this.value 280 + "\""; 281 } 282 return this.string; 283 } 284 285 } 286 | Popular Tags |