package org.jboss.jms.serverless;
import org.jboss.logging.Logger;
import javax.jms.Topic;
import javax.jms.JMSException;
import javax.jms.Destination;
public class Destinations {
private Destinations() {
}
public static Destination createDestination(String s) throws JMSException {
if (s == null) {
throw new JMSException("null destination string representation");
}
if (s.startsWith("GroupTopic[") && s.endsWith("]")) {
String name = s.substring("GroupTopic[".length(), s.length() - 1);
return new GroupTopic(name);
}
else if (s.startsWith("GroupQueue[") && s.endsWith("]")) {
String name = s.substring("GroupQueue[".length(), s.length() - 1);
return new GroupQueue(name);
}
throw new JMSException("invalid destination string representation: "+s);
}
public static String stringRepresentation(Destination d) throws JMSException {
if (d instanceof GroupTopic) {
String name = ((GroupTopic)d).getTopicName();
return "GroupTopic["+name+"]";
}
else if (d instanceof GroupQueue) {
String name = ((GroupQueue)d).getQueueName();
return "GroupQueue["+name+"]";
}
throw new JMSException("Unsupported destination: "+d);
}
}