1 43 44 package org.exolab.jms.selector; 45 46 import javax.jms.DeliveryMode ; 47 import javax.jms.JMSException ; 48 import javax.jms.Message ; 49 50 51 61 class Identifier implements Expression { 62 63 66 private final String _name; 67 68 72 private final boolean _headerField; 73 74 77 private static final SString PERSISTENT = 78 new SString(Identifiers.PERSISTENT); 79 80 83 private static final SString NON_PERSISTENT = 84 new SString(Identifiers.NON_PERSISTENT); 85 86 87 94 public Identifier(final String name) throws SelectorException { 95 _name = name; 96 97 if (Identifiers.isJMSIdentifier(_name)) { 98 if (!Identifiers.isQueryableJMSIdentifier(_name)) { 99 throw new SelectorException("Invalid header field: " + _name); 100 } 101 _headerField = true; 102 } else { 103 _headerField = false; 104 } 105 } 106 107 115 public final SObject evaluate(final Message msg) { 116 SObject value = null; 117 try { 118 if (_headerField) { 119 if (_name.equals(Identifiers.JMS_DELIVERY_MODE)) { 120 value = deliveryMode(msg.getJMSDeliveryMode()); 121 } else if (_name.equals(Identifiers.JMS_PRIORITY)) { 122 value = new SLong(msg.getJMSPriority()); 123 } else if (_name.equals(Identifiers.JMS_TIMESTAMP)) { 124 value = new SLong(msg.getJMSTimestamp()); 125 } else if (_name.equals(Identifiers.JMS_MESSAGE_ID)) { 126 String id = msg.getJMSMessageID(); 127 if (id != null) { 128 value = new SString(id); 129 } 130 } else if (_name.equals(Identifiers.JMS_CORRELATION_ID)) { 131 String id = msg.getJMSCorrelationID(); 132 if (id != null) { 133 value = new SString(id); 134 } 135 } else if (_name.equals(Identifiers.JMS_TYPE)) { 136 String type = msg.getJMSType(); 137 if (type != null) { 138 value = new SString(type); 139 } 140 } 141 } else { 142 value = SObjectFactory.create(msg.getObjectProperty(_name)); 143 } 144 } catch (JMSException ignore) { 145 } 147 return value; 148 } 149 150 155 public final String toString() { 156 return _name; 157 } 158 159 167 private SString deliveryMode(final int mode) { 168 SString result = PERSISTENT; 169 if (mode == DeliveryMode.NON_PERSISTENT) { 170 result = NON_PERSISTENT; 171 } 172 return result; 173 } 174 175 } 176 | Popular Tags |