KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > client > JmsTopic


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.client;
22
23 import javax.jms.InvalidDestinationException JavaDoc;
24 import javax.jms.JMSException JavaDoc;
25 import javax.jms.Message JavaDoc;
26 import javax.jms.Topic JavaDoc;
27
28
29 /**
30  * @see javax.jms.Topic
31  * @author Dan Greff
32  */

33 public final class JmsTopic extends JmsDestination
34     implements Topic JavaDoc, java.io.Serializable JavaDoc
35 {
36
37   public static final String JavaDoc TOPIC_PREFIX = "topic:";
38   
39   private final String JavaDoc topicName;
40   
41     /////////////////////////////////////////////////////////////////////////
42
// Constructors //
43
/////////////////////////////////////////////////////////////////////////
44

45   /**
46    * Initialize the object with the given topic name.
47    */

48   public JmsTopic(String JavaDoc topicName) throws JMSException JavaDoc
49   {
50     if (topicName == null) throw new
51       InvalidDestinationException JavaDoc("Can not create a null destination");
52   
53     if (topicName.startsWith(TOPIC_PREFIX))
54       this.topicName = topicName;
55     else
56       this.topicName = TOPIC_PREFIX + topicName;
57   }
58     
59
60     /////////////////////////////////////////////////////////////////////////
61
// Public Methods //
62
/////////////////////////////////////////////////////////////////////////
63

64   public String JavaDoc toString()
65   {
66     return topicName;
67   }
68   
69   public String JavaDoc getTopicName()
70   {
71     return topicName;
72   }
73
74   /**
75    * @secret
76    */

77   public String JavaDoc prepareContentFilter(String JavaDoc filter)
78   {
79     // Creates a filter of the format like
80
//
81
// ( <user filter> ) AND ( JMSX_DESTINATION LIKE 'myTopic' )
82
//
83
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
84     
85     if (filter != null && filter.length() != 0) {
86       buffer.append('(');
87       buffer.append(filter);
88       buffer.append(") AND");
89     }
90     
91     buffer.append(" ( ");
92     
93     buffer.append(JmsDestination.DESTINATION_PROPERTY_NAME);
94     buffer.append(" LIKE \'");
95     
96     int size = topicName.length();
97     for (int i=0; i < size; i++) {
98       char c = topicName.charAt(i);
99       if (c == '#' || c == '_' || c == '%') {
100         buffer.append('#');
101         buffer.append(c);
102       }
103       else if (c == '*') {
104         buffer.append('%');
105       } else {
106         buffer.append(c);
107       }
108     }
109     
110     buffer.append("\' ESCAPE \'#\' )");
111     
112     return buffer.toString();
113   }
114
115 }
116
Popular Tags