001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jms.selector;
030:
031: import javax.jms.DeliveryMode;
032: import javax.jms.JMSException;
033: import javax.jms.Message;
034:
035: /**
036: * The selector to grab a property.
037: */
038: public class SpecialIdentifierSelector extends Selector {
039: final static int JMS_DELIVERY_MODE = 1;
040: final static int JMS_PRIORITY = 2;
041: final static int JMS_MESSAGE_ID = 3;
042: final static int JMS_TIMESTAMP = 4;
043: final static int JMS_CORRELATION_ID = 5;
044: final static int JMS_TYPE = 6;
045:
046: private int _type;
047:
048: SpecialIdentifierSelector(int type) {
049: _type = type;
050: }
051:
052: /**
053: * Returns false, since it's a known type.
054: */
055: boolean isUnknown() {
056: return false;
057: }
058:
059: /**
060: * Returns true for the numeric values.
061: */
062: boolean isNumber() {
063: switch (_type) {
064: case JMS_PRIORITY:
065: case JMS_TIMESTAMP:
066: return true;
067: default:
068: return false;
069: }
070: }
071:
072: /**
073: * Returns true for the string values.
074: */
075: boolean isString() {
076: switch (_type) {
077: case JMS_MESSAGE_ID:
078: case JMS_CORRELATION_ID:
079: case JMS_TYPE:
080: case JMS_DELIVERY_MODE:
081: return true;
082: default:
083: return false;
084: }
085: }
086:
087: /**
088: * Evaluate the message. The boolean literal selector returns
089: * the value of the boolean.
090: */
091: Object evaluate(Message message) throws JMSException {
092: switch (_type) {
093: case JMS_DELIVERY_MODE:
094: if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT)
095: return "PERSISTENT";
096: else
097: return "NON_PERSISTENT";
098: case JMS_PRIORITY:
099: return new Integer(message.getJMSPriority());
100: case JMS_MESSAGE_ID:
101: return message.getJMSMessageID();
102: case JMS_TIMESTAMP:
103: return new Long(message.getJMSTimestamp());
104: case JMS_CORRELATION_ID:
105: return message.getJMSCorrelationID();
106: case JMS_TYPE:
107: return message.getJMSType();
108: default:
109: throw new UnsupportedOperationException();
110: }
111: }
112:
113: public String toString() {
114: switch (_type) {
115: case JMS_DELIVERY_MODE:
116: return "JMSDeliveryMode";
117: case JMS_PRIORITY:
118: return "JMSPriority";
119: case JMS_MESSAGE_ID:
120: return "JMSMessageID";
121: case JMS_TIMESTAMP:
122: return "JMSTimestamp";
123: case JMS_CORRELATION_ID:
124: return "JMSCorrelationID";
125: case JMS_TYPE:
126: return "JMSType";
127: default:
128: return "Special[" + _type + "]";
129: }
130: }
131: }
|