You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by de...@apache.org on 2011/08/26 13:58:03 UTC

svn commit: r1162073 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command: ActiveMQDestination.java DefaultUnresolvedDestinationTransformer.java UnresolvedDestinationTransformer.java

Author: dejanb
Date: Fri Aug 26 11:58:02 2011
New Revision: 1162073

URL: http://svn.apache.org/viewvc?rev=1162073&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3401 - pluggable unresolved destination trnasformer

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DefaultUnresolvedDestinationTransformer.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/UnresolvedDestinationTransformer.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java?rev=1162073&r1=1162072&r2=1162073&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java Fri Aug 26 11:58:02 2011
@@ -71,6 +71,8 @@ public abstract class ActiveMQDestinatio
     protected transient boolean isPattern;
     protected transient int hashValue;
     protected Map<String, String> options;
+
+    protected static UnresolvedDestinationTransformer unresolvableDestinationTransformer = new DefaultUnresolvedDestinationTransformer();
     
     public ActiveMQDestination() {
     }
@@ -127,8 +129,9 @@ public abstract class ActiveMQDestinatio
                 return new ActiveMQQueue(queueName);
             } else if (queueName == null && topicName != null) {
                 return new ActiveMQTopic(topicName);
+            } else {
+                return unresolvableDestinationTransformer.transform(dest);
             }
-            throw new JMSException("Could no disambiguate on queue|Topic-name totransform pollymorphic destination into a ActiveMQ destination: " + dest);
         }
         if (dest instanceof TemporaryQueue) {
             return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName());
@@ -379,4 +382,12 @@ public abstract class ActiveMQDestinatio
     public boolean isPattern() {
         return isPattern;
     }
+
+    public static UnresolvedDestinationTransformer getUnresolvableDestinationTransformer() {
+        return unresolvableDestinationTransformer;
+    }
+
+    public static void setUnresolvableDestinationTransformer(UnresolvedDestinationTransformer unresolvableDestinationTransformer) {
+        ActiveMQDestination.unresolvableDestinationTransformer = unresolvableDestinationTransformer;
+    }
 }

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DefaultUnresolvedDestinationTransformer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DefaultUnresolvedDestinationTransformer.java?rev=1162073&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DefaultUnresolvedDestinationTransformer.java (added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DefaultUnresolvedDestinationTransformer.java Fri Aug 26 11:58:02 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.activemq.command;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import java.lang.reflect.Method;
+
+public class DefaultUnresolvedDestinationTransformer implements UnresolvedDestinationTransformer {
+
+    @Override
+    public ActiveMQDestination transform(Destination dest) throws JMSException {
+        String queueName = ((Queue) dest).getQueueName();
+        String topicName = ((Topic) dest).getTopicName();
+
+        if (queueName == null && topicName == null) {
+            throw new JMSException("Unresolvable destination: Both queue and topic names are null: " + dest);
+        }
+        try {
+            Method isQueueMethod = dest.getClass().getMethod("isQueue");
+            Method isTopicMethod = dest.getClass().getMethod("isTopic");
+            Boolean isQueue = (Boolean) isQueueMethod.invoke(dest);
+            Boolean isTopic = (Boolean) isTopicMethod.invoke(dest);
+            if (isQueue) {
+                return new ActiveMQQueue(queueName);
+            } else if (isTopic) {
+                return new ActiveMQTopic(topicName);
+            } else {
+                throw new JMSException("Unresolvable destination: Neither Queue nor Topic: " + dest);
+            }
+        } catch (Exception e)  {
+            throw new JMSException("Unresolvable destination: "  + e.getMessage() + ": " + dest);
+        }
+    }
+}

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/UnresolvedDestinationTransformer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/UnresolvedDestinationTransformer.java?rev=1162073&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/UnresolvedDestinationTransformer.java (added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/UnresolvedDestinationTransformer.java Fri Aug 26 11:58:02 2011
@@ -0,0 +1,26 @@
+/**
+ * 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.activemq.command;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+
+public interface UnresolvedDestinationTransformer {
+
+    public ActiveMQDestination transform(Destination dest) throws JMSException;
+
+}