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/30 01:22:00 UTC

svn commit: r165359 - in /incubator/hermes/trunk/src: java/org/apache/ws/notification/base/v2004_6/impl/ java/org/apache/ws/notification/base/v2004_6/porttype/impl/ java/org/apache/ws/notification/topics/impl/ java/org/apache/ws/notification/topics/v2004_06/ test/org/apache/ws/notification/topics/impl/

Author: ips
Date: Fri Apr 29 16:21:59 2005
New Revision: 165359

URL: http://svn.apache.org/viewcvs?rev=165359&view=rev
Log:
finished unit testcase for full topic expression evaluator; refactored simple and concrete expression evaluators

Added:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/TopicsConstants.java
Removed:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/Topics1_2Constants.java
Modified:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/impl/WsnNamespaceVersionHolderImpl.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/impl/AbstractTopicExpressionEvaluator.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/TopicSpaceSetImpl.java
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/impl/WsnNamespaceVersionHolderImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/impl/WsnNamespaceVersionHolderImpl.java?rev=165359&r1=165358&r2=165359&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/impl/WsnNamespaceVersionHolderImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/base/v2004_6/impl/WsnNamespaceVersionHolderImpl.java Fri Apr 29 16:21:59 2005
@@ -2,7 +2,7 @@
 
 import org.apache.ws.notification.base.WsnNamespaceVersionHolder;
 import org.apache.ws.notification.base.v2004_6.BaseNotificationConstants;
-import org.apache.ws.notification.topics.v2004_06.Topics1_2Constants;
+import org.apache.ws.notification.topics.v2004_06.TopicsConstants;
 import org.apache.ws.resource.properties.v2004_06.impl.NamespaceVersionHolderImpl;
 
 
@@ -13,7 +13,7 @@
 {
     public String getTopicsXsdNamespace()
     {
-        return Topics1_2Constants.NSURI_WSTOP_SCHEMA;
+        return TopicsConstants.NSURI_WSTOP_SCHEMA;
     }
 
     public String getBaseNotificationXsdNamespace()

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=165359&r1=165358&r2=165359&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 Fri Apr 29 16:21:59 2005
@@ -216,12 +216,14 @@
      *
      * @param notificationConsumer
      * @param subscriptionEndConsumer the callback Interface for SubscriptionEnd Notifications, or null if no SubscriptionEnd should be send
-     * @param filters
+     * @param tf
+     * @param xf
      * @param initialTerminationTime
-     * @param deliveryMode            the notification delivery mode, or null to use default mode
+     * @param useNotify
+     *
      * @return the subscription
      */
-    public org.apache.ws.pubsub.Subscription subscribe(NotificationConsumer notificationConsumer, SubscriptionEndConsumer subscriptionEndConsumer, TopicFilter tf, XPathFilter xf, Calendar initialTerminationTime, boolean UseNotify)
+    public org.apache.ws.pubsub.Subscription subscribe(NotificationConsumer notificationConsumer, SubscriptionEndConsumer subscriptionEndConsumer, TopicFilter tf, XPathFilter xf, Calendar initialTerminationTime, boolean useNotify)
     {
         return null;    //todo
     }

Modified: 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=165359&r1=165358&r2=165359&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/AbstractTopicExpressionEvaluator.java Fri Apr 29 16:21:59 2005
@@ -17,16 +17,67 @@
 
 import org.apache.ws.util.xml.NamespaceContext;
 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;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.commons.lang.StringUtils;
 
 import javax.xml.namespace.QName;
 import java.util.StringTokenizer;
 
 /**
- * TODO
+ * An abstract class that provides functionality that is shared by the
+ * {@link TopicExpressionEvaluator}s for all three WS-Topics topic expression
+ * dialects.
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
  */
-public abstract class AbstractTopicExpressionEvaluator
+public abstract class AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
 {
 
+    protected NamespaceContext getNamespaceContext( TopicExpression topicExpr ) throws TopicExpressionException
+    {
+        if ( !( topicExpr.getNamespaceContext() instanceof NamespaceContext ) )
+        {
+            throw new TopicExpressionException(
+                    "This evaluator requires the TopicExpression namespaceContext to be a NamespaceContext." );
+        }
+        return (NamespaceContext) topicExpr.getNamespaceContext();
+    }
+
+    protected String getContent( TopicExpression topicExpr )
+            throws TopicExpressionException
+    {
+        if ( !( topicExpr.getContent() instanceof String ) )
+        {
+            throw new TopicExpressionException( "This evaluator requires the TopicExpression content to be a String." );
+        }
+        String expr = (String) topicExpr.getContent();
+        if ( StringUtils.isEmpty( expr ) || !StringUtils.containsNone( expr, " \t\n\r\f" ) )
+        {
+            throw new InvalidTopicExpressionException( "Full topic expression contains whitespace." );
+        }
+        return expr;
+    }
+
+    protected TopicSpace getTopicSpace( TopicSpaceSet topicSpaceSet, QName topicPath )
+            throws TopicExpressionResolutionException
+    {
+        TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicPath.getNamespaceURI() );
+        if ( topicSpace == null )
+        {
+            throw new TopicExpressionResolutionException( "Topic path '" + topicPath.getPrefix() + ":" +
+                    topicPath.getLocalPart() +
+                    "' references an unknown TopicSpace with namespace URI '" +
+                    topicPath.getNamespaceURI() +
+                    "'." );
+        }
+        return topicSpace;
+    }
+
     protected QName toQName( String topicPath, NamespaceContext nsContext )
             throws InvalidTopicExpressionException
     {
@@ -53,5 +104,5 @@
         String nsURI = nsContext.getNamespaceURI( prefix );
         return new QName( nsURI, localPart, prefix );
     }
-    
+
 }

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=165359&r1=165358&r2=165359&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 Fri Apr 29 16:21:59 2005
@@ -15,7 +15,6 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics.impl;
 
