summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2012-03-05 18:49:59 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2012-03-05 18:49:59 +0000
commitb47573c60286a50a9fe6b8b02e028d53d321538d (patch)
tree7c29d8948923da1f98834d9a85d141a7c18cfc86
parented8d1322211f717eb38b6d769caeb964523fea97 (diff)
downloadqpid-python-b47573c60286a50a9fe6b8b02e028d53d321538d.tar.gz
QPID-3401 Added a final field "type" to abstract destination
implementation, which will be used by the common methods in the abstract implementation to make decisions based on the type. Added the DestinationStringParser which will parse an Address string or a BURL string and populate an Address data structure. Added an AddressHelper class to extract information from the address string. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1297167 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java87
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java28
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java11
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java11
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java143
5 files changed, 265 insertions, 15 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
new file mode 100644
index 0000000000..c4c6f1f7e3
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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 java.net.URISyntaxException;
+import java.util.Collections;
+
+import org.apache.qpid.jms.QpidDestination.Type;
+import org.apache.qpid.messaging.Address;
+import org.apache.qpid.messaging.address.AddressException;
+import org.apache.qpid.messaging.address.Node;
+import org.apache.qpid.messaging.address.Node.AddressPolicy;
+import org.apache.qpid.messaging.util.AddressHelper;
+import org.apache.qpid.url.AMQBindingURL;
+
+public class DestinationStringParser
+{
+ public static Address parseAddressString(String str, Type type) throws AddressException
+ {
+ Address addr = Address.parse(str);
+ AddressHelper helper = new AddressHelper(addr);
+ Node node = new Node();
+ node.setAssertPolicy(AddressPolicy.getAddressPolicy(helper.getAssert()));
+ node.setCreatePolicy(AddressPolicy.getAddressPolicy(helper.getCreate()));
+ node.setDeletePolicy(AddressPolicy.getAddressPolicy(helper.getDelete()));
+
+ return addr;
+ }
+
+ public static Address parseBURLString(String str, Type type) throws AddressException
+ {
+ AMQBindingURL burl;
+ try
+ {
+ burl = new AMQBindingURL(str);
+ }
+ catch(URISyntaxException e)
+ {
+ AddressException ex = new AddressException("Error parsing BURL : " + e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+
+ Address addr;
+ if (type == Type.TOPIC)
+ {
+ addr = new Address(burl.getExchangeName().asString(),
+ burl.getRoutingKey().asString(),
+ Collections.EMPTY_MAP);
+
+ // use the queue name to add x-subscribe props.
+ }
+ else
+ {
+ addr = new Address(burl.getQueueName().asString(),
+ burl.getRoutingKey().asString(),
+ Collections.EMPTY_MAP);
+
+ // use the exchange and binding key to add a binding
+ }
+
+ Node node = new Node();
+ node.setAssertPolicy(AddressPolicy.NEVER);
+ node.setCreatePolicy(AddressPolicy.RECEIVER);
+ node.setDeletePolicy(AddressPolicy.NEVER);
+
+ return addr;
+ }
+}
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
index 165a5cc0c6..5166cce59a 100644
--- 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
@@ -36,47 +36,55 @@ import org.slf4j.LoggerFactory;
public abstract class QpidDestination implements Destination, Referenceable
{
+ public enum Type {QUEUE, TOPIC};
+
private static final Logger _logger = LoggerFactory.getLogger(QpidDestination.class);
private static final DestSyntax defaultDestSyntax;
private DestSyntax _destSyntax = DestSyntax.ADDR;
-
+
+ protected final Type type;
protected String destinationString;
protected Address address;
+ protected QpidDestination(Type type)
+ {
+ this.type = type;
+ }
+
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");
+ throw new javax.jms.IllegalStateException("Once a destination string is set, it cannot be changed");
}
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);
+ address = DestinationStringParser.parseAddressString(str,type);
}
else
{
- address = DestinationStringParser.parseBURLString(str);
+ address = DestinationStringParser.parseBURLString(str,type);
}
}
catch (AddressException e)
@@ -85,9 +93,9 @@ public abstract class QpidDestination implements Destination, Referenceable
ex.initCause(e);
ex.setLinkedException(e);
throw ex;
- }
+ }
}
-
+
protected Address getAddress()
{
return address;
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
index 199b53d2ae..18dafffd37 100644
--- 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
@@ -25,15 +25,20 @@ import javax.jms.Queue;
public class QpidQueue extends QpidDestination implements Queue
{
+ public QpidQueue()
+ {
+ super(Type.QUEUE);
+ }
+
public QpidQueue(String str) throws JMSException
{
- setDestinationString(str);
+ super(Type.QUEUE);
+ setDestinationString(str);
}
@Override
public String getQueueName() throws JMSException
{
- return address.getName();
+ 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
index d37add363e..6d34303fa2 100644
--- 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
@@ -23,18 +23,25 @@ package org.apache.qpid.jms;
import javax.jms.JMSException;
import javax.jms.Topic;
+import org.apache.qpid.jms.QpidDestination.Type;
+
public class QpidTopic extends QpidDestination implements Topic
{
+ public QpidTopic()
+ {
+ super(Type.TOPIC);
+ }
public QpidTopic(String str) throws JMSException
{
+ super(Type.TOPIC);
setDestinationString(str);
}
-
+
@Override
public String getTopicName() throws JMSException
{
- return address.getSubject() == null ? "" : address.getSubject();
+ return address.getSubject() == null ? "" : address.getSubject();
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java
new file mode 100644
index 0000000000..05cab69118
--- /dev/null
+++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java
@@ -0,0 +1,143 @@
+/*
+*
+* 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.messaging.util;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.configuration.Accessor;
+import org.apache.qpid.configuration.Accessor.MapAccessor;
+import org.apache.qpid.messaging.Address;
+
+/**
+* Utility class for extracting information from the address class
+*/
+public class AddressHelper
+{
+ public static final String NODE = "node";
+ public static final String LINK = "link";
+ public static final String X_DECLARE = "x-declare";
+ public static final String X_BINDINGS = "x-bindings";
+ public static final String X_SUBSCRIBE = "x-subscribes";
+ public static final String CREATE = "create";
+ public static final String ASSERT = "assert";
+ public static final String DELETE = "delete";
+ public static final String FILTER = "filter";
+ public static final String NO_LOCAL = "no-local";
+ public static final String DURABLE = "durable";
+ public static final String EXCLUSIVE = "exclusive";
+ public static final String AUTO_DELETE = "auto-delete";
+ public static final String TYPE = "type";
+ public static final String ALT_EXCHANGE = "alternate-exchange";
+ public static final String BINDINGS = "bindings";
+ public static final String BROWSE = "browse";
+ public static final String MODE = "mode";
+ public static final String CAPACITY = "capacity";
+ public static final String CAPACITY_SOURCE = "source";
+ public static final String CAPACITY_TARGET = "target";
+ public static final String NAME = "name";
+ public static final String EXCHANGE = "exchange";
+ public static final String QUEUE = "queue";
+ public static final String KEY = "key";
+ public static final String ARGUMENTS = "arguments";
+ public static final String RELIABILITY = "reliability";
+
+ private Address address;
+ private MapAccessor addressProps;
+ private MapAccessor nodeProps;
+ private MapAccessor linkProps;
+
+ public AddressHelper(Address address)
+ {
+ this.address = address;
+ addressProps = new MapAccessor(address.getOptions());
+ Map node_props = address.getOptions() == null
+ || address.getOptions().get(NODE) == null ? null
+ : (Map) address.getOptions().get(NODE);
+
+ if (node_props != null)
+ {
+ nodeProps = new MapAccessor(node_props);
+ }
+
+ Map link_props = address.getOptions() == null
+ || address.getOptions().get(LINK) == null ? null
+ : (Map) address.getOptions().get(LINK);
+
+ if (link_props != null)
+ {
+ linkProps = new MapAccessor(link_props);
+ }
+ }
+
+ public String getCreate()
+ {
+ return addressProps.getString(CREATE);
+ }
+
+ public String getAssert()
+ {
+ return addressProps.getString(ASSERT);
+ }
+
+ public String getDelete()
+ {
+ return addressProps.getString(DELETE);
+ }
+
+ public boolean isNodeMarkedNoLocal()
+ {
+ Boolean b = nodeProps.getBoolean(NO_LOCAL);
+ return b == null ? false : b;
+ }
+
+ public boolean isBrowseOnly()
+ {
+ String mode = addressProps.getString(MODE);
+ return mode != null && mode.equals(BROWSE) ? true : false;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Object> getNodeBindings()
+ {
+ return (List<Object>) nodeProps.getList(X_BINDINGS);
+ }
+
+ public Map getDeclareArgs(Map props)
+ {
+ if (props != null && props.get(X_DECLARE) != null)
+ {
+ return (Map) props.get(X_DECLARE);
+ }
+ else
+ {
+ return Collections.EMPTY_MAP;
+ }
+ }
+
+ private boolean getDurability(Map map)
+ {
+ Accessor access = new MapAccessor(map);
+ Boolean result = access.getBoolean(DURABLE);
+ return (result == null) ? false : result.booleanValue();
+ }
+}