Author: rajith
Date: Mon Mar 5 18:49:32 2012
New Revision: 1297165
URL: http://svn.apache.org/viewvc?rev=1297165&view=rev
Log:
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.
Added:
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
Added:
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
URL:
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java?rev=1297165&view=auto
==============================================================================
---
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
(added)
+++
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
Mon Mar 5 18:49:32 2012
@@ -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;
+ }
+ }
+}
Added:
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
URL:
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java?rev=1297165&view=auto
==============================================================================
---
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
(added)
+++
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
Mon Mar 5 18:49:32 2012
@@ -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();
+ }
+
+}
Added:
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
URL:
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java?rev=1297165&view=auto
==============================================================================
---
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
(added)
+++
qpid/branches/address-refactor2/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
Mon Mar 5 18:49:32 2012
@@ -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();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]