-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;
@@ -26,23 +25,27 @@
 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.topics.v2004_06.TopicsConstants;
 import org.apache.ws.util.xml.NamespaceContext;
 
 import javax.xml.namespace.QName;
 import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Topic expression evalutor for the WS-Topics "Concrete" topic dialect.
  *
  * @see TopicExpressionEvaluator
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
  */
-public class ConcreteTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
+public class ConcreteTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator
 {
 
     //private static final Log LOG = LogFactory.getLog(ConcreteTopicExpressionEvaluator.class.getName());
 
-    private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_CONCRETE};
+    private static final String[] SUPPORTED_DIALECTS = {TopicsConstants.TOPIC_EXPR_DIALECT_CONCRETE};
 
     public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression topicExpr )
         throws UnsupportedTopicExpressionDialectException,
@@ -50,56 +53,46 @@
             InvalidTopicExpressionException,
             TopicExpressionException
     {
-        if ( !( topicExpr.getContent() instanceof String ) )
-        {
-            throw new TopicExpressionException( "This evaluator requires the TopicExpression content to be a String." );
-        }
-        if ( !( topicExpr.getNamespaceContext() instanceof NamespaceContext ) )
-        {
-            throw new TopicExpressionException(
-                    "This evaluator requires the TopicExpression namespaceContext to be a NamespaceContext." );
-        }
-        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();
+        String expr = getContent( topicExpr );
+        NamespaceContext nsContext = getNamespaceContext( topicExpr );
         QName topicPath = toQName( expr, nsContext );
-        Topic topic = evaluateTopicPath( topicSpaceSet, topicPath );
-        return new Topic[] { topic };
+        List matchedTopics = evaluateTopicPath( topicSpaceSet, topicPath );
+        return (Topic[]) matchedTopics.toArray( new Topic[0] );
     }
 
-    private Topic evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
+    public String[] getDialects()
+    {
+        return SUPPORTED_DIALECTS;
+    }
+
+    private List evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
             throws TopicExpressionResolutionException, InvalidTopicExpressionException
     {
-        TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicPath.getNamespaceURI() );
-        if ( topicSpace == null )
+        List matchedTopics = new ArrayList();
+        TopicSpace topicSpace = getTopicSpace( topicSpaceSet, topicPath );
+        if ( topicPath.getLocalPart().indexOf( "//" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "*" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "|" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "." ) != -1 )
         {
-            throw new TopicExpressionResolutionException( "Topic path '" + topicPath.getPrefix() + ":" +
-                    topicPath.getLocalPart() +
-                    "' references an unknown TopicSpace with namespace URI '" +
-                    topicSpace.getTargetNamespace() +
-                    "'." );
+            throw new InvalidTopicExpressionException( "Topic path '" + topicPath +
+                    "' contains one or more illegal characters ('//', '*', '|' or '.')." );
         }
-        // TODO: check for invalid chars in localPart ("//", "*", ".")
         StringTokenizer pathTokenizer = new StringTokenizer( topicPath.getLocalPart(), "/" );
         TopicSet topicSet = topicSpace;
