summaryrefslogtreecommitdiff
path: root/qpid/java/client/src
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2012-03-05 18:49:32 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2012-03-05 18:49:32 +0000
commitac24059c9f1987e3dea78bb2c1f3b1c23964e3d1 (patch)
tree25d6d80ebb1d57d4ea06a6f5dc23a67531b7e2c4 /qpid/java/client/src
parentec5d0392f542bacc61fac8b445b29f4e7f4659f6 (diff)
downloadqpid-python-ac24059c9f1987e3dea78bb2c1f3b1c23964e3d1.tar.gz
QPID-3401 Stubbing out Destination, Topic and Queue implementations.
The Destination objects would be immutable. The base class QpidDestination which implements javax.jms.Destination is an abstract class. QpidTopic and QpidQueue which implements the respective Topic and Queue interfaces provides a concrete implementation. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1297165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src')
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java165
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java39
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java40
3 files changed, 244 insertions, 0 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
new file mode 100644
index 0000000000..165a5cc0c6
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
@@ -0,0 +1,165 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.messaging.Address;
+import org.apache.qpid.messaging.address.AddressException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class QpidDestination implements Destination, Referenceable
+{
+ private static final Logger _logger = LoggerFactory.getLogger(QpidDestination.class);
+ private static final DestSyntax defaultDestSyntax;
+ private DestSyntax _destSyntax = DestSyntax.ADDR;
+
+ protected String destinationString;
+ protected Address address;
+
+ public String getDestinationString()
+ {
+ return destinationString;
+ }
+
+ public void setDestinationString(String str) throws JMSException
+ {
+ if (destinationString != null)
+ {
+ throw new javax.jms.IllegalStateException("Once an address string is set, it cannot be set again");
+ }
+ destinationString = str;
+ parseDestinationString(str);
+ }
+
+ protected void parseDestinationString(String str) throws JMSException
+ {
+ _destSyntax = getDestType(str);
+ str = stripSyntaxPrefix(str);
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Based on " + str + " the selected destination syntax is " + _destSyntax);
+ }
+
+ try
+ {
+ if (_destSyntax == DestSyntax.BURL)
+ {
+ address = DestinationStringParser.parseAddressString(str);
+ }
+ else
+ {
+ address = DestinationStringParser.parseBURLString(str);
+ }
+ }
+ catch (AddressException e)
+ {
+ JMSException ex = new JMSException("Error parsing destination string, due to : " + e.getMessage());
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ protected Address getAddress()
+ {
+ return address;
+ }
+
+ @Override
+ public Reference getReference() throws NamingException
+ {
+ return new Reference(
+ this.getClass().getName(),
+ new StringRefAddr(this.getClass().getName(), toString()),
+ AMQConnectionFactory.class.getName(),
+ null); // factory location
+ }
+
+
+ // ------- utility methods -------
+
+ static
+ {
+ defaultDestSyntax = DestSyntax.getSyntaxType(
+ System.getProperty(ClientProperties.DEST_SYNTAX,
+ DestSyntax.ADDR.toString()));
+ }
+
+ public enum DestSyntax
+ {
+ BURL,ADDR;
+
+ public static DestSyntax getSyntaxType(String s)
+ {
+ if (("BURL").equals(s))
+ {
+ return BURL;
+ }
+ else if (("ADDR").equals(s))
+ {
+ return ADDR;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid Destination Syntax Type" +
+ " should be one of {BURL|ADDR}");
+ }
+ }
+ }
+
+ public static DestSyntax getDestType(String str)
+ {
+ if (str.startsWith("ADDR:"))
+ {
+ return DestSyntax.ADDR;
+ }
+ else if (str.startsWith("BURL:"))
+ {
+ return DestSyntax.BURL;
+ }
+ else
+ {
+ return defaultDestSyntax;
+ }
+ }
+
+ public static String stripSyntaxPrefix(String str)
+ {
+ if (str.startsWith("BURL:") || str.startsWith("ADDR:"))
+ {
+ return str.substring(5,str.length());
+ }
+ else
+ {
+ return str;
+ }
+ }
+}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
new file mode 100644
index 0000000000..199b53d2ae
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
@@ -0,0 +1,39 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+
+public class QpidQueue extends QpidDestination implements Queue
+{
+ public QpidQueue(String str) throws JMSException
+ {
+ setDestinationString(str);
+ }
+
+ @Override
+ public String getQueueName() throws JMSException
+ {
+ return address.getName();
+ }
+
+}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
new file mode 100644
index 0000000000..d37add363e
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Topic;
+
+public class QpidTopic extends QpidDestination implements Topic
+{
+
+ public QpidTopic(String str) throws JMSException
+ {
+ setDestinationString(str);
+ }
+
+ @Override
+ public String getTopicName() throws JMSException
+ {
+ return address.getSubject() == null ? "" : address.getSubject();
+ }
+
+}