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 [2/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/
Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java Thu Apr 28 18:32:52 2005
@@ -15,7 +15,7 @@
*=============================================================================*/
package org.apache.ws.notification.topics.util;
-import org.apache.ws.notification.topics.TopicSet;
+import org.apache.ws.notification.topics.TopicSpaceSet;
import org.apache.ws.notification.topics.ResourcePropertyValueChangeTopic;
import org.apache.ws.notification.topics.Topic;
import org.apache.ws.notification.topics.TopicSpace;
@@ -41,19 +41,20 @@
/**
* Adds the topic for ResoruceTermination....there should be only one of these!
*
- * @param topicSet
+ * @param topicSpaceSet
* @return
*/
- public static Topic addResourceTerminationTopic(TopicSet topicSet, Resource resource, NamespaceVersionHolder namespaces)
+ public static Topic addResourceTerminationTopic(TopicSpaceSet topicSpaceSet, Resource resource, NamespaceVersionHolder namespaces)
+ throws Exception
{
//there can be only 1 !
String namespace = namespaces.getLifetimeXsdNamespace();
Topic topic = null;
- TopicSpace topicSpace = topicSet.getTopicSpace(namespace);
+ TopicSpace topicSpace = topicSpaceSet.getTopicSpace(namespace);
if (topicSpace == null)
{
topicSpace = new TopicSpaceImpl(namespace);
- topicSet.addTopicSpace(topicSpace);
+ topicSpaceSet.addTopicSpace(topicSpace);
}
if (topicSpace.topicIterator().hasNext())
{
@@ -74,10 +75,11 @@
* Adds a topic for the specified property to the specified topic set.
*
* @param prop
- * @param topicSet
+ * @param topicSpaceSet
* @return
*/
- public static Topic addResourcePropertyValueChangeTopic( ResourceProperty prop, TopicSet topicSet )
+ public static Topic addResourcePropertyValueChangeTopic( ResourceProperty prop, TopicSpaceSet topicSpaceSet )
+ throws Exception
{
if ( prop.getMetaData().isReadOnly() )
{
@@ -86,11 +88,11 @@
ResourcePropertyValueChangeTopic valueChangeTopic = new ResourcePropertyValueChangeTopicImpl( prop );
prop.addChangeListener( valueChangeTopic );
String topicNsURI = prop.getMetaData().getName().getNamespaceURI();
- TopicSpace topicSpace = topicSet.getTopicSpace( topicNsURI );
+ TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicNsURI );
if ( topicSpace == null )
{
topicSpace = new TopicSpaceImpl( topicNsURI );
- topicSet.addTopicSpace( topicSpace );
+ topicSpaceSet.addTopicSpace( topicSpace );
}
topicSpace.addTopic( valueChangeTopic );
return valueChangeTopic;
@@ -100,10 +102,11 @@
* Adds topics for all non-readonly properties from the specified property set to the specified topic set.
*
* @param propSet
- * @param topicSet
+ * @param topicSpaceSet
* @return
*/
- public static Topic[] addResourcePropertyValueChangeTopics( ResourcePropertySet propSet, TopicSet topicSet )
+ public static Topic[] addResourcePropertyValueChangeTopics( ResourcePropertySet propSet, TopicSpaceSet topicSpaceSet )
+ throws Exception
{
List topicList = new ArrayList();
Iterator propIter = propSet.iterator();
@@ -112,7 +115,7 @@
ResourceProperty prop = (ResourceProperty) propIter.next();
if ( ! prop.getMetaData().isReadOnly() )
{
- Topic topic = addResourcePropertyValueChangeTopic( prop, topicSet );
+ Topic topic = addResourcePropertyValueChangeTopic( prop, topicSpaceSet );
topicList.add( topic );
}
}
Modified: incubator/hermes/trunk/src/java/org/apache/ws/pubsub/TopicFilter.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/TopicFilter.java?rev=165250&r1=165249&r2=165250&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/pubsub/TopicFilter.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/pubsub/TopicFilter.java Thu Apr 28 18:32:52 2005
@@ -34,7 +34,7 @@
if(it.hasNext())
topicexpr+="/";
}
- m_targetNamespace=t.getTopicSpace().getNamespaceURI();
+ m_targetNamespace=t.getTopicSpace().getTargetNamespace();
super.setURI(FilterFactory.topicsuri);
super.setContent(parse(topicexpr));
}
Added: 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=165250&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java Thu Apr 28 18:32:52 2005
@@ -0,0 +1,173 @@
+/*=============================================================================*
+ * 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 junit.framework.TestCase;
+import org.apache.ws.notification.base.impl.XmlBeansTopicExpression;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+
+/**
+ * TODO
+ */
+public class FullTopicExpressionEvaluatorTestCase extends TestCase
+{
+
+ private static final String NSURI1 = "http://ns1.com/";
+ private static final String NSPREFIX1 = "ns1";
+ private static final String NSURI2 = "http://ns2.com/";
+ private static final String NSPREFIX2 = "ns2";
+
+ private TopicExpressionEvaluator m_evaluator;
+ private TopicSpaceSet m_topicSpaceSet;
+
+ protected void setUp() throws Exception
+ {
+ m_evaluator = new FullTopicExpressionEvaluator();
+ m_topicSpaceSet = new TopicSpaceSetImpl( true );
+ TopicSpace topicSpace1 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( NSURI1 ) );
+ Topic sportsTopic = topicSpace1.addTopic( "sports" );
+ Topic tennisTopic = sportsTopic.addTopic( "tennis" );
+ tennisTopic.addTopic( "college" );
+ Topic footballTopic = sportsTopic.addTopic( "football" );
+ footballTopic.addTopic( "college" );
+ Topic gamesTopic = topicSpace1.addTopic( "games" );
+ gamesTopic.addTopic( "monopoly" );
+ gamesTopic.addTopic( "chess" );
+ TopicSpace topicSpace2 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( NSURI2 ) );
+ Topic bandsTopic = topicSpace2.addTopic( "bands" );
+ bandsTopic.addTopic( "beatles" );
+ bandsTopic.addTopic( "kinks" );
+ }
+
+ public void testEvaluateSimple() throws Exception
+ {
+ Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports" );
+ assertEquals( 1, resultTopics.length );
+ assertContainsTopic( resultTopics, "sports" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":sports/tennis" );
+ assertEquals( 1, resultTopics.length );
+ assertContainsTopic( resultTopics, "tennis" );
+ }
+
+ public void testEvaluateWildcard() throws Exception
+ {
+ Topic[] resultTopics = evaluate( NSPREFIX1 + ":*" );
+ assertEquals( 2, resultTopics.length );
+ assertContainsTopic( resultTopics, "sports" );
+ assertContainsTopic( resultTopics, "games" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":*/tennis" );
+ assertEquals( 1, resultTopics.length );
+ assertContainsTopic( resultTopics, "tennis" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":sports/*" );
+ assertEquals( 2, resultTopics.length );
+ assertContainsTopic( resultTopics, "tennis" );
+ assertContainsTopic( resultTopics, "football" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":sports/*/college" );
+ assertEquals( 2, resultTopics.length );
+ assertContainsTopic( resultTopics, "college" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":*/*" );
+ assertEquals( 4, resultTopics.length );
+ assertContainsTopic( resultTopics, "tennis" );
+ assertContainsTopic( resultTopics, "football" );
+ assertContainsTopic( resultTopics, "monopoly" );
+ assertContainsTopic( resultTopics, "chess" );
+
+ resultTopics = evaluate( NSPREFIX1 + ":*/*/college" );
+ assertEquals( 2, resultTopics.length );
+ assertContainsTopic( resultTopics, "college" );
+ }
+
+ public void testEvaluateRecursive() throws Exception
+ {
+ Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports//*" );
+ assertEquals( 4, resultTopics.length );
+ assertContainsTopic( resultTopics, "tennis" );
+ assertContainsTopic( resultTopics, "football" );
+ assertContainsTopic( resultTopics, "college" );
+
+ resultTopics = evaluate( NSPREFIX1 + "://*" );
+ assertEquals( 8, resultTopics.length );
+ assertContainsTopic( resultTopics, "sports" );
+ assertContainsTopic( resultTopics, "tennis" );
+ assertContainsTopic( resultTopics, "football" );
+ assertContainsTopic( resultTopics, "college" );
+ assertContainsTopic( resultTopics, "games" );
+ assertContainsTopic( resultTopics, "monopoly" );
+ assertContainsTopic( resultTopics, "chess" );
+ }
+
+ public void testEvaluateInvalid() throws Exception
+ {
+ assertExpressionIsInvalid( NSPREFIX1 + ":." );
+ assertExpressionIsInvalid( NSPREFIX1 + "://." );
+ assertExpressionIsInvalid( NSPREFIX1 + ":bands" );
+ assertExpressionIsInvalid( NSPREFIX1 + ":bands/beatles" );
+ assertExpressionIsInvalid( NSPREFIX1 + ":bands/*" );
+ // TODO: add tests for non-fixed topic set
+ }
+
+ private void assertExpressionIsInvalid( String expr )
+ throws Exception
+ {
+ try
+ {
+ evaluate( expr );
+ fail();
+ }
+ catch ( InvalidTopicExpressionException itee )
+ {
+ // success!
+ }
+ }
+
+ private void assertContainsTopic( Topic[] topics, String name )
+ {
+ boolean foundIt = false;
+ for ( int i = 0; i < topics.length; i++ )
+ {
+ if ( topics[i].getName().equals( name ) )
+ {
+ foundIt = true;
+ }
+ }
+ assertTrue( foundIt );
+ }
+
+ 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:" +
+ NSPREFIX1 +
+ "='" +
+ NSURI1 +
+ "' Dialect='http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full'>" +
+ expr +
+ "</TopicExpression>" ) ).getTopicExpression();
+ return m_evaluator.evaluate( m_topicSpaceSet, new XmlBeansTopicExpression( topicExpr ) );
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: hermes-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: hermes-dev-help@ws.apache.org