1 28 29 package com.caucho.jms.selector; 30 31 import com.caucho.jms.message.ObjectConverter; 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import javax.jms.JMSException ; 36 import javax.jms.Message ; 37 import java.util.logging.Logger ; 38 39 42 abstract public class Selector { 43 protected static final Logger log = Log.open(Selector.class); 44 static final L10N L = new L10N(Selector.class); 45 46 protected final static Object NULL = new Object (); 47 48 51 abstract Object evaluate(Message message) 52 throws JMSException ; 53 54 public boolean isMatch(Message message) 55 throws JMSException 56 { 57 Object obj = evaluate(message); 58 59 if (! (obj instanceof Boolean )) 60 return false; 61 62 Boolean bool = (Boolean ) obj; 63 64 return bool.booleanValue(); 65 } 66 67 protected static Boolean toBoolean(boolean value) 68 { 69 return value ? Boolean.TRUE : Boolean.FALSE; 70 } 71 72 boolean isBoolean() 73 { 74 return false; 75 } 76 77 boolean isUnknown() 78 { 79 return true; 80 } 81 82 boolean isNumber() 83 { 84 return false; 85 } 86 87 static boolean isDouble(Object obj) 88 { 89 return obj instanceof Double || obj instanceof Float ; 90 } 91 92 static boolean isInteger(Object obj) 93 { 94 return (obj instanceof Integer || 95 obj instanceof Long || 96 obj instanceof Short || 97 obj instanceof Byte ); 98 } 99 100 static boolean isNumber(Object obj) 101 { 102 return (obj instanceof Number ); 103 } 104 105 protected long toLong(Object obj) 106 throws JMSException 107 { 108 return ObjectConverter.toLong(obj); 109 } 110 111 protected double toDouble(Object obj) 112 throws JMSException 113 { 114 return ObjectConverter.toDouble(obj); 115 } 116 } 117 | Popular Tags |