KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > serverless > Destinations


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.serverless;
8
9 import org.jboss.logging.Logger;
10 import javax.jms.Topic JavaDoc;
11 import javax.jms.JMSException JavaDoc;
12 import javax.jms.Destination JavaDoc;
13
14 /**
15  * Collection of utilites to parse Destination names and generate Destination instances.
16  *
17  * @author Ovidiu Feodorov <ovidiu@jboss.org>
18  * @version $Revision: 1.1 $ $Date: 2004/04/15 22:54:19 $
19  *
20  **/

21 public class Destinations {
22
23     private Destinations() {
24     }
25
26     /**
27      * The method expects to get the string representation of a GroupTopic or GroupQueue and
28      * attempts to parse it and create the corresponding destination instance. A parsing error
29      * generates a JMSException.
30      *
31      * @param s - the string representation of a Destination.
32      *
33      * TO_DO: doesn't handle null names consistently
34      **/

35     public static Destination JavaDoc createDestination(String JavaDoc s) throws JMSException JavaDoc {
36
37         // TO_DO: add test cases
38

39         if (s == null) {
40             throw new JMSException JavaDoc("null destination string representation");
41         }
42
43         if (s.startsWith("GroupTopic[") && s.endsWith("]")) {
44             String JavaDoc name = s.substring("GroupTopic[".length(), s.length() - 1);
45             return new GroupTopic(name);
46         }
47         else if (s.startsWith("GroupQueue[") && s.endsWith("]")) {
48             String JavaDoc name = s.substring("GroupQueue[".length(), s.length() - 1);
49             return new GroupQueue(name);
50         }
51         throw new JMSException JavaDoc("invalid destination string representation: "+s);
52
53     }
54
55     /**
56      * TO_DO: doesn't handle null names consistently
57      * @exception JMSException - if handling the destination throws exception.
58      **/

59     public static String JavaDoc stringRepresentation(Destination JavaDoc d) throws JMSException JavaDoc {
60
61         if (d instanceof GroupTopic) {
62             String JavaDoc name = ((GroupTopic)d).getTopicName();
63             return "GroupTopic["+name+"]";
64         }
65         else if (d instanceof GroupQueue) {
66             String JavaDoc name = ((GroupQueue)d).getQueueName();
67             return "GroupQueue["+name+"]";
68         }
69         throw new JMSException JavaDoc("Unsupported destination: "+d);
70     }
71
72 }
73
Popular Tags