You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2007/01/05 21:36:42 UTC

svn commit: r493183 - in /webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl: SimpleNotificationProducer.java TopicFilter.java

Author: danj
Date: Fri Jan  5 12:36:42 2007
New Revision: 493183

URL: http://svn.apache.org/viewvc?view=rev&rev=493183
Log:
initial fixes for MUSE-151 and MUSE-153. these additions are discussed in the respective JIRA items.

Modified:
    webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/SimpleNotificationProducer.java
    webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/TopicFilter.java

Modified: webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/SimpleNotificationProducer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/SimpleNotificationProducer.java?view=diff&rev=493183&r1=493182&r2=493183
==============================================================================
--- webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/SimpleNotificationProducer.java (original)
+++ webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/SimpleNotificationProducer.java Fri Jan  5 12:36:42 2007
@@ -28,7 +28,6 @@
 
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.muse.core.Persistence;
@@ -79,8 +78,6 @@
     //
     private static Messages _MESSAGES = MessagesFactory.get(SimpleNotificationProducer.class);
     
-    private static final String _TOPIC_SET_PARAM = "topic-set";
-    
     //
     // all topic names in the topic set - not a hierarchical collection
     //
@@ -153,20 +150,6 @@
         return topics;
     }
     
-    protected void addTopics(Element topicTree, 
-                             String namespace, 
-                             String prefix) 
-        throws BaseFault
-    {
-        String name = topicTree.getLocalName();
-        addTopic(new QName(namespace, name, prefix));
-        
-        Element[] children = XmlUtils.getAllElements(topicTree);
-        
-        for (int n = 0; n < children.length; ++n)
-            addTopics(children[n], namespace, prefix);
-    }
-    
     protected MessageHandler createGetCurrentMessageHandler()
     {
         MessageHandler handler = new GetCurrentMessageHandler();
@@ -214,21 +197,6 @@
         return handler;
     }
     
-    protected void createTopicSetDocument(String topicSetFile)
-        throws BaseFault
-    {
-        Document doc = getEnvironment().getDocument(topicSetFile);
-        Element topicSetXML = XmlUtils.getFirstElement(doc);
-        Element[] topicTrees = XmlUtils.getAllElements(topicSetXML);
-        
-        for (int n = 0; n < topicTrees.length; ++n)
-        {
-            String uri = topicTrees[n].getNamespaceURI();
-            String prefix = topicTrees[n].getPrefix();
-            addTopics(topicTrees[n], uri, prefix);
-        }
-    }
-    
     public NotificationMessage getCurrentMessage(QName topicPath)
         throws NoCurrentMessageOnTopicFault, 
                TopicNotSupportedFault
@@ -355,15 +323,6 @@
         // make sure we can listen for new subscriptions/destructions
         //
         manager.addListener(this);
-        
-        //
-        // if there are any user-defined topic spaces, find those files 
-        // and make sure they exist
-        //
-        String topicSetFile = getInitializationParameter(_TOPIC_SET_PARAM);
-        
-        if (topicSetFile != null)
-            createTopicSetDocument(topicSetFile);
     }
     
     public void initializeCompleted()
@@ -386,22 +345,34 @@
             QName name = (QName)i.next();
             
             addTopic(name);
-            _allTopicNames.add(name);
             
             PropertyChangeListener listener = factory.newInstance(name, resource);
             props.addChangeListener(listener);
         }
         
+        Collection[] values = new Collection[2];
+        values[0] = props.getMetadata().getInitialValues(WsnConstants.TOPIC_EXPRESSION_QNAME);
+        values[1] = props.getMetadata().getStaticValues(WsnConstants.TOPIC_EXPRESSION_QNAME);
+        
+        for (int n = 0; n < values.length; ++n)
+        {
+            i = values[n].iterator();
+            
+            while (i.hasNext())
+            {
+                Element topicTree = (Element)i.next();
+                QName topicName = XmlUtils.getQName(topicTree);
+                addTopic(topicName);
+            }
+        }
+        
         //
         // if the resource supports either WS-RL capability, add support 
         // for the WS-RL termination topic
         //
         if (resource.hasCapability(WsrlConstants.IMMEDIATE_TERMINATION_URI) || 
             resource.hasCapability(WsrlConstants.SCHEDULED_TERMINATION_URI))
