org.exolab.jms.client
Class JmsTopic

java.lang.Object
  |
  +--org.exolab.jms.message.DestinationImpl
        |
        +--org.exolab.jms.client.JmsDestination
              |
              +--org.exolab.jms.client.JmsTopic
All Implemented Interfaces:
java.lang.Cloneable, javax.jms.Destination, java.io.Externalizable, javax.naming.Referenceable, java.io.Serializable, javax.jms.Topic
Direct Known Subclasses:
JmsTemporaryTopic

public class JmsTopic
extends JmsDestination
implements javax.jms.Topic, java.io.Externalizable, javax.naming.Referenceable

A topic is a destination specific for the puiblish-subscribe messaging model. OpenJMS also supports topic hierarchy and wild carding.

Version:
$Revision: 1.12 $ $Date: 2003/08/07 13:32:50 $
Author:
Jim Alateras, Jim Mourikis
See Also:
JmsDestination, Serialized Form

Field Summary
static java.lang.String ALL_WILDCARD
           
static java.lang.String SEPARATOR
           
static java.lang.String WILDCARD
           
 
Constructor Summary
JmsTopic()
          Need a default constructor for the serialization
JmsTopic(java.lang.String name)
          Instantiate an instance of this object with the specified string
 
Method Summary
 boolean equals(java.lang.Object object)
           
 javax.naming.Reference getReference()
           
 java.lang.String getTopicName()
          Return the name of the topic
 int hashCode()
           
 boolean isWildCard()
          Check whether this topic represents a wildcard expression.
static boolean isWildCard(java.lang.String topic)
          A static method which checks a topic to determine whether or not it complies to a wildcard definition.
 boolean match(JmsTopic destination)
          If it is a wildcard check to see that it matches the specified topic.
 void readExternal(java.io.ObjectInput stream)
           
 void writeExternal(java.io.ObjectOutput stream)
           
 
Methods inherited from class org.exolab.jms.client.JmsDestination
getName, getPersistent, isTemporaryDestination, isTemporaryDestination, setPersistent, toString
 
Methods inherited from class org.exolab.jms.message.DestinationImpl
clone, getDestination, isEqual
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.jms.Topic
toString
 

Field Detail

WILDCARD

public static final java.lang.String WILDCARD

ALL_WILDCARD

public static final java.lang.String ALL_WILDCARD

SEPARATOR

public static final java.lang.String SEPARATOR
Constructor Detail

JmsTopic

public JmsTopic()
Need a default constructor for the serialization

JmsTopic

public JmsTopic(java.lang.String name)
Instantiate an instance of this object with the specified string
Parameters:
name - name of the queue
Method Detail

getTopicName

public java.lang.String getTopicName()
                              throws javax.jms.JMSException
Return the name of the topic
Specified by:
getTopicName in interface javax.jms.Topic
Returns:
name name of the topic
Throws:
javax.jms.JMSException -  

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

writeExternal

public void writeExternal(java.io.ObjectOutput stream)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class JmsDestination

readExternal

public void readExternal(java.io.ObjectInput stream)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class JmsDestination

hashCode

public int hashCode()
Overrides:
hashCode in class JmsDestination

isWildCard

public boolean isWildCard()
Check whether this topic represents a wildcard expression.
Returns:
boolean true if the topic contains wildcards

isWildCard

public static boolean isWildCard(java.lang.String topic)
A static method which checks a topic to determine whether or not it complies to a wildcard definition.
Parameters:
topic - - the topic to check
Returns:
boolean - true if it does

match

public boolean match(JmsTopic destination)
If it is a wildcard check to see that it matches the specified topic. if wildcard is **, its a an imediate match for every topic. else tokenize both the wildcard and the topic. if the wildcard has less or equal no of tokens than the topic and ends in "**" check tokens if both wildcard and topic contain the same no of tokens check tokens Otherwise topic and wildcard do not match so return false.

Note we treat "a.b.c.*.*" and "a.b.c" as not a match at this stage, since the wildcard is attempting to match more levels than exist in the topic. if this proves to be unpopular with the masses, its a very trivial change below to fix this problem.

Tokens are compared and must either be identical or the wildcard token must be a "*" to match at this level. Once a mismatch is detected the comparison is stopped and a false returned.

NOTE: This check assumes both the topic and wildcard topic have both already been validated. if the topics are inavlid this test can return arbitrary results.

Parameters:
destination - The specific topic to match to
Returns:
True if the wildcard matches.

getReference

public javax.naming.Reference getReference()
Specified by:
getReference in interface javax.naming.Referenceable


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.