KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jms > selector > SpecialIdentifierSelector


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jms.selector;
30
31 import javax.jms.DeliveryMode JavaDoc;
32 import javax.jms.JMSException JavaDoc;
33 import javax.jms.Message JavaDoc;
34
35 /**
36  * The selector to grab a property.
37  */

38 public class SpecialIdentifierSelector extends Selector {
39   final static int JMS_DELIVERY_MODE = 1;
40   final static int JMS_PRIORITY = 2;
41   final static int JMS_MESSAGE_ID = 3;
42   final static int JMS_TIMESTAMP = 4;
43   final static int JMS_CORRELATION_ID = 5;
44   final static int JMS_TYPE = 6;
45   
46   private int _type;
47
48   SpecialIdentifierSelector(int type)
49   {
50     _type = type;
51   }
52
53   /**
54    * Returns false, since it's a known type.
55    */

56   boolean isUnknown()
57   {
58     return false;
59   }
60
61   /**
62    * Returns true for the numeric values.
63    */

64   boolean isNumber()
65   {
66     switch (_type) {
67     case JMS_PRIORITY:
68     case JMS_TIMESTAMP:
69       return true;
70     default:
71       return false;
72     }
73   }
74
75   /**
76    * Returns true for the string values.
77    */

78   boolean isString()
79   {
80     switch (_type) {
81     case JMS_MESSAGE_ID:
82     case JMS_CORRELATION_ID:
83     case JMS_TYPE:
84     case JMS_DELIVERY_MODE:
85       return true;
86     default:
87       return false;
88     }
89   }
90
91   /**
92    * Evaluate the message. The boolean literal selector returns
93    * the value of the boolean.
94    */

95   Object JavaDoc evaluate(Message JavaDoc message)
96     throws JMSException JavaDoc
97   {
98     switch (_type) {
99     case JMS_DELIVERY_MODE:
100       if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT)
101     return "PERSISTENT";
102       else
103     return "NON_PERSISTENT";
104     case JMS_PRIORITY:
105       return new Integer JavaDoc(message.getJMSPriority());
106     case JMS_MESSAGE_ID:
107       return message.getJMSMessageID();
108     case JMS_TIMESTAMP:
109       return new Long JavaDoc(message.getJMSTimestamp());
110     case JMS_CORRELATION_ID:
111       return message.getJMSCorrelationID();
112     case JMS_TYPE:
113       return message.getJMSType();
114     default:
115       throw new UnsupportedOperationException JavaDoc();
116     }
117   }
118
119   public String JavaDoc toString()
120   {
121     switch (_type) {
122     case JMS_DELIVERY_MODE:
123       return "JMSDeliveryMode";
124     case JMS_PRIORITY:
125       return "JMSPriority";
126     case JMS_MESSAGE_ID:
127       return "JMSMessageID";
128     case JMS_TIMESTAMP:
129       return "JMSTimestamp";
130     case JMS_CORRELATION_ID:
131       return "JMSCorrelationID";
132     case JMS_TYPE:
133       return "JMSType";
134     default:
135       return "Special[" + _type + "]";
136     }
137   }
138 }
139
Popular Tags