Commit in servicemix/ws/jaxws/wsnotification/src on MAIN
main/java/org/servicemix/ws/notification/impl/invoke/InvokerSupport.java+11-21.1 -> 1.2
main/java/org/servicemix/ws/notification/impl/ActiveMQNotificationBroker.java+12-31.1 -> 1.2
                                             /ActiveMQPublisherRegistration.java+10-21.1 -> 1.2
                                             /ActiveMQSubscription.java+5-21.1 -> 1.2
                                             /TopicExpressionConverter.java+18-161.1 -> 1.2
test/java/org/servicemix/ws/notification/impl/ActiveMQNotificationBrokerTest.java+2-21.3 -> 1.4
                                             /TestSupport.java+14-61.1 -> 1.2
                                             /TopicExpressionConverterTest.java+4-21.1 -> 1.2
+76-35
8 modified files
refactor to make mapping of WS-N TopicExpressions to ActiveMQ topics easier - we may wanna do clever things mapping QNames to JMS destinations

servicemix/ws/jaxws/wsnotification/src/main/java/org/servicemix/ws/notification/impl/invoke
InvokerSupport.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- InvokerSupport.java	24 Aug 2005 14:45:59 -0000	1.1
+++ InvokerSupport.java	25 Aug 2005 17:35:17 -0000	1.2
@@ -31,11 +31,12 @@
 /**
  * A base class for a JMS consumer which is capable of dispatching messages to some WS endpoint.
  *
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  */
 public abstract class InvokerSupport implements MessageListener {
     private static final transient Log log = LogFactory.getLog(NotificationConsumerInvoker.class);
 
+    private TopicExpressionConverter topicConverter = new TopicExpressionConverter();
     private EndpointReferenceType producerReference;
 
     public void onMessage(Message msg) {
@@ -56,10 +57,18 @@
         this.producerReference = producerReference;
     }
 
+    public TopicExpressionConverter getTopicConverter() {
+        return topicConverter;
+    }
+
+    public void setTopicConverter(TopicExpressionConverter topicConverter) {
+        this.topicConverter = topicConverter;
+    }
+
     // Implementation methods
     //-------------------------------------------------------------------------
     protected TopicExpressionType extractTopic(Message msg) throws JMSException {
-        return TopicExpressionConverter.toTopicExpression((ActiveMQTopic) msg.getJMSDestination());
+        return topicConverter.toTopicExpression((ActiveMQTopic) msg.getJMSDestination());
     }
 
     protected abstract void dispatchMessage(TopicExpressionType topic, Message message) throws Exception;

servicemix/ws/jaxws/wsnotification/src/main/java/org/servicemix/ws/notification/impl
ActiveMQNotificationBroker.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ActiveMQNotificationBroker.java	24 Aug 2005 14:45:59 -0000	1.1
+++ ActiveMQNotificationBroker.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -49,6 +49,7 @@
 
     private ActiveMQPublisherRegistrationManager publisherManager = new ActiveMQPublisherRegistrationManager();
     private ActiveMQSubscriptionManager subscriptionManager = new ActiveMQSubscriptionManager();
+    private TopicExpressionConverter topicConverter = new TopicExpressionConverter();
 
     private ActiveMQConnectionFactory factory;
     private ActiveMQConnection connection;
@@ -96,6 +97,14 @@
         return subscriptionManager;
     }
 
+    public TopicExpressionConverter getTopicConverter() {
+        return topicConverter;
+    }
+
+    public void setTopicConverter(TopicExpressionConverter topicConverter) {
+        this.topicConverter = topicConverter;
+    }
+
     // NotificationBroker interface
     //-------------------------------------------------------------------------
 
