1 21 package com.presumo.jms.client; 22 23 import javax.jms.InvalidDestinationException ; 24 import javax.jms.JMSException ; 25 import javax.jms.Message ; 26 import javax.jms.Topic ; 27 28 29 33 public final class JmsTopic extends JmsDestination 34 implements Topic , java.io.Serializable 35 { 36 37 public static final String TOPIC_PREFIX = "topic:"; 38 39 private final String topicName; 40 41 45 48 public JmsTopic(String topicName) throws JMSException 49 { 50 if (topicName == null) throw new 51 InvalidDestinationException ("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 64 public String toString() 65 { 66 return topicName; 67 } 68 69 public String getTopicName() 70 { 71 return topicName; 72 } 73 74 77 public String prepareContentFilter(String filter) 78 { 79 StringBuffer buffer = new StringBuffer (); 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 |