1 package com.sun.el; 23 24 import java.io.Externalizable ; 25 import java.io.IOException ; 26 import javax.el.ELContext; 27 import javax.el.PropertyNotWritableException; 28 29 import java.io.ObjectInput ; 30 import java.io.ObjectOutput ; 31 32 import javax.el.ValueExpression; 33 34 import com.sun.el.lang.ELSupport; 35 import com.sun.el.util.MessageFactory; 36 import com.sun.el.util.ReflectionUtil; 37 38 public final class ValueExpressionLiteral extends ValueExpression implements 39 Externalizable { 40 41 private static final long serialVersionUID = 1L; 42 43 private Object value; 44 45 private Class expectedType; 46 47 public ValueExpressionLiteral() { 48 super(); 49 } 50 51 public ValueExpressionLiteral(Object value, Class expectedType) { 52 this.value = value; 53 this.expectedType = expectedType; 54 } 55 56 public Object getValue(ELContext context) { 57 if (this.expectedType != null) { 58 return ELSupport.coerceToType(this.value, this.expectedType); 59 } 60 return this.value; 61 } 62 63 public void setValue(ELContext context, Object value) { 64 throw new PropertyNotWritableException(MessageFactory.get( 65 "error.value.literal.write", this.value)); 66 } 67 68 public boolean isReadOnly(ELContext context) { 69 return true; 70 } 71 72 public Class getType(ELContext context) { 73 return (this.value != null) ? this.value.getClass() : null; 74 } 75 76 public Class getExpectedType() { 77 return this.expectedType; 78 } 79 80 public String getExpressionString() { 81 return (this.value != null) ? this.value.toString() : null; 82 } 83 84 public boolean equals(Object obj) { 85 return (obj instanceof ValueExpressionLiteral && this 86 .equals((ValueExpressionLiteral) obj)); 87 } 88 89 public boolean equals(ValueExpressionLiteral ve) { 90 return (ve != null && (this.value != null && ve.value != null && (this.value == ve.value || this.value 91 .equals(ve.value)))); 92 } 93 94 public int hashCode() { 95 return (this.value != null) ? this.value.hashCode() : 0; 96 } 97 98 public boolean isLiteralText() { 99 return true; 100 } 101 102 public void writeExternal(ObjectOutput out) throws IOException { 103 out.writeObject(this.value); 104 out.writeUTF((this.expectedType != null) ? this.expectedType.getName() 105 : ""); 106 } 107 108 public void readExternal(ObjectInput in) throws IOException , 109 ClassNotFoundException { 110 this.value = in.readObject(); 111 String type = in.readUTF(); 112 if (!"".equals(type)) { 113 this.expectedType = ReflectionUtil.forName(type); 114 } 115 } 116 } 117 | Popular Tags |