1 21 package com.presumo.jms.selector; 22 23 import javax.jms.Message ; 24 import javax.jms.JMSException ; 25 import java.util.Hashtable ; 26 27 33 class JmsIdentifier extends JmsOperand 34 { 35 private String identifier = null; 37 38 private static Hashtable instances = null; 41 42 43 50 static JmsIdentifier getInstance(String newValue) { 51 JmsIdentifier retval; 52 53 if (instances == null) 54 instances = new Hashtable (); 55 56 retval = (JmsIdentifier) instances.get(newValue); 57 if (retval == null) { 58 retval = new JmsIdentifier(newValue); 59 instances.put(newValue, retval); 60 } 61 else { 62 retval.incrementRefCount(); 63 } 64 65 return retval; 66 } 67 68 72 75 protected JmsIdentifier(String newValue) 76 { 77 super(true); 78 this.identifier = newValue; 79 } 80 81 public String toString() { return identifier + " " + super.toString(); } 85 86 87 88 92 97 String getIdentifier() 98 { 99 return identifier; 100 } 101 102 JmsOperand evaluate(Message msg) throws SelectorFalseException { 103 104 Object value; 105 try { 106 value = msg.getObjectProperty(identifier); 107 } catch (JMSException e) { throw SelectorFalseException.getInstance(); } 108 109 if (value == null) 110 return null; 111 112 if (value instanceof String ) 113 return JmsStringLiteral.getUniqueInstance((String )value); 114 115 if (value instanceof Boolean ) { 116 if (((Boolean )value).booleanValue()) 117 return JmsBooleanLiteral.TRUE; 118 else 119 return JmsBooleanLiteral.FALSE; 120 } 121 122 if (value instanceof Number ) { 123 if ( (value instanceof Double ) || (value instanceof Float ) ) 124 return JmsFloatLiteral.getUniqueInstance( ((Number )value).doubleValue() ); 125 else 126 return JmsIntegerLiteral.getUniqueInstance( ((Number )value).longValue() ); 127 } 128 129 throw SelectorFalseException.getInstance(); 133 } 134 135 String unParse() 136 { 137 return identifier; 138 } 139 140 144 short getType() { return JmsOperand.JMS_IDENTIFIER; } 145 146 147 151 protected void delete(JmsOperand parent) { 152 super.delete(parent); 153 if (refcount == 0 && instances != null) { 154 instances.remove(identifier); 155 if (instances.size() == 0) { 156 instances = null; 157 } 158 } 159 } 160 161 } 162 163 164 165 | Popular Tags |