-        {
             addTopic(WsrlConstants.TERMINATION_TOPIC_QNAME);
-            _allTopicNames.add(WsrlConstants.TERMINATION_TOPIC_QNAME);
-        }
     }
     
     public void prepareShutdown() 
@@ -541,13 +512,16 @@
         if (filter instanceof TopicFilter)
         {
             TopicFilter topicFilter = (TopicFilter)filter;
-            QName topic = topicFilter.getTopic();
+            QName topicName = topicFilter.getTopic();
             
-            if (!hasTopic(topic))
+            if (!hasTopic(topicName))
             {
-                Object[] filler = { topic };
+                Object[] filler = { topicName };
                 throw new TopicNotSupportedFault(_MESSAGES.get("TopicNotFound", filler));
             }
+            
+            Topic topic = getTopic(topicName);
+            topicFilter.setTopic(topic);            
         }
         
         WsResource producer = getWsResource();

Modified: webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/TopicFilter.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/TopicFilter.java?view=diff&rev=493183&r1=493182&r2=493183
==============================================================================
--- webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/TopicFilter.java (original)
+++ webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/TopicFilter.java Fri Jan  5 12:36:42 2007
@@ -17,6 +17,7 @@
 package org.apache.muse.ws.notification.impl;
 
 import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -29,6 +30,7 @@
 import org.apache.muse.ws.notification.NotificationMessage;
 import org.apache.muse.ws.notification.WsnConstants;
 import org.apache.muse.ws.notification.faults.*;
+import org.apache.muse.ws.notification.topics.Topic;
 import org.apache.muse.ws.notification.topics.WstConstants;
 import org.apache.muse.ws.notification.topics.impl.ConcretePathExpression;
 
@@ -52,6 +54,8 @@
     
     private QName _topicName = null;
     
+    private Topic _topic = null;
+    
     public TopicFilter(QName topicName) 
         throws TopicExpressionDialectUnknownFault, 
                InvalidTopicExpressionFault
@@ -78,15 +82,78 @@
         _topicName = topicName;
     }
     
+    public TopicFilter(Topic topic) 
+        throws TopicExpressionDialectUnknownFault, 
+               InvalidTopicExpressionFault
+    {
+        this(topic, WstConstants.CONCRETE_TOPIC_URI);
+    }
+    
+    public TopicFilter(Topic topic, String dialect) 
+        throws TopicExpressionDialectUnknownFault, 
+               InvalidTopicExpressionFault
+    {
+        this(topic.getConcretePath(), dialect);
+    }
+    
     public boolean accepts(NotificationMessage message)
     {
-        QName messageTopic = message.getTopic();
-        return messageTopic != null && messageTopic.equals(_topicName);
+        QName messageTopicName = message.getTopic();
+        
+        //
+        // no topic name? not from our topic
+        //
+        if (messageTopicName == null)
+            return false;
+        
+        //
+        // different topic name? not from our topic
+        //
+        if (!messageTopicName.equals(_topicName))
+            return false;
+        
+        //
+        // if we haven't supplied the Topic data structure, we 
+        // can't compare message types/patterns - must be a match
+        //
+        if (_topic == null)
+            return true;
+        
+        String pattern = _topic.getMessagePattern();
+        
+        //
+        // no pattern to compare? it's a match
+        //
+        if (pattern == null)
+            return true;
+        
+        //
+        // we only support XPath patterns in the default impl
+        //
+        try
+        {
+            return XPathUtils.isMatch(message.toXML(), pattern);
+        }
+        
+        catch (TransformerException error)
+        {
+            throw new RuntimeException(error.getMessage(), error);
+        }
     }
     
     public QName getTopic()
     {
         return _topicName;
+    }
+    
+    public void setTopic(QName topicName)
+    {
+        _topicName = topicName;
+    }
+    
+    public void setTopic(Topic topic)
+    {
+        _topic = topic;
     }
     
     public String toString()



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org