+        boolean resolvedPath = true;
         while ( pathTokenizer.hasMoreTokens() )
         {
             String name = pathTokenizer.nextToken();
             if ( ! topicSet.containsTopic( name ) )
             {
-                throw new TopicExpressionResolutionException();
+                resolvedPath = false;
+                break;
             }
             topicSet = topicSet.getTopic( name );
         }
-        return (Topic)topicSet;
-    }
-
-    public String[] getDialects()
-    {
-        return SUPPORTED_DIALECTS;
+        if ( resolvedPath ) { matchedTopics.add( topicSet ); }
+        return matchedTopics;
     }
 
 }

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=165359&r1=165358&r2=165359&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 Fri Apr 29 16:21:59 2005
@@ -15,7 +15,6 @@
  *=============================================================================*/
 package org.apache.ws.notification.topics.impl;
 
-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;
@@ -26,7 +25,7 @@
 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.topics.v2004_06.TopicsConstants;
 import org.apache.ws.util.xml.NamespaceContext;
 
 import javax.xml.namespace.QName;
@@ -41,14 +40,16 @@
 /**
  * Topic expression evalutor for the WS-Topics "Full" topic dialect.
  *
- * @see org.apache.ws.notification.topics.TopicExpressionEvaluator
+ * @see TopicExpressionEvaluator
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
  */
-public class FullTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
+public class FullTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator
 {
 
     //private static final Log LOG = LogFactory.getLog( FullTopicExpressionEvaluator.class.getName() );
 
-    private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_FULL};
+    private static final String[] SUPPORTED_DIALECTS = {TopicsConstants.TOPIC_EXPR_DIALECT_FULL};
 
     public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression topicExpr )
             throws UnsupportedTopicExpressionDialectException,
@@ -56,82 +57,83 @@
             InvalidTopicExpressionException,
             TopicExpressionException
     {
-        if ( !( topicExpr.getContent() instanceof String ) )
-        {
-            throw new TopicExpressionException( "This evaluator requires the TopicExpression content to be a String." );
-        }
-        if ( !( topicExpr.getNamespaceContext() instanceof NamespaceContext ) )
-        {
-            throw new TopicExpressionException(
-                    "This evaluator requires the TopicExpression namespaceContext to be a NamespaceContext." );
-        }
-        String expr = (String) topicExpr.getContent();
-        if ( StringUtils.isEmpty( expr ) || !StringUtils.containsNone( expr, " \t\n\r\f" ) )
-        {
-            throw new InvalidTopicExpressionException( "Full topic expression contains whitespace." );
-        }
-        NamespaceContext nsContext = (NamespaceContext) topicExpr.getNamespaceContext();
+        String expr = getContent( topicExpr );
+        NamespaceContext nsContext = getNamespaceContext( topicExpr );
         StringTokenizer exprTokenizer = new StringTokenizer( expr, "|" );
-        Set allTopics = new HashSet();
+        Set allMatchedTopics = new HashSet();
         while ( exprTokenizer.hasMoreTokens() )
         {
             QName topicPath = toQName( exprTokenizer.nextToken(), nsContext );
-            List topics = evaluateTopicPath( topicSpaceSet, topicPath );
-            allTopics.addAll( topics );
+            List matchedTopics = evaluateTopicPath( topicSpaceSet, topicPath );
+            allMatchedTopics.addAll( matchedTopics );
         }
-        if ( topicSpaceSet.isFixed() && allTopics.isEmpty() )
+        if ( topicSpaceSet.isFixed() && allMatchedTopics.isEmpty() )
         {
             throw new InvalidTopicExpressionException( "Full topic expression '" + expr +
                     "' does not match any topics, and the target topic set is fixed." );
         }
-        return (Topic[]) allTopics.toArray( new Topic[0] );
+        return (Topic[]) allMatchedTopics.toArray( new Topic[0] );
+    }
+
+    public String[] getDialects()
+    {
+        return SUPPORTED_DIALECTS;
     }
 
     private List evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
             throws TopicExpressionResolutionException, InvalidTopicExpressionException
     {
         List matchedTopics = new ArrayList();
-        TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicPath.getNamespaceURI() );
-        if ( topicSpace == null )
+        TopicSpace topicSpace = getTopicSpace( topicSpaceSet, topicPath );
+        if ( topicPath.getLocalPart().indexOf( "///" ) != -1 )
         {
-            throw new TopicExpressionResolutionException( "Topic path '" + topicPath.getPrefix() + ":" +
-                    topicPath.getLocalPart() +
-                    "' references an unknown TopicSpace with namespace URI '" +
-                    topicSpace.getTargetNamespace() +
-                    "'." );
+            throw new InvalidTopicExpressionException( "Topic path '" + topicPath +
+                    "' contains an empty path component." );
         }
