1 43 44 package org.exolab.jms.selector; 45 46 import javax.jms.Message ; 47 48 49 56 class Literal implements Expression { 57 58 61 private SObject _value = null; 62 63 68 protected Literal(final SObject value) { 69 _value = value; 70 } 71 72 80 public static Literal approxNumericLiteral(final String text) 81 throws SelectorException { 82 SDouble value = null; 83 try { 84 value = new SDouble(Double.parseDouble(text)); 85 } catch (NumberFormatException exception) { 86 throw new SelectorException("invalid float: " + text); 87 } 88 return new Literal(value); 89 } 90 91 99 public static Literal exactNumericLiteral(final String text) 100 throws SelectorException { 101 SLong value = null; 102 try { 103 value = new SLong(Long.decode(text).longValue()); 104 } catch (NumberFormatException exception) { 105 throw new SelectorException("invalid integer: " + text); 106 } 107 return new Literal(value); 108 } 109 110 116 public static Literal stringLiteral(final String text) { 117 return new Literal(new SString(text)) { 118 119 public final String toString() { 120 return "'" + this.getValue().toString() + "'"; 121 } 122 }; 123 } 124 125 131 public static Literal booleanLiteral(final boolean value) { 132 SBool bool = SBool.FALSE; 133 if (value) { 134 bool = SBool.TRUE; 135 } 136 return new Literal(bool); 137 } 138 139 147 public final SObject evaluate(final Message msg) { 148 return _value; 149 } 150 151 156 public String toString() { 157 return getValue().toString(); 158 } 159 160 165 protected final SObject getValue() { 166 return _value; 167 } 168 169 } | Popular Tags |