You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-dev@ws.apache.org by ip...@apache.org on 2005/04/29 03:32:53 UTC

svn commit: r165250 [1/2] - in /incubator/hermes/trunk/src: java/org/apache/ws/notification/base/ java/org/apache/ws/notification/base/impl/ java/org/apache/ws/notification/base/v2004_6/porttype/impl/ java/org/apache/ws/notification/topics/ java/org/apache/ws/notification/topics/impl/ java/org/apache/ws/notification/topics/util/ java/org/apache/ws/pubsub/ test/org/apache/ws/notification/topics/impl/

Author: ips
Date: Thu Apr 28 18:32:52 2005
New Revision: 165250

URL: http://svn.apache.org/viewcvs?rev=165250&view=rev
Log:
finished implementing Full topic expressions

Added:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceSet.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicSet.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java
Removed:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSetImpl.java
Modified:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/base/NotificationProducerResource.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/base/impl/AbstractSubscription.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/porttype/impl/NotificationProducerPortTypeImpl.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/Topic.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEngine.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEvaluator.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSet.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpace.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceRegistry.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluator.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluator.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluator.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicExpressionEngineImpl.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java
    incubator/hermes/trunk/src/java/org/apache/ws/pubsub/TopicFilter.java

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/base/NotificationProducerResource.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/base/NotificationProducerResource.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/base/NotificationProducerResource.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/base/NotificationProducerResource.java Thu Apr 28 18:32:52 2005
@@ -15,7 +15,7 @@
  *=============================================================================*/
 package org.apache.ws.notification.base;
 
-import org.apache.ws.notification.topics.TopicSet;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.resource.Resource;
 
 /**
@@ -27,6 +27,6 @@
 public interface NotificationProducerResource extends Resource
 {
 
-    TopicSet getTopicSpaceSet();
+    TopicSpaceSet getTopicSpaceSet();
 
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/base/impl/AbstractSubscription.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/base/impl/AbstractSubscription.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/base/impl/AbstractSubscription.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/base/impl/AbstractSubscription.java Thu Apr 28 18:32:52 2005
@@ -15,26 +15,25 @@
  *=============================================================================*/
 package org.apache.ws.notification.base.impl;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.ws.addressing.EndpointReference;
 import org.apache.ws.notification.base.NotificationProducerResource;
 import org.apache.ws.notification.base.Subscription;
+import org.apache.ws.notification.topics.Topic;
 import org.apache.ws.notification.topics.TopicExpression;
 import org.apache.ws.notification.topics.TopicListener;
 import org.apache.ws.notification.topics.TopicListenerList;
-import org.apache.ws.notification.topics.TopicSet;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.impl.SimpleSubscriptionTopicListener;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
 import org.apache.ws.pubsub.Filter;
 import org.apache.ws.pubsub.NotificationConsumer;
 import org.apache.ws.pubsub.NotificationProducer;
 import org.apache.ws.resource.PersistenceCallback;
+import org.apache.ws.resource.PropertiesResource;
 import org.apache.ws.resource.Resource;
 import org.apache.ws.resource.ResourceException;
 import org.apache.ws.resource.ResourceHome;
 import org.apache.ws.resource.ResourceKey;
-import org.apache.ws.resource.PropertiesResource;
 import org.apache.ws.resource.lifetime.ResourceTerminationEvent;
 import org.apache.ws.resource.lifetime.ResourceTerminationListener;
 import org.apache.ws.resource.lifetime.impl.ResourceTerminationEventImpl;