-        // TODO: check for invalid chars in localPart ("///")
         PathTokenizer pathTokenizer = new PathTokenizer( topicPath.getLocalPart() );
-        List topicSets = new ArrayList();
-        topicSets.add( topicSpace );
+        List topicSetsToSearch = new ArrayList();
+        topicSetsToSearch.add( topicSpace );
+        boolean atFirstToken = true;
         while ( pathTokenizer.hasMoreTokens() )
         {
             String pathToken = pathTokenizer.nextToken();
             matchedTopics.clear();
-            for ( int i = 0; i < topicSets.size(); i++ )
+            for ( int i = 0; i < topicSetsToSearch.size(); i++ )
             {
-                TopicSet topicSet = (TopicSet) topicSets.get( i );
+                TopicSet topicSetToSearch = (TopicSet) topicSetsToSearch.get( i );
                 boolean recurse = pathToken.startsWith( "/" );
                 String name = recurse ? pathToken.substring( 1 ) : pathToken;
-                matchedTopics.addAll( findTopics( topicSet, name, recurse ) );
+                matchedTopics.addAll( findTopics( topicSetToSearch, name, recurse ) );
             }
-            topicSets.clear();
-            topicSets.addAll( matchedTopics );
+            if ( atFirstToken && matchedTopics.isEmpty() )
+            {
+                throw new InvalidTopicExpressionException( "Topic path '" + topicPath +
+                        "' refers to a root topic that is not defined in the referenced topic space." );
+            }
+            topicSetsToSearch.clear();
+            topicSetsToSearch.addAll( matchedTopics );
+            atFirstToken = false;
         }
         return matchedTopics;
     }
 
     private List findTopics( TopicSet topicSet, String name, boolean recurse ) throws InvalidTopicExpressionException
     {
-        List matchedTopics = findTopics( topicSet, name );
-        if ( !recurse )
+        List allMatchedTopics = new ArrayList();
+        if ( name.equals( "." ) )
         {
-            return matchedTopics;
+            allMatchedTopics.add( topicSet );
+            name = "*";  // we only want to evaluate "." the first time through during recursion
         }
-        List allMatchedTopics = new ArrayList( matchedTopics );
-        for ( int i = 0; i < matchedTopics.size(); i++ )
+        List matchedTopics = findTopics( topicSet, name );
+        allMatchedTopics.addAll( matchedTopics );
+        if ( recurse )
         {
-            allMatchedTopics.addAll( findTopics( (Topic) matchedTopics.get( i ), name, recurse ) );
+            Iterator topicIter = topicSet.topicIterator();
+            while ( topicIter.hasNext() )
+            {
+                allMatchedTopics.addAll( findTopics( (Topic) topicIter.next(), name, recurse ) );
+            }
         }
         return allMatchedTopics;
     }
@@ -139,12 +141,8 @@
     private List findTopics( TopicSet topicSet, String name )
     {
         List matchedTopics = new ArrayList();
-        if ( name.equals( "*" ) || name.equals( "." ) )
+        if ( name.equals( "*" ) )
         {
-            if ( name.equals( "." ) )
-            {
-                matchedTopics.add( topicSet );
-            }
             Iterator topicIter = topicSet.topicIterator();
             while ( topicIter.hasNext() )
             {
@@ -161,11 +159,6 @@
         return matchedTopics;
     }
 
-    public String[] getDialects()
-    {
-        return SUPPORTED_DIALECTS;
-    }
-
     protected class PathTokenizer
     {
         private String m_path;
@@ -178,12 +171,12 @@
             m_maxPos = m_path.length();
         }
 
-        boolean hasMoreTokens()
+        public boolean hasMoreTokens()
         {
             return m_currentPos < m_maxPos;
         }
 
-        String nextToken() throws InvalidTopicExpressionException
+        public String nextToken() throws InvalidTopicExpressionException
         {
             if ( m_currentPos >= m_maxPos )
             {
@@ -192,11 +185,11 @@
             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 );
             }
+            ++m_currentPos; // skip the slash
             return token;
         }
 
@@ -212,7 +205,7 @@
                 if ( m_path.charAt( newPos ) == '.' )
                 {
                     throw new InvalidTopicExpressionException(
-                                "'.' may not be used as the first component of a topic path." );
+                            "'.' may not be used as the first component of a topic path." );
                 }
             }
             else

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=165359&r1=165358&r2=165359&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 Fri Apr 29 16:21:59 2005
@@ -18,38 +18,71 @@
 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.apache.ws.notification.topics.v2004_06.TopicsConstants;
