01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.jms.serverless;
23:
24: import org.jboss.logging.Logger;
25: import javax.jms.Topic;
26: import javax.jms.JMSException;
27: import javax.jms.Destination;
28:
29: /**
30: * Collection of utilites to parse Destination names and generate Destination instances.
31: *
32: * @author Ovidiu Feodorov <ovidiu@jboss.org>
33: * @version $Revision: 57195 $ $Date: 2006-09-26 08:08:17 -0400 (Tue, 26 Sep 2006) $
34: *
35: **/
36: public class Destinations {
37:
38: private Destinations() {
39: }
40:
41: /**
42: * The method expects to get the string representation of a GroupTopic or GroupQueue and
43: * attempts to parse it and create the corresponding destination instance. A parsing error
44: * generates a JMSException.
45: *
46: * @param s - the string representation of a Destination.
47: *
48: * TO_DO: doesn't handle null names consistently
49: **/
50: public static Destination createDestination(String s)
51: throws JMSException {
52:
53: // TO_DO: add test cases
54:
55: if (s == null) {
56: throw new JMSException(
57: "null destination string representation");
58: }
59:
60: if (s.startsWith("GroupTopic[") && s.endsWith("]")) {
61: String name = s.substring("GroupTopic[".length(), s
62: .length() - 1);
63: return new GroupTopic(name);
64: } else if (s.startsWith("GroupQueue[") && s.endsWith("]")) {
65: String name = s.substring("GroupQueue[".length(), s
66: .length() - 1);
67: return new GroupQueue(name);
68: }
69: throw new JMSException(
70: "invalid destination string representation: " + s);
71:
72: }
73:
74: /**
75: * TO_DO: doesn't handle null names consistently
76: * @exception JMSException - if handling the destination throws exception.
77: **/
78: public static String stringRepresentation(Destination d)
79: throws JMSException {
80:
81: if (d instanceof GroupTopic) {
82: String name = ((GroupTopic) d).getTopicName();
83: return "GroupTopic[" + name + "]";
84: } else if (d instanceof GroupQueue) {
85: String name = ((GroupQueue) d).getQueueName();
86: return "GroupQueue[" + name + "]";
87: }
88: throw new JMSException("Unsupported destination: " + d);
89: }
90:
91: }
|