@@ -49,7 +48,6 @@
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -59,8 +57,7 @@
 public abstract class AbstractSubscription implements Subscription, PropertiesResource
 {
 
-    private static final Log LOG =
-            LogFactory.getLog( AbstractSubscription.class.getName() );
+    //private static final Log LOG = LogFactory.getLog( AbstractSubscription.class.getName() );
 
     protected EndpointReference m_consumerReference;
     protected EndpointReference m_producerReference;
@@ -85,10 +82,10 @@
     private NotificationConsumer m_notificationConsumer;
     private NotificationProducer m_notificationProducer;
 
-   /**
-    * A list of termination listeners to be notified when the resource is terminated.
-    */
-   private List m_terminationListeners = new ArrayList();
+    /**
+     * A list of termination listeners to be notified when the resource is terminated.
+     */
+    private List m_terminationListeners = new ArrayList();
 
     public ResourcePropertySet getResourcePropertySet()
     {
@@ -144,12 +141,12 @@
 
     public QueryExpression getSelector()
     {
-            return m_selector;     
+        return m_selector;
     }
 
     public TopicExpression getTopicExpression()
     {
-            return m_topicExpression;
+        return m_topicExpression;
     }
 
     public boolean isPaused()
@@ -226,10 +223,9 @@
         m_id = (String) o;
     }
 
-
     public void destroy()
     {
-         Resource producerResource = null;
+        Resource producerResource = null;
         try
         {
             producerResource = getResource();
@@ -244,10 +240,11 @@
             return;
         }
 
-        TopicSet topicSet = ( (NotificationProducerResource) producerResource ).getTopicSpaceSet();
-        Collection topics = null;
+        //todo fix!
+        //TopicSpaceSet topicSpaceSet = ( (NotificationProducerResource) producerResource ).getTopicSpaceSet();
+        Topic[] topics = null;
         try
-        {                      //todo fix!
+        {
             //TopicSpace topicSpace = topicSpaceSet.getTopicSpace();
             //topics = topicSpace.getTopics( m_topicExpression );
             topics = evaluateTopicExpression();
@@ -270,7 +267,7 @@
                 {
                     ( (PersistenceCallback) producerResource ).store();
                 }
-                catch (ResourceException e)
+                catch ( ResourceException e )
                 {
                     ;
                 }
@@ -278,51 +275,42 @@
         }
 
         //notify listeners that this subscription expired.
-        ResourceTerminationEvent rte = new ResourceTerminationEventImpl(getID(), "Subscription Destroyed");
-        for (int i = 0; i < m_terminationListeners.size(); i++)
+        ResourceTerminationEvent rte = new ResourceTerminationEventImpl( getID(), "Subscription Destroyed" );
+        for ( int i = 0; i < m_terminationListeners.size(); i++ )
         {
-            ResourceTerminationListener resourceTerminationListener = (ResourceTerminationListener) m_terminationListeners.get(i);
-            resourceTerminationListener.terminationOccurred(rte);
+            ResourceTerminationListener resourceTerminationListener = (ResourceTerminationListener) m_terminationListeners.get(
+                    i );
+            resourceTerminationListener.terminationOccurred( rte );
         }
 
     }
 
-    private Collection evaluateTopicExpression() throws Exception
+    private Topic[] evaluateTopicExpression() throws Exception
     {
         NotificationProducerResource resource = (NotificationProducerResource) getResource();
-        TopicSet topicSet = resource.getTopicSpaceSet();
-
-        Collection collection = null;
+        TopicSpaceSet topicSpaceSet = resource.getTopicSpaceSet();
         try
         {
-            collection = topicSet.evaluateExpression(m_topicExpression);
+            return topicSpaceSet.evaluateTopicExpression( m_topicExpression );
         }
-        catch (TopicExpressionException e)
+        catch ( TopicExpressionException e )
         {
-            throw new JAXRPCException("An exception occurred during subscription. ", e);
+            throw new JAXRPCException( "An exception occurred during subscription. ", e );
         }
-        return collection;
     }
 
-    private boolean removeListener( Collection topics )
+    private boolean removeListener( Topic[] topics )
     {
         boolean removed = false;
-
-        Iterator topicIterator = topics.iterator();
-        TopicListenerList topicListenerList;
-        Iterator topicListenerIterator;
-        TopicListener listener;
-
-        while ( topicIterator.hasNext() )
+        for ( int i = 0; i < topics.length; i++ )
         {
-            topicListenerList = (TopicListenerList) topicIterator.next();
+            TopicListenerList topicListenerList = topics[i];
             synchronized ( topicListenerList )
             {
-                topicListenerIterator =
-                        topicListenerList.topicListenerIterator();
+                Iterator topicListenerIterator = topicListenerList.topicListenerIterator();
                 while ( topicListenerIterator.hasNext() )
                 {
-                    listener = (TopicListener) topicListenerIterator.next();
+                    TopicListener listener = (TopicListener) topicListenerIterator.next();
                     if ( listener instanceof SimpleSubscriptionTopicListener )
                     {
                         SimpleSubscriptionTopicListener lt =
@@ -374,22 +362,23 @@
         return m_epr;
     }
 
-    public void setEpr(EndpointReference epr)
+    public void setEpr( EndpointReference epr )
     {
         m_epr = epr;
     }
 
-    public void setNotificationConsumer(NotificationConsumer notificationConsumer)
+    public void setNotificationConsumer( NotificationConsumer notificationConsumer )
     {
         m_notificationConsumer = notificationConsumer;
     }
 
-    public void setNotificationProducer(NotificationProducer notificationProducer)
+    public void setNotificationProducer( NotificationProducer notificationProducer )
     {
         m_notificationProducer = notificationProducer;
     }
-     public void addTerminationListener(ResourceTerminationListener resourceTerminationListener)
+
+    public void addTerminationListener( ResourceTerminationListener resourceTerminationListener )
     {
-        m_terminationListeners.add(resourceTerminationListener);
+        m_terminationListeners.add( resourceTerminationListener );
     }
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/porttype/impl/NotificationProducerPortTypeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/porttype/impl/NotificationProducerPortTypeImpl.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/porttype/impl/NotificationProducerPortTypeImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/porttype/impl/NotificationProducerPortTypeImpl.java Thu Apr 28 18:32:52 2005
@@ -20,16 +20,15 @@
 import org.apache.ws.addressing.XmlBeansEndpointReference;
 import org.apache.ws.notification.base.NotificationProducerResource;
 import org.apache.ws.notification.base.Subscription;
-import org.apache.ws.notification.base.v2004_6.impl.SubscriptionHome;
 import org.apache.ws.notification.base.impl.XmlBeansTopicExpression;
 import org.apache.ws.notification.base.impl.faults.SubscribeCreationFailedFaultException;
+import org.apache.ws.notification.base.v2004_6.impl.SubscriptionHome;
 import org.apache.ws.notification.base.v2004_6.impl.SubscriptionResource;
 import org.apache.ws.notification.base.v2004_6.impl.WsnNamespaceVersionHolderImpl;
-import org.apache.ws.notification.base.v2004_6.impl.SubscriptionHome;
 import org.apache.ws.notification.base.v2004_6.porttype.NotificationProducerPortType;
 import org.apache.ws.notification.topics.Topic;
 import org.apache.ws.notification.topics.TopicExpression;
-import org.apache.ws.notification.topics.TopicSet;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.impl.SimpleSubscriptionTopicListener;
 import org.apache.ws.notification.topics.impl.faults.NoCurrentMessageOnTopicFaultException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
@@ -61,11 +60,8 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
-import javax.naming.directory.SchemaViolationException;
 import javax.xml.rpc.JAXRPCException;
 import java.util.Calendar;
-import java.util.Collection;
-import java.util.Iterator;
 
 /**
  * An implementation of the WS-BaseNotification NotificationProducer portType.
@@ -125,13 +121,11 @@
             subscription.setNotificationProducer(this);
             epr = (EndpointReferenceType) ((XmlObjectWrapper)subscription.getEpr()).getXmlObject();
 
-            Collection collection = evaluateTopicExpression(topicExpr);
+            Topic[] topics = evaluateTopicExpression(topicExpr);
             SimpleSubscriptionTopicListener simpleSubscriptionTopicListener = new SimpleSubscriptionTopicListener(subscription);
-            //add listeners
-            for (Iterator iterator = collection.iterator(); iterator.hasNext();)
+            for ( int i = 0; i < topics.length; i++ )
             {
-                Topic topic = (Topic) iterator.next();
-                topic.addTopicListener(simpleSubscriptionTopicListener);
+                topics[i].addTopicListener(simpleSubscriptionTopicListener);
             }
         }
         catch (Exception e)
@@ -146,23 +140,18 @@
         return subscribeResponseDocument;
     }
 
-    private Collection evaluateTopicExpression(TopicExpression topicExpr)
+    private Topic[] evaluateTopicExpression(TopicExpression topicExpr)
     {
         NotificationProducerResource resource = (NotificationProducerResource) getResource();
-        TopicSet topicSet = resource.getTopicSpaceSet();
-
-        Collection collection = null;
+        TopicSpaceSet topicSpaceSet = resource.getTopicSpaceSet();
         try
         {
-            collection = topicSet.evaluateExpression(topicExpr);
+            return topicSpaceSet.evaluateTopicExpression(topicExpr);
         }
         catch (TopicExpressionException e)
         {
             throw new JAXRPCException("An exception occurred evaluating a TopicExpression. ", e);
         }
-
-
-        return collection;
     }
 
     private static XmlBeansEndpointReference buildEPR( ResourceContext resourceContext )
@@ -187,34 +176,24 @@
     public GetCurrentMessageResponseDocument getCurrentMessage( GetCurrentMessageDocument requestDoc )
     {
         GetCurrentMessageDocument.GetCurrentMessage request = requestDoc.getGetCurrentMessage();
-        TopicExpressionType topicExprMess = request.getTopic();
-        Collection collection = null;
-        try
-        {
-            TopicExpression topicExpr = new XmlBeansTopicExpression( topicExprMess );
-            collection = evaluateTopicExpression(topicExpr);
-        }
-        catch ( SchemaViolationException e)
-        {
-            throw new JAXRPCException("An exception occurred: ",e);
-        }
+        TopicExpressionType topicExprXmlBean = request.getTopic();
+        TopicExpression topicExpr = new XmlBeansTopicExpression( topicExprXmlBean );
+        Topic[] topics = evaluateTopicExpression(topicExpr);
 
-        if(collection.size() < 1)
+        if(topics.length == 0)
         {
             throw new NoCurrentMessageOnTopicFaultException(new WsnNamespaceVersionHolderImpl(),"There was no current message to retrieve.");
         }
 
         GetCurrentMessageResponseDocument message = GetCurrentMessageResponseDocument.Factory.newInstance();
             GetCurrentMessageResponseDocument.GetCurrentMessageResponse response = message.addNewGetCurrentMessageResponse();
-        if(collection.size() > 1)
+        if(topics.length > 1)
         {
-            throw new JAXRPCException("The topicexpression for GetCurrentMessage return more than 1 value!  This is an invalid request.");
+            throw new JAXRPCException("The topicexpression for GetCurrentMessage returned more than 1 value!  This is an invalid request.");
         }
         else
         {
-            Topic topic = (Topic) collection.iterator().next();
-            XmlObject currentMessage = (XmlObject) topic.getCurrentMessage();
-
+            XmlObject currentMessage = (XmlObject) topics[0].getCurrentMessage();
             XmlBeanUtils.addChildElement(response, currentMessage);
         }
 

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/Topic.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/Topic.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/Topic.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/Topic.java Thu Apr 28 18:32:52 2005
@@ -15,7 +15,6 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics;
 
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -24,32 +23,23 @@
  *
  * @see TopicSpace
  */
-public interface Topic extends TopicListenerList
+public interface Topic extends TopicSet, TopicListenerList
 {
-    /**
-     * Add a subtopic.
-     *
-     * @param topic the sub-topic to add
-     *
-     * @throws Exception
-     */
-    void addTopic( Topic topic ) throws Exception;
 
     /**
-     * Remove a subtopic.
+     * Get the name of this topic.
      *
-     * @param topic the sub-topic to remove
+     * @return the name of this topic
      */
-    void removeTopic( Topic topic );
+    String getName();
 
     /**
-     * Get the subtopic with the given topic name
-     *
-     * @param topicName the topic name of the sub topic
+     * Get the latest notification message published to this topic.
      *
-     * @return the subtopic, or null if no subtopic with the given name exists
+     * @return an Object representing the latest notification message published to this topic, or null if no messages
+     *         have yet been published
      */
-    Topic getTopic( String topicName );
+    Object getCurrentMessage();
 
     /**
      * Set the topic expression that resolves to a set of topics that this topic references.
@@ -81,20 +71,6 @@
     List getTopicPath();
 
     /**
-     * Get the name of the topic.
-     *
-     * @return the name of the topic
-     */
-    String getName();
-
-    /**
-     * Get the current notification message if there is any
-     *
-     * @return A object containing the current message, may be null
-     */
-    Object getCurrentMessage();
-
-    /**
      * Publish a notification message to this topic.
      *
      * @param msg the notification message to be published
@@ -109,13 +85,6 @@
      * @return true if this topic is a reference to another topic, false if not
      */
     boolean isReference();
-
-    /**
-     * Iterator for the set of child topics
-     *
-     * @return the iterator
-     */
-    Iterator topicIterator();
 
     /**
      * Set the TopicSpace this Topic is part of

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEngine.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEngine.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEngine.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEngine.java Thu Apr 28 18:32:52 2005
@@ -15,13 +15,10 @@
  */
 package org.apache.ws.notification.topics;
 
-import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
 import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
-
-import java.util.Collection;
-import java.util.List;
+import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
+import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
 
 /**
  * The <code>TopicExpressionEngine</code> interface is used to map queries on a
@@ -39,14 +36,14 @@
      * @param evaluator implementation of evaluator to be used for evaluating
      *                  topic expressions
      */
-    public void registerEvaluator(TopicExpressionEvaluator evaluator);
+    void registerEvaluator(TopicExpressionEvaluator evaluator);
 
     /**
      * Resolves a topic expression using the passed topic list. The appropraite
      * TopicExpressionEvaluator is used based on the dialect element.
      *
+     * @param topicSpaceSet       the topic list to apply the expression to
      * @param topicExpression topic expression
-     * @param topicSpace       the topic list to apply the expression to
      * @return the set of topics the expression evaluated to
      * @throws UnsupportedTopicExpressionDialectException
      *                                  if the topic expression dialect is not
@@ -58,44 +55,19 @@
      *                                  if the topic expression is invalid
      * @throws TopicExpressionException if any other error occurs
      */
-    public Collection resolveTopicExpression(
-        TopicExpression topicExpression,
-        TopicSpace topicSpace) throws UnsupportedTopicExpressionDialectException,
+    Topic[] evaluateTopicExpression( TopicSpaceSet topicSpaceSet, TopicExpression topicExpression ) throws UnsupportedTopicExpressionDialectException,
                                     TopicExpressionResolutionException,
                                     InvalidTopicExpressionException,
                                     TopicExpressionException;
 
     /**
-     * Converts the expression from dialect specific form to a ordered list of
-     * QNames. This method throws an exception if the expression does not
-     * evaluate to a concrete topic path.
-     *
-     * @param topicExpression topic expression
-     * @return a list of QNames describing the concrete topic path
-     * @throws UnsupportedTopicExpressionDialectException
-     *                                  if the topic expression dialect is not
-     *                                  supported
-     * @throws TopicExpressionResolutionException
-     *                                  if the expression could not be
-     *                                  evaluated
-     * @throws org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException
-     *                                  if the topic expression is invalid
-     * @throws TopicExpressionException if any other error occurs
-     */
-    public List getConcretePath(TopicExpression topicExpression)
-        throws UnsupportedTopicExpressionDialectException,
-               TopicExpressionResolutionException,
-               InvalidTopicExpressionException,
-               TopicExpressionException;
-
-    /**
      * Gets the evaluator currently registered to handle a topic expression of
      * the specified dialect.
      *
      * @return the matching topic expression evaluator or null if none was
      *         found
      */
-    public TopicExpressionEvaluator getEvaluator(String dialect);
+    TopicExpressionEvaluator getEvaluator(String dialect);
 
     /**
      * Returns a list of URIs representing the registered topic expression
@@ -103,5 +75,6 @@
      *
      * @return the list of supported dialects
      */
-    public String[] getSupportedDialects();
+    String[] getSupportedDialects();
+
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEvaluator.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEvaluator.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicExpressionEvaluator.java Thu Apr 28 18:32:52 2005
@@ -19,15 +19,11 @@
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
 import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
-import org.w3c.dom.Element;
-
-import java.util.Collection;
-import java.util.List;
 
 /**
  * A <code>TopicExpressionEvaluator</code> is used to implement a topic expression evaluation against a
- * <code>TopicList</code>. An evaluator can be registered with a <code>TopicExpressionEngine</code>, which in turn calls
- * the evaluator when a matching expression is found.
+ * <code>TopicSpaceSet</code>. An evaluator can be registered with a <code>TopicExpressionEngine</code>,
+ * which in turn calls the evaluator when a matching expression is found.
  */
 public interface TopicExpressionEvaluator
 {
@@ -35,10 +31,8 @@
     /**
      * Evaluates the expression over a TopicSpace and returns the set of matching topics.
      *
+     * @param topicSpaceSet topic list associated with the service/resource
      * @param expression object passed by client representing the topic expression
-     * @param topicSpace topic list associated with the service/resource
-     * @param nsContext  a DOM element to use as the context for resolving namespace prefixes
-     *
      * @return the set of topics that matched the specified expression
      *
      * @throws UnsupportedTopicExpressionDialectException
@@ -49,8 +43,7 @@
      *                                  if the topic expression is invalid
      * @throws TopicExpressionException if any other error occurs
      */
-    public Collection resolve( TopicExpression expression,
-                               TopicSpace topicSpace )
+    Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression expression )
             throws UnsupportedTopicExpressionDialectException,
             TopicExpressionResolutionException,
             InvalidTopicExpressionException,
@@ -61,40 +54,6 @@
      *
      * @return array of URIs supported by this evaluator
      */
-    public String[] getDialects();
+    String[] getDialects();
 
-    /**
-     * Converts the expression from dialect specific form to a ordered list of QNames.
-     * This method throws an exception if the expression does not evaluate to a concrete
-     * topic path.
-     *
-     * @param expression object passed by client representing the topic expression
-     *
-     * @return a list of QNames describing the concrete topic path
-     *
-     * @throws UnsupportedTopicExpressionDialectException
-     *                                  if the topic expression dialect is not supported
-     * @throws InvalidTopicExpressionException
-     *                                  if the topic expression is invalid
-     * @throws TopicExpressionException if any other error occurs
-     */
-    public List getConcreteTopicPath( TopicExpression expression )
-            throws UnsupportedTopicExpressionDialectException,
-            InvalidTopicExpressionException,
-            TopicExpressionException;
-
-    /**
-     * Converts a topic path (list of QNames) to a dialect specific concrete topic expression.
-     *
-     * @param topicPath containing a list of QNames describing a concrete topic path
-     *
-     * @return dialect specific version of the topic path
-     *
-     * @throws InvalidTopicExpressionException
-     *                                  if the conrete topic path is invalid
-     * @throws TopicExpressionException if any other error occurs
-     */
-    public TopicExpression toTopicExpression( List topicPath )
-            throws org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException,
-            TopicExpressionException;
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSet.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSet.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSet.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSet.java Thu Apr 28 18:32:52 2005
@@ -1,5 +1,5 @@
 /*=============================================================================*
- *  Copyright 2004 The Apache Software Foundation
+ *  Copyright 2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -15,32 +15,65 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics;
 
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
-
-import java.util.Collection;
+import java.util.Iterator;
 
 /**
- * The set of topics that a particular NotificationProducer supports.
+ * TODO
  *
  * @author Ian Springer (ian DOT springer AT hp DOT com)
  */
 public interface TopicSet
 {
 
-    void addTopicSpace( TopicSpace topicSpace );
+    /**
+     * Adds the specified topic to this set.
+     *
+     * @param topic the topic to add
+     *
+     * @throws Exception if topic is null or has the same name as a topic already in this set
+     */
+    Topic addTopic( Topic topic ) throws Exception;
 
-    void removeTopicSpace( String namespaceURI );
+    /**
+     * Creates a new Topic object with the specified name and adds it to this set.
+     *
+     * @param name the name of the topic to add
+     *
+     * @throws Exception if name is null, invalid (contains '/', '*', or '.'), or is the same as the name of a topic
+     *                   already in this set
+     */
+    Topic addTopic( String name ) throws Exception;
 
-    TopicSpace getTopicSpace( String namespaceURI );
+    /**
+     * Removes the topic with the specified name from this set.
+     *
+     * @param name the name of the topic to remove
+     */
+    void removeTopic( String name );
 
-    TopicSpace[] getTopicSpaces();
+    /**
+     * Gets the topic with the specified name.
+     *
+     * @param name the name of the topic to get
+     *
+     * @return the topic, or null if no topic with the given name exists in this set
+     */
+    Topic getTopic( String name );
 
-    Collection evaluateExpression(TopicExpression topicExpr) throws TopicExpressionException;
+    /**
+     * Returns <tt>true</tt> if this set contains a topic with the specified name.
+     *
+     * @param name the name
+     *
+     * @return <tt>true</tt> if this set contains a topic with the specified name
+     */
+    boolean containsTopic( String name );
 
     /**
-     * Returns a boolean that indicates if this topic set is fixed as defined by
-     * the WS-BaseNotification specification.
+     * Gets an iterator of the topics in this set.
+     *
+     * @return the iterator
      */
-    boolean isFixed();
+    Iterator topicIterator();
 
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpace.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpace.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpace.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpace.java Thu Apr 28 18:32:52 2005
@@ -15,73 +15,25 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics;
 
-import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * A topic space (i.e. a set of topics within a particular namespace).
  * Provides methods for managing the topics and performing queries on them.
  */
-public interface TopicSpace extends TopicListenerList
+public interface TopicSpace extends TopicSet, TopicListenerList
 {
 
     /**
-     * Returns this topic space's namespace URI.
-     *
-     * @return this topic space's namespace URI
-     */
-    String getNamespaceURI();
-
-    /**
-     * Add a root topic.
-     *
-     * @param topic the topic to add
-     */
-    void addTopic( Topic topic );
-
-    /**
-     * Remove a root topic.
+     * Returns this topic space's target namespace.
      *
-     * @param topic the topic to remove
+     * @return this topic space's target namespace
      */
-    void removeTopic( Topic topic );
+    String getTargetNamespace();
 
     /**
-     * Get the set of topics the given topic expression resolves to.
+     * Returns this topic space's name.
      *
-     * @param topicExpression The topic expression to resolve to a set of topics
-     *
-     * @return The resulting set of topics
-     *
-     * @throws UnsupportedTopicExpressionDialectException
-     *                                  if the topic expression dialect is not supported
-     * @throws TopicExpressionResolutionException
-     *                                  if the expression could not be evaluated
-     * @throws InvalidTopicExpressionException
-     *                                  if the topic expression is invalid
-     * @throws TopicExpressionException if any other error occurs
-     */
-    Collection getTopics( TopicExpression topicExpression ) throws TopicExpressionException, TopicExpressionResolutionException
-            /* throws UnsupportedTopicExpressionDialectException, TopicExpressionResolutionException, InvalidTopicExpressionException, TopicExpressionException */;
-
-    /**
-     * Get the topic for the given topic path.
-     *
-     * @param topicPath The topic path (list of topic names)
-     *
-     * @return The topic corresponding to the given topic path
+     * @return this topic space's name
      */
-    Topic getTopic( List topicPath );
+    String getName();
 
-    /**
-     * Iterator for the set of root topics
-     *
-     * @return The iterator
-     */
-    Iterator topicIterator();
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceRegistry.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceRegistry.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceRegistry.java Thu Apr 28 18:32:52 2005
@@ -41,7 +41,7 @@
 
     public void addTopicSpace( TopicSpace topicSpace )
     {
-        m_topicSpaceMap.put( topicSpace.getNamespaceURI(), topicSpace );
+        m_topicSpaceMap.put( topicSpace.getTargetNamespace(), topicSpace );
     }
 
     public void removeTopicSpace( String namespaceURI )

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceSet.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceSet.java?rev=165250&view=auto
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceSet.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/TopicSpaceSet.java Thu Apr 28 18:32:52 2005
@@ -0,0 +1,44 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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.ws.notification.topics;
+
+import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
+
+/**
+ * The set of topics that a particular NotificationProducer supports.
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public interface TopicSpaceSet
+{
+
+    TopicSpace addTopicSpace( TopicSpace topicSpace ) throws Exception;
+
+    void removeTopicSpace( String namespaceURI );
+
+    TopicSpace getTopicSpace( String namespaceURI );
+
+    TopicSpace[] getTopicSpaces();
+
+    Topic[] evaluateTopicExpression(TopicExpression topicExpr) throws TopicExpressionException;
+
+    /**
+     * Returns a boolean that indicates if this topic set is fixed as defined by
+     * the WS-BaseNotification specification.
+     */
+    boolean isFixed();
+
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java?rev=165250&view=auto
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java Thu Apr 28 18:32:52 2005
@@ -0,0 +1,57 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.ws.notification.topics.impl;
+
+import org.apache.ws.util.xml.NamespaceContext;
+import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
+
+import javax.xml.namespace.QName;
+import java.util.StringTokenizer;
+
+/**
+ * TODO
+ */
+public abstract class AbstractTopicExpressionEvaluator
+{
+
+    protected QName toQName( String topicPath, NamespaceContext nsContext )
+            throws InvalidTopicExpressionException
+    {
+        StringTokenizer topicPathTokenizer = new StringTokenizer( topicPath, ":" );
+        if ( topicPathTokenizer.countTokens() == 0 )
+        {
+            throw new InvalidTopicExpressionException( "Topic path '" + topicPath + "' contains no local part." );
+        }
+        if ( topicPathTokenizer.countTokens() > 2 )
+        {
+            throw new InvalidTopicExpressionException( "Topic path '" + topicPath + "' contains more than one colon." );
+        }
+        String prefix, localPart;
+        if ( topicPathTokenizer.countTokens() == 1 )
+        {
+            prefix = "";
+            localPart = topicPathTokenizer.nextToken();
+        }
+        else
+        {
+            prefix = topicPathTokenizer.nextToken();
+            localPart = topicPathTokenizer.nextToken();
+        }
+        String nsURI = nsContext.getNamespaceURI( prefix );
+        return new QName( nsURI, localPart, prefix );
+    }
+    
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicSet.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicSet.java?rev=165250&view=auto
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicSet.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicSet.java Thu Apr 28 18:32:52 2005
@@ -0,0 +1,59 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.ws.notification.topics.impl;
+
+import org.apache.ws.notification.topics.TopicSet;
+import org.apache.ws.notification.topics.Topic;
+
+import java.util.Iterator;
+
+/**
+ * TODO
+ */
+public class AbstractTopicSet implements TopicSet
+{
+
+    public Topic addTopic( Topic topic ) throws Exception
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Topic addTopic( String name ) throws Exception
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void removeTopic( String name )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Topic getTopic( String name )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public boolean containsTopic( String name )
+    {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Iterator topicIterator()
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+}

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluator.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluator.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluator.java Thu Apr 28 18:32:52 2005
@@ -15,107 +15,91 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics.impl;
 
-import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ws.notification.topics.Topic;
 import org.apache.ws.notification.topics.TopicExpression;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.ws.notification.topics.TopicSet;
 import org.apache.ws.notification.topics.TopicSpace;
-import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.impl.faults.InvalidTopicExpressionFaultException;
-import org.apache.ws.notification.topics.impl.faults.TopicNotSupportedFaultException;
-import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
+import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
+import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
 import org.apache.ws.notification.topics.v2004_06.Topics1_2Constants;
-import org.apache.ws.notification.base.v2004_6.impl.WsnNamespaceVersionHolderImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Text;
-
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.ws.util.xml.NamespaceContext;
+
+import javax.xml.namespace.QName;
 import java.util.StringTokenizer;
 
 /**
- * Topic expression evalutor for the "Concrete" topic dialect.
+ * Topic expression evalutor for the WS-Topics "Concrete" topic dialect.
  *
  * @see TopicExpressionEvaluator
  */
-public class ConcreteTopicExpressionEvaluator implements TopicExpressionEvaluator
+public class ConcreteTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
 {
 
-    private static final Log LOG =
-        LogFactory.getLog(SimpleTopicExpressionEvaluator.class.getName());
+    //private static final Log LOG = LogFactory.getLog(ConcreteTopicExpressionEvaluator.class.getName());
 
     private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_CONCRETE};
 
-    public Collection resolve(TopicExpression expr,
-                              TopicSpace topicSpace)
+    public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression topicExpr )
         throws UnsupportedTopicExpressionDialectException,
             TopicExpressionResolutionException,
             InvalidTopicExpressionException,
             TopicExpressionException
     {
-        List topicPath = getConcreteTopicPath( expr );
-        LOG.debug("Looking for topic with namespace: " +
-                     topicSpace.getNamespaceURI() + " and local part " +
-                     topicPath.get(0));
-        Collection result = new ArrayList();
-        Topic topic = topicSpace.getTopic(topicPath);
-        if(topic != null)
+        if ( !( topicExpr.getContent() instanceof String ) )
         {
-            result.add(topic);
+            throw new TopicExpressionException( "This evaluator requires the TopicExpression content to be a String." );
         }
-        else
+        if ( !( topicExpr.getNamespaceContext() instanceof NamespaceContext ) )
         {
-            throw new TopicNotSupportedFaultException(new WsnNamespaceVersionHolderImpl(), "Topic expression: " + expr.getContent() + " did not return a valid Topic.");
+            throw new TopicExpressionException(
+                    "This evaluator requires the TopicExpression namespaceContext to be a NamespaceContext." );
         }
-        return result;
-    }
-
-    public String[] getDialects()
-    {
-        return SUPPORTED_DIALECTS;
+        String expr = (String) topicExpr.getContent();
+        if ( StringUtils.isEmpty( expr ) || !StringUtils.containsNone( expr, " \t\n\r\f" ) )
+        {
+            throw new InvalidTopicExpressionException( "Topic expression contains whitespace." );
+        }
+        NamespaceContext nsContext = (NamespaceContext) topicExpr.getNamespaceContext();
+        QName topicPath = toQName( expr, nsContext );
+        Topic topic = evaluateTopicPath( topicSpaceSet, topicPath );
+        return new Topic[] { topic };
     }
 
-    /**
-     * @see TopicExpressionEvaluator#getConcreteTopicPath(org.apache.ws.notification.topics.TopicExpression)
-     */
-    public List getConcreteTopicPath(TopicExpression expr) throws UnsupportedTopicExpressionDialectException, InvalidTopicExpressionException, TopicExpressionException
+    private Topic evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
+            throws TopicExpressionResolutionException, InvalidTopicExpressionException
     {
-        List result = new ArrayList();
-        Text exprText = (Text) expr.getContent();
-        String exprValue = exprText.getNodeValue();
-        exprValue = exprValue.substring(exprValue.indexOf(':') + 1);
-        StringTokenizer tokenizer = new StringTokenizer( exprValue, "/" );
-        if ( tokenizer.countTokens() == 0 )
+        TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicPath.getNamespaceURI() );
+        if ( topicSpace == null )
         {
-            throw new InvalidTopicExpressionFaultException(new WsnNamespaceVersionHolderImpl(), "Topic expression must contain at least one path element." );
+            throw new TopicExpressionResolutionException( "Topic path '" + topicPath.getPrefix() + ":" +
+                    topicPath.getLocalPart() +
+                    "' references an unknown TopicSpace with namespace URI '" +
+                    topicSpace.getTargetNamespace() +
+                    "'." );
         }
-        while ( tokenizer.hasMoreTokens() )
+        // TODO: check for invalid chars in localPart ("//", "*", ".")
+        StringTokenizer pathTokenizer = new StringTokenizer( topicPath.getLocalPart(), "/" );
+        TopicSet topicSet = topicSpace;
+        while ( pathTokenizer.hasMoreTokens() )
         {
-            result.add( tokenizer.nextToken() );
+            String name = pathTokenizer.nextToken();
+            if ( ! topicSet.containsTopic( name ) )
+            {
+                throw new TopicExpressionResolutionException();
+            }
+            topicSet = topicSet.getTopic( name );
         }
-        return result;
+        return (Topic)topicSet;
     }
 
-    public TopicExpression toTopicExpression(List topicPath)
-        throws InvalidTopicExpressionException,
-               TopicExpressionException
+    public String[] getDialects()
     {
-        if(topicPath == null || topicPath.size() != 1)
-        {
-            throw new InvalidTopicExpressionException(
-               "invalidSimpleTopicPath");
-        }
-
-        TopicExpression result = null;
-
-          /*   result = new XmlBeansTopicExpression(); (
-                            Topics1_2Constants.TOPIC_EXPR_DIALECT_SIMPLE,
-                            (QName) topicPath.get(0));*/
-
-        return result;
+        return SUPPORTED_DIALECTS;
     }
 
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluator.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluator.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluator.java Thu Apr 28 18:32:52 2005
@@ -16,12 +16,12 @@
 package org.apache.ws.notification.topics.impl;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.ws.notification.topics.Topic;
 import org.apache.ws.notification.topics.TopicExpression;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
 import org.apache.ws.notification.topics.TopicSet;
 import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
@@ -32,25 +32,25 @@
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.StringTokenizer;
 
 /**
- * Topic expression evalutor for the "Concrete" topic dialect.
+ * Topic expression evalutor for the WS-Topics "Full" topic dialect.
  *
  * @see org.apache.ws.notification.topics.TopicExpressionEvaluator
  */
-public class FullTopicExpressionEvaluator // implements TopicExpressionEvaluator
+public class FullTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
 {
 
-    private static final Log LOG =
-            LogFactory.getLog( FullTopicExpressionEvaluator.class.getName() );
+    //private static final Log LOG = LogFactory.getLog( FullTopicExpressionEvaluator.class.getName() );
 
     private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_FULL};
 
-    public Topic[] resolve( TopicExpression topicExpr,
-                            TopicSet topicSet )
+    public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression topicExpr )
             throws UnsupportedTopicExpressionDialectException,
             TopicExpressionResolutionException,
             InvalidTopicExpressionException,
@@ -70,16 +70,16 @@
         {
             throw new InvalidTopicExpressionException( "Full topic expression contains whitespace." );
         }
+        NamespaceContext nsContext = (NamespaceContext) topicExpr.getNamespaceContext();
         StringTokenizer exprTokenizer = new StringTokenizer( expr, "|" );
         Set allTopics = new HashSet();
-        NamespaceContext nsContext = (NamespaceContext) topicExpr.getNamespaceContext();
         while ( exprTokenizer.hasMoreTokens() )
         {
             QName topicPath = toQName( exprTokenizer.nextToken(), nsContext );
-            List topics = evaluateTopicPath( topicPath, topicSet );
+            List topics = evaluateTopicPath( topicSpaceSet, topicPath );
             allTopics.addAll( topics );
         }
-        if ( topicSet.isFixed() && allTopics.isEmpty() )
+        if ( topicSpaceSet.isFixed() && allTopics.isEmpty() )
         {
             throw new InvalidTopicExpressionException( "Full topic expression '" + expr +
                     "' does not match any topics, and the target topic set is fixed." );
@@ -87,53 +87,151 @@
         return (Topic[]) allTopics.toArray( new Topic[0] );
     }
 
-    private List evaluateTopicPath( QName topicPath, TopicSet topicSet )
-            throws TopicExpressionResolutionException
+    private List evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
+            throws TopicExpressionResolutionException, InvalidTopicExpressionException
     {
         List matchedTopics = new ArrayList();
-        TopicSpace topicSpace = topicSet.getTopicSpace( topicPath.getNamespaceURI() );
+        TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicPath.getNamespaceURI() );
         if ( topicSpace == null )
         {
-            throw new TopicExpressionResolutionException(
-                    "Topic path '" + topicPath.getPrefix() + ":" + topicPath.getLocalPart() +
+            throw new TopicExpressionResolutionException( "Topic path '" + topicPath.getPrefix() + ":" +
+                    topicPath.getLocalPart() +
                     "' references an unknown TopicSpace with namespace URI '" +
-                    topicSpace.getNamespaceURI() +
+                    topicSpace.getTargetNamespace() +
                     "'." );
         }
-        // TODO: parse and resolve localPart of topicPath and build up matchedTopics
+        // TODO: check for invalid chars in localPart ("///")
+        PathTokenizer pathTokenizer = new PathTokenizer( topicPath.getLocalPart() );
+        List topicSets = new ArrayList();
+        topicSets.add( topicSpace );
+        while ( pathTokenizer.hasMoreTokens() )
+        {
+            String pathToken = pathTokenizer.nextToken();
+            matchedTopics.clear();
+            for ( int i = 0; i < topicSets.size(); i++ )
+            {
+                TopicSet topicSet = (TopicSet) topicSets.get( i );
+                boolean recurse = pathToken.startsWith( "/" );
+                String name = recurse ? pathToken.substring( 1 ) : pathToken;
+                matchedTopics.addAll( findTopics( topicSet, name, recurse ) );
+            }
+            topicSets.clear();
+            topicSets.addAll( matchedTopics );
+        }
         return matchedTopics;
     }
 
-    private QName toQName( String topicPath, NamespaceContext nsContext )
-            throws InvalidTopicExpressionException
+    private List findTopics( TopicSet topicSet, String name, boolean recurse ) throws InvalidTopicExpressionException
     {
-        StringTokenizer topicPathTokenizer = new StringTokenizer( topicPath, ":" );
-        if ( topicPathTokenizer.countTokens() == 0 )
+        List matchedTopics = findTopics( topicSet, name );
+        if ( !recurse )
         {
-            throw new InvalidTopicExpressionException( "Topic path '" + topicPath + "' contains no local part." );
+            return matchedTopics;
         }
-        if ( topicPathTokenizer.countTokens() > 2 )
+        List allMatchedTopics = new ArrayList( matchedTopics );
+        for ( int i = 0; i < matchedTopics.size(); i++ )
         {
-            throw new InvalidTopicExpressionException( "Topic path '" + topicPath + "' contains more than one colon." );
+            allMatchedTopics.addAll( findTopics( (Topic) matchedTopics.get( i ), name, recurse ) );
         }
-        String prefix, localPart;
-        if ( topicPathTokenizer.countTokens() == 1 )
+        return allMatchedTopics;
+    }
+
+    private List findTopics( TopicSet topicSet, String name )
+    {
+        List matchedTopics = new ArrayList();
+        if ( name.equals( "*" ) || name.equals( "." ) )
         {
-            prefix = "";
-            localPart = topicPathTokenizer.nextToken();
+            if ( name.equals( "." ) )
+            {
+                matchedTopics.add( topicSet );
+            }
+            Iterator topicIter = topicSet.topicIterator();
+            while ( topicIter.hasNext() )
+            {
+                matchedTopics.add( (Topic) topicIter.next() );
+            }
         }
         else
         {
-            prefix = topicPathTokenizer.nextToken();
-            localPart = topicPathTokenizer.nextToken();
+            if ( topicSet.containsTopic( name ) )
+            {
+                matchedTopics.add( topicSet.getTopic( name ) );
+            }
         }
-        String nsURI = nsContext.getNamespaceURI( prefix );
-        return new QName( localPart, nsURI, prefix );
+        return matchedTopics;
     }
 
     public String[] getDialects()
     {
         return SUPPORTED_DIALECTS;
+    }
+
+    protected class PathTokenizer
+    {
+        private String m_path;
+        private int m_currentPos;
+        private int m_maxPos;
+
+        public PathTokenizer( String path )
+        {
+            m_path = path;
+            m_maxPos = m_path.length();
+        }
+
+        boolean hasMoreTokens()
+        {
+            return m_currentPos < m_maxPos;
+        }
+
+        String nextToken() throws InvalidTopicExpressionException
+        {
+            if ( m_currentPos >= m_maxPos )
+            {
+                throw new NoSuchElementException();
+            }
+            int startPos = m_currentPos;
+            m_currentPos = scanToken( startPos );
+            String token = m_path.substring( startPos, m_currentPos );
+            ++m_currentPos; // skip the slash
+            if ( token.startsWith( "//" ) )
+            {
+                token = token.substring( 1 );
+            }
+            return token;
+        }
+
+        private int scanToken( int startPos ) throws InvalidTopicExpressionException
+        {
+            int newPos = startPos;
+            if ( newPos == 0 )  // special handling for head of path, as per spec
+            {
+                if ( m_path.startsWith( "//" ) )
+                {
+                    newPos += 2;
+                }
+                if ( m_path.charAt( newPos ) == '.' )
+                {
+                    throw new InvalidTopicExpressionException(
+                                "'.' may not be used as the first component of a topic path." );
+                }
+            }
+            else
+            {
+                if ( m_path.charAt( newPos ) == '/' )
+                {
+                    newPos += 1;  // do not count leading slash as a delim
+                }
+            }
+            while ( newPos < m_maxPos )
+            {
+                if ( m_path.charAt( newPos ) == '/' )
+                {
+                    break;
+                }
+                newPos++;
+            }
+            return newPos;
+        }
     }
 
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluator.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluator.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluator.java Thu Apr 28 18:32:52 2005
@@ -15,57 +15,36 @@
  */
 package org.apache.ws.notification.topics.impl;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.ws.notification.topics.Topic;
 import org.apache.ws.notification.topics.TopicExpression;
 import org.apache.ws.notification.topics.TopicExpressionEvaluator;
-import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
 import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
 import org.apache.ws.notification.topics.v2004_06.Topics1_2Constants;
-import org.w3c.dom.Text;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
 
 /**
- * Topic expression evalutor for the "Simple" topic dialect.
+ * Topic expression evalutor for the WS-Topics "Simple" topic dialect.
  *
  * @see TopicExpressionEvaluator
  */
-public class SimpleTopicExpressionEvaluator implements TopicExpressionEvaluator
+public class SimpleTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
 {
-    private static final Log LOG =
-        LogFactory.getLog(SimpleTopicExpressionEvaluator.class.getName());
+
+    //private static final Log LOG = LogFactory.getLog(SimpleTopicExpressionEvaluator.class.getName());
 
     private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_SIMPLE};
 
-    public Collection resolve(TopicExpression expr,
-                              TopicSpace topicSpace)
+    public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression expr )
         throws UnsupportedTopicExpressionDialectException,
                TopicExpressionResolutionException,
                InvalidTopicExpressionException,
                TopicExpressionException
     {
-        List topicPath = getConcreteTopicPath( expr );
-        LOG.debug("Looking for topic with namespace: " +
-                     topicSpace.getNamespaceURI() + " and local part " +
-                     topicPath.get( 0 ) );
-        Collection result = new ArrayList();
-        Topic topic = topicSpace.getTopic(topicPath);
-        if(topic != null)
-        {
-            result.add(topic);
-        }
-        else
-        {
-            throw new TopicExpressionException("Topic expression: " + expr.getContent() + " did not return a valid Topic.");
-        }
-        return result;
+        // TODO
+        return null;
     }
 
     public String[] getDialects()
@@ -73,39 +52,4 @@
         return SUPPORTED_DIALECTS;
     }
 
-    /**
-     * @see TopicExpressionEvaluator#getConcreteTopicPath(org.apache.ws.notification.topics.TopicExpression)
-     */
-    public List getConcreteTopicPath(TopicExpression expr) throws UnsupportedTopicExpressionDialectException, InvalidTopicExpressionException, TopicExpressionException
-    {
-        List result = new ArrayList();
-        Text exprText = (Text) expr.getContent();
-        String exprValue = exprText.getNodeValue();
-        if ( exprValue.indexOf( '/' ) != -1 )
-        {
-            throw new InvalidTopicExpressionException( "Simple topic expressions must not contain slashes." );
-        }
-        exprValue = exprValue.substring(exprValue.indexOf(':') + 1);
-        result.add( exprValue );
-        return result;
-    }
-
-    public TopicExpression toTopicExpression(List topicPath)
-        throws InvalidTopicExpressionException,
-               TopicExpressionException
-    {
-        if(topicPath == null || topicPath.size() != 1)
-        {
-            throw new InvalidTopicExpressionException(
-               "invalidSimpleTopicPath");
-        }
-
-        TopicExpression result = null;
-
-          /*   result = new XmlBeansTopicExpression(); (
-                            Topics1_2Constants.TOPIC_EXPR_DIALECT_SIMPLE,
-                            (QName) topicPath.get(0));*/
-
-        return result;
-    }
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicExpressionEngineImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicExpressionEngineImpl.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicExpressionEngineImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicExpressionEngineImpl.java Thu Apr 28 18:32:52 2005
@@ -17,35 +17,33 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ws.notification.base.v2004_6.impl.WsnNamespaceVersionHolderImpl;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicExpression;
 import org.apache.ws.notification.topics.TopicExpressionEngine;
 import org.apache.ws.notification.topics.TopicExpressionEvaluator;
-import org.apache.ws.notification.topics.TopicExpression;
-import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
 import org.apache.ws.notification.topics.impl.faults.TopicPathDialectUnknownFaultException;
-import org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException;
 import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
 import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
-import org.apache.ws.notification.base.v2004_6.impl.WsnNamespaceVersionHolderImpl;
-import org.apache.ws.util.jndi.JNDIUtils;
 import org.apache.ws.resource.JndiConstants;
+import org.apache.ws.util.jndi.JNDIUtils;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 /**
  * Resolves topic expressions over topic lists. The engine looks for topic expression evaluators under
  * "wsrf/topic/eval" context.
  *
- * @see org.apache.ws.notification.topics.TopicSet
+ * @see org.apache.ws.notification.topics.TopicSpaceSet
  */
 public class TopicExpressionEngineImpl implements TopicExpressionEngine
 {
@@ -68,17 +66,16 @@
      */
     public static TopicExpressionEngine getInstance()
     {
-        Context context = null;
         try
         {
-            context = new InitialContext();
+            Context context = new InitialContext();
             return (TopicExpressionEngine) context.lookup( JndiConstants.KEY_NAME_DEFAULT_TOPIC_EXPRESSION_ENGINE );
         }
-        catch ( NamingException e )
+        catch ( NamingException ne )
         {
-            LOG.error( "topicEngineConfigError" + e );
+            LOG.warn( "topicEngineConfigError: " + ne );
+            return new TopicExpressionEngineImpl();
         }
-        return null;
     }
 
     /**
@@ -87,26 +84,25 @@
      */
     public synchronized void refresh()
     {
-        this.m_evaluators.clear();
+        m_evaluators.clear();
         NamingEnumeration list = null;
         try
         {
             Context context = new InitialContext();
             list = context.list( JndiConstants.TOPIC_EXPRESSION_EVALUATOR_CONTEXT );
-            NameClassPair pair = null;
-            TopicExpressionEvaluator evaluator = null;
             while ( list.hasMore() )
             {
-                pair = (NameClassPair) list.next();
-                evaluator = (TopicExpressionEvaluator) JNDIUtils.lookup( context,
+                NameClassPair pair = (NameClassPair) list.next();
+                TopicExpressionEvaluator evaluator = (TopicExpressionEvaluator) JNDIUtils.lookup( context,
                         JndiConstants.TOPIC_EXPRESSION_EVALUATOR_CONTEXT + "/" + pair.getName(),
                         TopicExpressionEvaluator.class );
-                this.registerEvaluator( evaluator );
+                registerEvaluator( evaluator );
             }
         }
-        catch ( NamingException e )
+        catch ( NamingException ne )
         {
-            LOG.error( "topicEngineInitError" + e );
+            LOG.warn( "topicEngineInitError: " + ne );
+            registerEvaluator( new FullTopicExpressionEvaluator() );
         }
         finally
         {
@@ -116,7 +112,7 @@
                 {
                     list.close();
                 }
-                catch ( NamingException ee )
+                catch ( NamingException ne )
                 {
                 }
             }
@@ -141,8 +137,8 @@
         return evaluator;
     }
 
-    public synchronized Collection resolveTopicExpression( TopicExpression topicExpression,
-                                                           TopicSpace topicSpace )
+    public synchronized Topic[] evaluateTopicExpression( TopicSpaceSet topicSpaceSet,
+                                                            TopicExpression topicExpression )
             throws org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException,
             TopicExpressionResolutionException,
             InvalidTopicExpressionException,
@@ -184,36 +180,7 @@
             }
             throw new TopicPathDialectUnknownFaultException(new WsnNamespaceVersionHolderImpl(), "The dialect: " + dialect + " was unrecognized.");
         }
-        return evaluator.resolve( topicExpression, topicSpace );
-    }
-
-    public synchronized List getConcretePath( TopicExpression topicExpression )
-            throws org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException,
-            TopicExpressionResolutionException,
-            InvalidTopicExpressionException,
-            TopicExpressionException
-    {
-        if ( topicExpression == null )
-        {
-            throw new org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException(
-                    "nullArgument"+ "topicExpression" );
-        }
-
-        if ( topicExpression.getDialect() == null )
-        {
-            throw new org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException(
-                     "nullArgument"+ "topicExpression.dialect" );
-        }
-
-        String dialect = topicExpression.getDialect().toString();
-        TopicExpressionEvaluator evaluator = this.getEvaluator( dialect );
-
-        if ( evaluator == null )
-        {
-            throw new org.apache.ws.notification.topics.topicexpression.impl.UnsupportedTopicExpressionDialectException();
-        }
-
-        return evaluator.getConcreteTopicPath( topicExpression );
+        return evaluator.evaluate( topicSpaceSet, topicExpression );
     }
 
     public synchronized String[] getSupportedDialects()

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java Thu Apr 28 18:32:52 2005
@@ -40,12 +40,13 @@
     protected TopicExpression m_reference;
     protected Collection m_listeners;
     protected String m_name;
-    protected Object m_current;
+    protected Object m_currentMsg;
     protected List m_topicPath; // ordered set of QNames
     protected TopicSpace m_topicSpace;
     private static final Log LOG = LogFactory.getLog( TopicImpl.class.getName() );
 
-    public void addTopic( Topic topic ) throws Exception
+    // TODO: throw more specific exceptions
+    public Topic addTopic( Topic topic ) throws Exception
     {
         if ( m_reference != null )
         {
@@ -61,10 +62,21 @@
 
         topic.setTopicPath( topicPath );
         topic.addTopicListener( this );
-        
+
         topic.setTopicSpace(m_topicSpace);
-        
+
         this.topicAdded( topic );
+        return topic;
+    }
+
+    public Topic addTopic( String name ) throws Exception
+    {
+        return addTopic( new TopicImpl( name ) );
+    }
+
+    public void removeTopic( String name )
+    {
+        m_subTopics.remove( name );
     }
 
     public synchronized void addTopicListener( TopicListener listener )
@@ -82,6 +94,11 @@
         return (Topic) m_subTopics.get( topicName );
     }
 
+    public boolean containsTopic( String name )
+    {
+        return m_subTopics.containsKey( name );
+    }
+
     /**
      * Get the topic expression for the topic(s) that this topic references.
      *
@@ -104,7 +121,7 @@
 
     public void publish( Object obj ) throws Exception
     {
-        m_current = obj;
+        m_currentMsg = obj;
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "Notify called on topic " +
@@ -115,7 +132,7 @@
 
     public Object getCurrentMessage()
     {
-        return m_current;
+        return m_currentMsg;
     }
 
     public void removeTopic( Topic topic )
@@ -178,7 +195,7 @@
         this.m_reference = reference;
         this.m_listeners = listeners;
         this.m_name = name;
-        this.m_current = current;
+        this.m_currentMsg = current;
         if(topicPath==null){
             this.m_topicPath = new java.util.LinkedList();
             m_topicPath.add(name);
@@ -221,7 +238,8 @@
 
     public Topic getParent()
     {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO
+        return null;
     }
     
     public String toString(){
@@ -234,5 +252,6 @@
     
     public TopicSpace getTopicSpace() {
         return m_topicSpace;
-    }   
+    }
+    
 }

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java Thu Apr 28 18:32:52 2005
@@ -16,17 +16,11 @@
 package org.apache.ws.notification.topics.impl;
 
 import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.TopicExpression;
-import org.apache.ws.notification.topics.TopicExpressionEngine;
 import org.apache.ws.notification.topics.TopicListener;
 import org.apache.ws.notification.topics.TopicSpace;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
-import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionResolutionException;
 
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -34,60 +28,57 @@
  */
 public class TopicSpaceImpl implements TopicSpace
 {
-    private String m_namespaceURI;
+
+    private String m_targetNs;
+    private String m_name = "TopicSpace";
     private Map m_rootTopicMap = new HashMap();
-    private static TopicExpressionEngine m_topicExpressionEngine =
-            TopicExpressionEngineImpl.getInstance();
 
-    public TopicSpaceImpl( String namespaceURI )
+
+    public TopicSpaceImpl( String targetNs )
+    {
+        m_targetNs = targetNs;
+    }
+
+    public String getTargetNamespace()
     {
-        m_namespaceURI = namespaceURI;
+        return m_targetNs;
     }
 
-    public String getNamespaceURI()
+    public String getName()
     {
-        return m_namespaceURI;
+        return m_name;
     }
 
-    public void addTopic( Topic topic )
+    public void setName( String name )
+    {
+        m_name = name;
+    }
+
+    public Topic addTopic( Topic topic )
     {
         m_rootTopicMap.put( topic.getName(), topic );
         topic.setTopicSpace(this);
+        return topic;
     }
 
-    public void removeTopic( Topic topic )
+    public Topic addTopic( String name ) throws Exception
     {
-        m_rootTopicMap.remove( topic.getName() );
+        return addTopic( new TopicImpl( name ) );
     }
 
-    public Collection getTopics( TopicExpression topicExpression ) throws TopicExpressionException,
-            TopicExpressionResolutionException
+    public void removeTopic( String name )
     {
-        return m_topicExpressionEngine.resolveTopicExpression( topicExpression, this );
-    }
-
-    public Topic getTopic( List topicPath )
-    {
-        Topic topic = null;
-        Iterator pathItemIter = topicPath.iterator();
-        if ( pathItemIter.hasNext() )
-        {
-            String rootTopicName = (String) pathItemIter.next();
-            topic = (Topic) m_rootTopicMap.get( rootTopicName );
-        }
-        if ( topic != null )
-        {
-            while ( pathItemIter.hasNext() )
-            {
-                String topicName = (String) pathItemIter.next();
-                topic = topic.getTopic( topicName );
-                if ( topic == null )
-                {
-                    break;
-                }
-            }
-        }
-        return topic;
+        m_rootTopicMap.remove( name );
+    }
+
+    public Topic getTopic( String name )
+    {
+        return (Topic) m_rootTopicMap.get( name );
+    }
+
+    public boolean containsTopic( String name )
+    {
+        return m_rootTopicMap.containsKey( name );
     }
 
     public Iterator topicIterator()
@@ -109,4 +100,5 @@
     {
         return null;  // TODO: either remove, or implement
     }
+
 }

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java?rev=165250&view=auto
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java Thu Apr 28 18:32:52 2005
@@ -0,0 +1,89 @@
+package org.apache.ws.notification.topics.impl;
+
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicExpression;
+import org.apache.ws.notification.topics.TopicExpressionEngine;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.topicexpression.impl.TopicExpressionException;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Sal Campana
+ */
+public class TopicSpaceSetImpl implements TopicSpaceSet
+{
+
+    private static final TopicExpressionEngine TOPIC_EXPR_ENGINE =
+            TopicExpressionEngineImpl.getInstance();  // TODO: look up from JNDI
+
+    private Map m_topicSpaces = new Hashtable();
+    private boolean m_fixed;
+
+    public TopicSpaceSetImpl( boolean fixed )
+    {
+        m_fixed = fixed;
+    }
+
+    /**
+     * Adds the TopicSpace to the TopicSpaceSet.
+     *
+     * Note. If the TopiSpace already exists, this method will add all the known Topics
+     * to the passed-in TopicSpace and set it as the current TopicSpace in the TopicSpaceSet.
+     * This will ensure there is only 1 TopicSpace in the set and it is complete...
+     *
+     * @param topicSpace
+     */
+    // TODO: throw more specific exceptions
+    public TopicSpace addTopicSpace(TopicSpace topicSpace) throws Exception
+    {
+        String namespaceURI = topicSpace.getTargetNamespace();
+        //if topicSpace exists, simply add all topics to topicspace
+        if(m_topicSpaces.containsKey(namespaceURI))
+        {
+            TopicSpace topicSpc = (TopicSpace) m_topicSpaces.get(namespaceURI);
+            Iterator iterator = topicSpc.topicIterator();
+            while (iterator.hasNext())
+            {
+                Topic topic = (Topic) iterator.next();
+                topicSpace.addTopic(topic);
+            }
+        }
+        m_topicSpaces.put(namespaceURI, topicSpace);
+        return topicSpace;
+    }
+
+    public void removeTopicSpace(String namespaceURI)
+    {
+        m_topicSpaces.remove(namespaceURI);
+    }
+
+    public TopicSpace getTopicSpace(String namespaceURI)
+    {
+        return (TopicSpace) m_topicSpaces.get(namespaceURI);
+    }
+
+    public TopicSpace[] getTopicSpaces()
+    {
+        return (TopicSpace[]) m_topicSpaces.values().toArray(new TopicSpace[0]);
+    }
+
+    public Topic[] evaluateTopicExpression(TopicExpression topicExpr)
+            throws TopicExpressionException
+    {
+        return TOPIC_EXPR_ENGINE.evaluateTopicExpression( this, topicExpr );
+    }
+
+    public boolean isFixed()
+    {
+        return m_fixed;
+    }
+
+    public void setFixed( boolean fixed )
+    {
+        m_fixed = fixed;
+    }
+}



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