+import org.apache.ws.util.xml.NamespaceContext;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Topic expression evalutor for the WS-Topics "Simple" topic dialect.
  *
  * @see TopicExpressionEvaluator
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
  */
-public class SimpleTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator implements TopicExpressionEvaluator
+public class SimpleTopicExpressionEvaluator extends AbstractTopicExpressionEvaluator
 {
 
     //private static final Log LOG = LogFactory.getLog(SimpleTopicExpressionEvaluator.class.getName());
 
-    private static final String[] SUPPORTED_DIALECTS = {Topics1_2Constants.TOPIC_EXPR_DIALECT_SIMPLE};
+    private static final String[] SUPPORTED_DIALECTS = {TopicsConstants.TOPIC_EXPR_DIALECT_SIMPLE};
 
-    public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression expr )
+    public Topic[] evaluate( TopicSpaceSet topicSpaceSet, TopicExpression topicExpr )
         throws UnsupportedTopicExpressionDialectException,
                TopicExpressionResolutionException,
                InvalidTopicExpressionException,
                TopicExpressionException
     {
-        // TODO
-        return null;
+        String expr = getContent( topicExpr );
+        NamespaceContext nsContext = getNamespaceContext( topicExpr );
+        QName topicPath = toQName( expr, nsContext );
+        List matchedTopics = evaluateTopicPath( topicSpaceSet, topicPath );
+        return (Topic[]) matchedTopics.toArray( new Topic[0] );
     }
 
     public String[] getDialects()
     {
         return SUPPORTED_DIALECTS;
+    }
+
+    private List evaluateTopicPath( TopicSpaceSet topicSpaceSet, QName topicPath )
+            throws TopicExpressionResolutionException, InvalidTopicExpressionException
+    {
+        List matchedTopics = new ArrayList();
+        TopicSpace topicSpace = getTopicSpace( topicSpaceSet, topicPath );
+        if ( topicPath.getLocalPart().indexOf( "/" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "*" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "|" ) != -1 ||
+             topicPath.getLocalPart().indexOf( "." ) != -1 )
+        {
+            throw new InvalidTopicExpressionException( "Topic path '" + topicPath +
+                    "' contains one or more illegal characters ('/', '*', '|' or '.')." );
+        }
+        String name = topicPath.getLocalPart();
+        Topic topic = topicSpace.getTopic( name );
+        if ( topic != null )
+        {
+            matchedTopics.add( topic );
+        }
+        return matchedTopics;
     }
 
 }

Modified: 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=165359&r1=165358&r2=165359&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java Fri Apr 29 16:21:59 2005
@@ -82,7 +82,7 @@
         return m_fixed;
     }
 
-    public void setFixed( boolean fixed )
+    void setFixed( boolean fixed )
     {
         m_fixed = fixed;
     }

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/TopicsConstants.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/TopicsConstants.java?rev=165359&view=auto
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/TopicsConstants.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/v2004_06/TopicsConstants.java Fri Apr 29 16:21:59 2005
@@ -0,0 +1,49 @@
+/*=============================================================================*
+ *  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.v2004_06;
+
+/**
+ * Constants defined by the WS-Topics 1.2 specification.
+ */
+public interface TopicsConstants
+{
+
+    /**
+     * Namespace URI of the WS-Topics 1.2 schema.
+     */
+    String NSURI_WSTOP_SCHEMA = "http://docs.oasis-open.org/wsn/2004/06/wsn-WS-Topics-1.2-draft-01.xsd";
+
+    /**
+     * Namespace prefix of the WS-Topics 1.2 schema.
+     */
+    String NSPREFIX_WSTOP_SCHEMA = "wstop";
+
+    /**
+     * URI of the "Simple" topic expression dialect.
+     */
+    String TOPIC_EXPR_DIALECT_SIMPLE = "http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Simple";
+
+    /**
+     * URI of the "Concrete" topic expression dialect.
+     */
+    String TOPIC_EXPR_DIALECT_CONCRETE = "http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Concrete";
+
+    /**
+     * URI of the "Full" topic expression dialect.
+     */
+    String TOPIC_EXPR_DIALECT_FULL = "http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full";
+
+}

