View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: JmsDestination.java,v 1.1 2004/11/26 01:50:40 tanderson Exp $
44   *
45   * Date         Author  Changes
46   * 3/21/2000    jima    Created
47   */
48  package org.exolab.jms.client;
49  
50  
51  import java.io.Externalizable;
52  import java.io.IOException;
53  import java.io.ObjectInput;
54  import java.io.ObjectOutput;
55  
56  import javax.jms.Destination;
57  import javax.jms.JMSException;
58  import javax.naming.Referenceable;
59  
60  import org.exolab.jms.message.DestinationImpl;
61  
62  
63  /***
64   * This is the base class for all destinations.
65   *
66   * @version     $Revision: 1.1 $ $Date: 2004/11/26 01:50:40 $
67   * @author      <a href="mailto:jima@exoffice.com">Jim Alateras</a>
68   */
69  abstract public class JmsDestination
70      extends DestinationImpl
71      implements Destination, Externalizable, Referenceable {
72  
73      /***
74       * Need a default constructor for the serialization
75       */
76      public JmsDestination() {
77      }
78  
79      /***
80       * Instantiate an instance of this object with the specified string
81       *
82       * @param       name            name of the destination
83       */
84      protected JmsDestination(String name) {
85          super(name);
86      }
87  
88      /***
89       * Return the name of the destination
90       *
91       * @return      String
92       */
93      public String getName() {
94          return getDestination();
95      }
96  
97      /***
98       * Determine whether the destination is persistent or not
99       *
100      * @param       flag            true for persistent
101      */
102     public void setPersistent(boolean flag) {
103         persistent_ = flag;
104     }
105 
106     /***
107      * Return the persistent state of this destination
108      *
109      * @return      boolean
110      */
111     public boolean getPersistent() {
112         return persistent_;
113     }
114 
115     // implementation of Object.toString()
116     public String toString() {
117         return getDestination() + "-" + persistent_;
118     }
119 
120     // implementation of Object.hashCode
121     public int hashCode() {
122         return getName().hashCode();
123     }
124 
125     // implementation of Externalizable.writeExternal
126     public void writeExternal(ObjectOutput stream)
127         throws IOException {
128         stream.writeLong(serialVersionUID);
129         stream.writeBoolean(persistent_);
130         super.writeExternal(stream);
131     }
132 
133     // implementation of Externalizable.writeExternal
134     public void readExternal(ObjectInput stream)
135         throws IOException, ClassNotFoundException {
136         long version = stream.readLong();
137         if (version == serialVersionUID) {
138             persistent_ = stream.readBoolean();
139             super.readExternal(stream);
140         } else {
141             throw new IOException("JmsDestination with version " +
142                 version + " is not supported.");
143         }
144     }
145 
146     /***
147      * This static method determines whether a particular string
148      * refers to a temporary destination.
149      *
150      * @param       destination         destination to test
151      * @return      boolean             true if it is
152      */
153     public boolean isTemporaryDestination() {
154         boolean result = false;
155 
156         if ((getDestination().startsWith(TEMP_QUEUE_PREFIX)) ||
157             (getDestination().startsWith(TEMP_TOPIC_PREFIX))) {
158             result = true;
159         }
160 
161         return result;
162     }
163 
164     /***
165      * This static method determines whether a particular DestinationImpl
166      * instance refers to a temporary destination.
167      *
168      * @param       destination         destination to test
169      * @return      boolean             true if it is
170      */
171     public static boolean isTemporaryDestination(DestinationImpl destination) {
172         boolean result = false;
173 
174         if ((destination.getDestination().startsWith(TEMP_QUEUE_PREFIX)) ||
175             (destination.getDestination().startsWith(TEMP_TOPIC_PREFIX))) {
176             result = true;
177         }
178 
179         return result;
180     }
181 
182 
183     /***
184      * This flag determines whether or not the destination is persistent or
185      * not
186      */
187     private boolean persistent_ = false;
188 
189     /***
190      * This is the prefix used by the temporary queues
191      */
192     final static String TEMP_QUEUE_PREFIX = "tempqueue:";
193 
194     /***
195      * This is the prefix used by the temporary topics
196      */
197     final static String TEMP_TOPIC_PREFIX = "temptopic:";
198 
199     /***
200      * Used for serialization
201      */
202     static final long serialVersionUID = 1;
203 }
204