@@ -108,7 +117,7 @@
 
         try {
             for (NotificationMessageHolderType messageHolder : list) {
-                Topic topic = TopicExpressionConverter.toActiveMQTopic(messageHolder.getTopic());
+                Topic topic = topicConverter.toActiveMQTopic(messageHolder.getTopic());
                 EndpointReferenceType producerReference = messageHolder.getProducerReference();
                 ActiveMQPublisherRegistration publisher = getPublisher(producerReference);
                 publisher.notify(topic, messageHolder.getMessage());
@@ -159,7 +168,7 @@
 
         try {
 
-            subscription = new ActiveMQSubscription(connection, consumerReference);
+            subscription = new ActiveMQSubscription(connection, consumerReference, topicConverter);
             subscription.setTopicExpression(topicExpression);
             subscription.setUseNotify(useNotify);
             subscription.setPrecondition(precondition);
@@ -202,7 +211,7 @@
             XMLGregorianCalendar terminationTime) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, ResourceUnknownFault, TopicNotSupportedFault {
 
         // Check request.
-        ActiveMQTopic topic = TopicExpressionConverter.toActiveMQTopic(list);
+        ActiveMQTopic topic = topicConverter.toActiveMQTopic(list);
 
         terminationTime = validateTerminationTime(terminationTime);
 

servicemix/ws/jaxws/wsnotification/src/main/java/org/servicemix/ws/notification/impl
ActiveMQPublisherRegistration.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ActiveMQPublisherRegistration.java	24 Aug 2005 14:45:59 -0000	1.1
+++ ActiveMQPublisherRegistration.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -55,11 +55,12 @@
 
     private static final transient Log log = LogFactory.getLog(ActiveMQPublisherRegistration.class);
 
+    private final ActiveMQConnection connection;
+    private TopicExpressionConverter topicConverter = new TopicExpressionConverter();
     private boolean demand = true;
     private EndpointReferenceType endpointReference;
     private EndpointReferenceType publisherReference;
     private Topic topic;
-    private final ActiveMQConnection connection;
     private ProducerDemandAdvisor advisor;
     private Boolean useNotify;
     private QueryExpressionType precondition;
@@ -230,13 +231,20 @@
         this.terminationTime = terminationTime;
     }
 
+    public TopicExpressionConverter getTopicConverter() {
+        return topicConverter;
+    }
+
+    public void setTopicConverter(TopicExpressionConverter topicConverter) {
+        this.topicConverter = topicConverter;
+    }
 
     // Implementation methods
     //-------------------------------------------------------------------------
     protected void fireDemandChangeEvent(boolean inDemand) throws RemoteException, SubscribeCreationFailedFault, ResourceUnknownFault, TopicPathDialectUnknownFault {
         NotificationProducer producer = createPublisherNotificationProducer();
         if (inDemand) {
-            producer.subscribe(publisherReference, TopicExpressionConverter.toTopicExpression(topic), useNotify, precondition, selector, subscriptionPolicy, terminationTime);
+            producer.subscribe(publisherReference, topicConverter.toTopicExpression(topic), useNotify, precondition, selector, subscriptionPolicy, terminationTime);
         }
         else {
 

servicemix/ws/jaxws/wsnotification/src/main/java/org/servicemix/ws/notification/impl
ActiveMQSubscription.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ActiveMQSubscription.java	24 Aug 2005 14:45:59 -0000	1.1
+++ ActiveMQSubscription.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -35,7 +35,9 @@
 public class ActiveMQSubscription implements Service {
 
     private final ActiveMQConnection connection;
+
     private EndpointReferenceType consumerReference;
+    private TopicExpressionConverter topicConverter;
     private Session session;
     private ActiveMQMessageConsumer consumer;
 
@@ -47,9 +49,10 @@
     private XMLGregorianCalendar terminationTime;
     private MessageListener dispatcher;
 
-    public ActiveMQSubscription(ActiveMQConnection connection, EndpointReferenceType consumerReference) {
+    public ActiveMQSubscription(ActiveMQConnection connection, EndpointReferenceType consumerReference, TopicExpressionConverter topicConverter) {
         this.connection = connection;
         this.consumerReference = consumerReference;
+        this.topicConverter = topicConverter;
     }
 
     public void start() throws JMSException {
@@ -58,7 +61,7 @@
                 throw new IllegalArgumentException("Must specify a dispatcher");
             }
             session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-            consumer = (ActiveMQMessageConsumer) session.createConsumer(TopicExpressionConverter.toActiveMQTopic(topicExpression), toJMSSelector(selector));
+            consumer = (ActiveMQMessageConsumer) session.createConsumer(topicConverter.toActiveMQTopic(topicExpression), toJMSSelector(selector));
             consumer.setMessageListener(dispatcher);
         }
         else {

servicemix/ws/jaxws/wsnotification/src/main/java/org/servicemix/ws/notification/impl
TopicExpressionConverter.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- TopicExpressionConverter.java	24 Aug 2005 14:45:59 -0000	1.1
+++ TopicExpressionConverter.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -28,15 +28,15 @@
 
     public static final String SIMPLE_DIALECT = "http://www.ibm.com/xmlns/stdwip/web-services/WSTopics/TopicExpression/simple";
 
-    static public TopicExpressionType toTopicExpression(Topic topic) {
+    public TopicExpressionType toTopicExpression(Topic topic) {
         return toTopicExpression(topic.toString());
     }
 
-    static public TopicExpressionType toTopicExpression(ActiveMQTopic topic) {
+    public TopicExpressionType toTopicExpression(ActiveMQTopic topic) {
         return toTopicExpression(topic.getPhysicalName());
     }
 
-    public static TopicExpressionType toTopicExpression(String name) {
+    public TopicExpressionType toTopicExpression(String name) {
         TopicExpressionType answer = new TopicExpressionType();
         answer.getContent().add(name);
         answer.setDialect(SIMPLE_DIALECT);
@@ -44,7 +44,7 @@
     }
 
 
-    static public ActiveMQTopic toActiveMQTopic(List<TopicExpressionType> topics) {
+    public ActiveMQTopic toActiveMQTopic(List<TopicExpressionType> topics) {
         if (topics == null || topics.size() == 0) {
             return null;
         }
@@ -59,25 +59,27 @@
         return topic;
     }
 
-    static public ActiveMQTopic toActiveMQTopic(TopicExpressionType topic) {
+    public ActiveMQTopic toActiveMQTopic(TopicExpressionType topic) {
         String dialect = topic.getDialect();
-        if (SIMPLE_DIALECT.equals(dialect)) {
-            Object item = null;
+        if (dialect == null || SIMPLE_DIALECT.equals(dialect)) {
             for (Iterator iter = topic.getContent().iterator(); iter.hasNext();) {
-                item = iter.next();
-                if (item instanceof String) {
-                    return new ActiveMQTopic((String) item);
+                ActiveMQTopic answer = createActiveMQFromContent(iter.next());
+                if (answer != null) {
+                    return answer;
                 }
             }
-            if (item != null) {
-                return new ActiveMQTopic(item.toString());
-            }
-            else {
-                throw new RuntimeException("No topic name available topic: " + topic);
-            }
+            throw new RuntimeException("No topic name available topic: " + topic);
         }
         else {
             throw new RuntimeException("Topic dialect: " + dialect + " not supported");
         }
     }
+
+    protected ActiveMQTopic createActiveMQFromContent(Object contentItem) {
+        if (contentItem instanceof String) {
+            return new ActiveMQTopic((String) contentItem);
+        }
+        return null;
+    }
+
 }

servicemix/ws/jaxws/wsnotification/src/test/java/org/servicemix/ws/notification/impl
ActiveMQNotificationBrokerTest.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ActiveMQNotificationBrokerTest.java	24 Aug 2005 15:25:52 -0000	1.3
+++ ActiveMQNotificationBrokerTest.java	25 Aug 2005 17:35:18 -0000	1.4
@@ -32,7 +32,7 @@
 import java.util.List;
 
 /**
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 public class ActiveMQNotificationBrokerTest extends TestSupport {
 
@@ -63,7 +63,7 @@
         MessageConsumer consumer = session.createConsumer(topic);
 
         NotificationMessageHolderType messageHolder = new NotificationMessageHolderType();
-        messageHolder.setTopic(TopicExpressionConverter.toTopicExpression(topic));
+        messageHolder.setTopic(topicConverter.toTopicExpression(topic));
         messageHolder.setMessage(createMessage());
 
         List<NotificationMessageHolderType> list = new ArrayList<NotificationMessageHolderType>();

servicemix/ws/jaxws/wsnotification/src/test/java/org/servicemix/ws/notification/impl
TestSupport.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- TestSupport.java	24 Aug 2005 14:51:20 -0000	1.1
+++ TestSupport.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -30,14 +30,19 @@
 import java.util.List;
 
 /**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  */
 public abstract class TestSupport extends TestCase {
-    protected ActiveMQTopic topic = new ActiveMQTopic("Test");
+    protected final String TOPIC_NAME = getClass() + "." + getName();
+
+    protected ActiveMQTopic topic = new ActiveMQTopic(TOPIC_NAME);
+    protected TopicExpressionConverter topicConverter = new TopicExpressionConverter();
 
     protected EndpointReferenceType addSubscription(ActiveMQNotificationBroker broker) throws Exception {
         // START SNIPPET: subscribe
-        TopicExpressionType topicExpression = TopicExpressionConverter.toTopicExpression(topic);
+        String topicName = TOPIC_NAME;
+        TopicExpressionType topicExpression = new TopicExpressionType();
+        topicExpression.getContent().add(topicName);
         EndpointReferenceType consumerReference = createReference();
         Boolean useNotify = Boolean.TRUE;
         QueryExpressionType precondition = null;
@@ -51,10 +56,13 @@
 
     protected void sendNotification(ActiveMQNotificationBroker broker) {
         // START SNIPPET: notify
-        NotificationMessageHolderType messageHolder = new NotificationMessageHolderType();
-        messageHolder.setTopic(TopicExpressionConverter.toTopicExpression(topic));
+        String topicName = TOPIC_NAME;
+        TopicExpressionType topicExpression = new TopicExpressionType();
+        topicExpression.getContent().add(topicName);
 
-        messageHolder.setMessage(createMessage());
+        NotificationMessageHolderType messageHolder = new NotificationMessageHolderType();
+        messageHolder.setTopic(topicExpression);
+        messageHolder.setMessage("Hello there! The time is: " + new Date());
 
         List<NotificationMessageHolderType> list = new ArrayList<NotificationMessageHolderType>(1);
         list.add(messageHolder);

servicemix/ws/jaxws/wsnotification/src/test/java/org/servicemix/ws/notification/impl
TopicExpressionConverterTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- TopicExpressionConverterTest.java	24 Aug 2005 14:51:20 -0000	1.1
+++ TopicExpressionConverterTest.java	25 Aug 2005 17:35:18 -0000	1.2
@@ -23,10 +23,12 @@
 
 public class TopicExpressionConverterTest extends TestCase {
 
+    private TopicExpressionConverter topicConverter = new TopicExpressionConverter();
+
     public void testConvert() {
         ActiveMQTopic topic1 = new ActiveMQTopic("Hello");
-        TopicExpressionType type = TopicExpressionConverter.toTopicExpression(topic1);
-        ActiveMQTopic topic2 = TopicExpressionConverter.toActiveMQTopic(type);
+        TopicExpressionType type = topicConverter.toTopicExpression(topic1);
+        ActiveMQTopic topic2 = topicConverter.toActiveMQTopic(type);
         assertEquals(topic1, topic2);
     }
 }
CVSspam 0.2.8



Reply via email to