Modified: incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java?rev=165359&r1=165358&r2=165359&view=diff
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java (original)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java Fri Apr 29 16:21:59 2005
@@ -68,6 +68,10 @@
         resultTopics = evaluate( NSPREFIX1 + ":sports/tennis" );
         assertEquals( 1, resultTopics.length );
         assertContainsTopic( resultTopics, "tennis" );
+
+        ((TopicSpaceSetImpl)m_topicSpaceSet).setFixed( false );
+        resultTopics = evaluate( NSPREFIX1 + ":sports/baseball" );
+        assertEquals( 0, resultTopics.length );
     }
 
     public void testEvaluateWildcard() throws Exception
@@ -86,6 +90,16 @@
         assertContainsTopic( resultTopics, "tennis" );
         assertContainsTopic( resultTopics, "football" );
 
+        resultTopics = evaluate( NSPREFIX1 + ":sports/." );
+        assertEquals( 3, resultTopics.length );
+        assertContainsTopic( resultTopics, "sports" );
+        assertContainsTopic( resultTopics, "tennis" );
+        assertContainsTopic( resultTopics, "football" );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports/./college" );
+        assertEquals( 2, resultTopics.length );
+        assertContainsTopic( resultTopics, "college" );
+
         resultTopics = evaluate( NSPREFIX1 + ":sports/*/college" );
         assertEquals( 2, resultTopics.length );
         assertContainsTopic( resultTopics, "college" );
@@ -104,12 +118,23 @@
 
     public void testEvaluateRecursive() throws Exception
     {
-        Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports//*" );
+        Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports//college" );
+        assertEquals( 2, resultTopics.length );
+        assertContainsTopic( resultTopics, "college" );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports//*" );
         assertEquals( 4, resultTopics.length );
         assertContainsTopic( resultTopics, "tennis" );
         assertContainsTopic( resultTopics, "football" );
         assertContainsTopic( resultTopics, "college" );
 
+        resultTopics = evaluate( NSPREFIX1 + ":sports//." );
+        assertEquals( 5, resultTopics.length );
+        assertContainsTopic( resultTopics, "sports" );
+        assertContainsTopic( resultTopics, "tennis" );
+        assertContainsTopic( resultTopics, "football" );
+        assertContainsTopic( resultTopics, "college" );
+
         resultTopics = evaluate( NSPREFIX1 + "://*" );
         assertEquals( 8, resultTopics.length );
         assertContainsTopic( resultTopics, "sports" );
@@ -121,14 +146,24 @@
         assertContainsTopic( resultTopics, "chess" );
     }
 
+    public void testEvaluateConjoined() throws Exception
+    {
+        Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports/tennis|" + NSPREFIX2 + ":bands/*" );
+        assertEquals( 3, resultTopics.length );
+        assertContainsTopic( resultTopics, "tennis" );
+        assertContainsTopic( resultTopics, "beatles" );
+        assertContainsTopic( resultTopics, "kinks" );
+    }
+
     public void testEvaluateInvalid() throws Exception
     {
+        // first check expressions do not conform to the Full Topic Expression grammar defined by the WS-Topics spec
         assertExpressionIsInvalid( NSPREFIX1 + ":." );
         assertExpressionIsInvalid( NSPREFIX1 + "://." );
-        assertExpressionIsInvalid( NSPREFIX1 + ":bands" );
-        assertExpressionIsInvalid( NSPREFIX1 + ":bands/beatles" );
-        assertExpressionIsInvalid( NSPREFIX1 + ":bands/*" );
-        // TODO: add tests for non-fixed topic set
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports///tennis" );
+        // now check expressions that violate other validity constraints defined by the spec
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/baseball" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":bands|" + NSPREFIX2 + ":bands" );
     }
 
     private void assertExpressionIsInvalid( String expr )
@@ -160,10 +195,16 @@
 
     private Topic[] evaluate( String expr ) throws Exception
     {
-        TopicExpressionType topicExpr = ( (TopicExpressionDocument) XmlObject.Factory.parse( "<TopicExpression xmlns='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' xmlns:" +
+        TopicExpressionType topicExpr = ( (TopicExpressionDocument) XmlObject.Factory.parse(
+                "<TopicExpression xmlns='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' " +
+                "xmlns:" +
                 NSPREFIX1 +
                 "='" +
                 NSURI1 +
+                "' xmlns:" +
+                NSPREFIX2 +
+                "='" +
+                NSURI2 +
                 "' Dialect='http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full'>" +
                 expr +
                 "</TopicExpression>" ) ).getTopicExpression();



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