You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2007/01/03 20:31:51 UTC
svn commit: r492265 - in
/webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl:
FilterCollection.java FilterFactory.java
Author: danj
Date: Wed Jan 3 11:31:51 2007
New Revision: 492265
URL: http://svn.apache.org/viewvc?view=rev&rev=492265
Log:
Fix for MUSE-122 - we now support multiple subscription filters as per the WSN 1.3 spec. We did not have to break
the 2.x API to do this - I hid the multiple filters in a 'FilterCollection' that implements the original Filter
interface and implements accepts() as an aggregate conditional operation.
The FilterCollection class can also be used by WSN clients to create requests w/ multiple filters.
Added:
webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterCollection.java
Modified:
webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterFactory.java
Added: webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterCollection.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterCollection.java?view=auto&rev=492265
==============================================================================
--- webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterCollection.java (added)
+++ webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterCollection.java Wed Jan 3 11:31:51 2007
@@ -0,0 +1,107 @@
+/*=============================================================================*
+ * Copyright 2007 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.muse.ws.notification.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.notification.Filter;
+import org.apache.muse.ws.notification.NotificationMessage;
+import org.apache.muse.ws.notification.WsnConstants;
+
+/**
+ *
+ * FilterCollection is a set of WSN subscription filters that a notification
+ * producer must evaluate when determining whether it should send a message
+ * to a consumer or not. It implements the {@linkplain Filter Filter} interface
+ * so that it can be treated as a single filter by filter-evaluating code; this
+ * allows us to use FilterCollection objects in places where a Filter is
+ * specified even though FilterCollection was not part of the original 2.x API.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class FilterCollection implements Filter
+{
+ private Collection _filters = new ArrayList();
+
+ public boolean accepts(NotificationMessage message)
+ {
+ Iterator i = getFilters().iterator();
+
+ while (i.hasNext())
+ {
+ Filter next = (Filter)i.next();
+
+ //
+ // only one filter has to fail for the whole thing to fail
+ //
+ if (!next.accepts(message))
+ return false;
+ }
+
+ return true;
+ }
+
+ public void addFilter(Filter filter)
+ {
+ _filters.add(filter);
+ }
+
+ public Collection getFilters()
+ {
+ return Collections.unmodifiableCollection(_filters);
+ }
+
+ public Element toXML()
+ {
+ return toXML(XmlUtils.EMPTY_DOC);
+ }
+
+ public Element toXML(Document doc)
+ {
+ Element filterXML = XmlUtils.createElement(doc, WsnConstants.FILTER_QNAME);
+
+ Iterator i = getFilters().iterator();
+
+ while (i.hasNext())
+ {
+ Filter next = (Filter)i.next();
+ Element nextXML = next.toXML(doc);
+
+ //
+ // we have to 'move' instead of 'appendChild' because the other
+ // Filter types already add a <Filter/> element as part of their
+ // toXML() implementations, and we can't change this for reasons
+ // of backwards compatibility. therefore, we just take the element
+ // under the <Filter/> and move it under our new <Filter/>
+ //
+ XmlUtils.moveSubTree(nextXML, filterXML);
+ }
+
+ return filterXML;
+ }
+
+}
+
Modified: webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterFactory.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterFactory.java?view=diff&rev=492265&r1=492264&r2=492265
==============================================================================
--- webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterFactory.java (original)
+++ webservices/muse/trunk/modules/muse-wsn-impl/src/org/apache/muse/ws/notification/impl/FilterFactory.java Wed Jan 3 11:31:51 2007
@@ -99,52 +99,66 @@
if (xml == null)
return PublishAllMessagesFilter.getInstance();
- //
- // no table with multiple parsers - we only have three filter types,
- // so just do all the parsing here
- //
+ Element[] children = XmlUtils.getAllElements(xml);
//
- // topic-based filtering?
+ // <Filter/> element, but not child elements? publish all messages
//
- Element topic = XmlUtils.getElement(xml, WsnConstants.TOPIC_EXPRESSION_QNAME);
-
- if (topic != null)
- {
- String dialect = topic.getAttribute(WsnConstants.DIALECT);
- QName topicName = XmlUtils.getQName(topic);
- return new TopicFilter(topicName, dialect);
- }
+ if (children.length == 0)
+ return PublishAllMessagesFilter.getInstance();
//
- // resource properties-based filtering?
+ // no table with multiple parsers - we only have three filter types,
+ // so just do all the parsing here
//
- Element props = XmlUtils.getElement(xml, WsnConstants.PRODUCER_PROPERTIES_QNAME);
-
- if (props != null)
- {
- String dialect = props.getAttribute(WsnConstants.DIALECT);
- String expression = XmlUtils.extractText(props);
- return new ProducerPropertiesFilter(resource, expression, dialect);
- }
- //
- // message pattern (xpath)-based filtering?
- //
- Element content = XmlUtils.getElement(xml, WsnConstants.MESSAGE_CONTENT_QNAME);
+ FilterCollection filters = new FilterCollection();
- if (content != null)
+ for (int n = 0; n < children.length; ++n)
{
- String dialect = content.getAttribute(WsnConstants.DIALECT);
- String pattern = XmlUtils.extractText(content);
- return new MessagePatternFilter(pattern, dialect);
+ //
+ // topic-based filtering?
+ //
+ QName childName = XmlUtils.getElementQName(children[n]);
+
+ if (childName.equals(WsnConstants.TOPIC_EXPRESSION_QNAME))
+ {
+ String dialect = children[n].getAttribute(WsnConstants.DIALECT);
+ QName topicName = XmlUtils.getQName(children[n]);
+ filters.addFilter(new TopicFilter(topicName, dialect));
+ }
+
+ //
+ // resource properties-based filtering?
+ //
+ else if (childName.equals(WsnConstants.PRODUCER_PROPERTIES_QNAME))
+ {
+ String dialect = children[n].getAttribute(WsnConstants.DIALECT);
+ String expression = XmlUtils.extractText(children[n]);
+ filters.addFilter(new ProducerPropertiesFilter(resource, expression, dialect));
+ }
+
+ //
+ // message pattern (xpath)-based filtering?
+ //
+ else if (childName.equals(WsnConstants.MESSAGE_CONTENT_QNAME))
+ {
+ String dialect = children[n].getAttribute(WsnConstants.DIALECT);
+ String pattern = XmlUtils.extractText(children[n]);
+ filters.addFilter(new MessagePatternFilter(pattern, dialect));
+ }
+
+ else
+ {
+ //
+ // no match for known filter types - try and tell the user what
+ // was found and why it's not valid
+ //
+ Object[] filler = { XmlUtils.getFirstElement(xml) };
+ throw new InvalidFilterFault(_MESSAGES.get("InvalidFilterType", filler));
+ }
}
- //
- // no match for known filter types - try and tell the user what
- // was found and why it's not valid
- //
- Object[] filler = { XmlUtils.getFirstElement(xml) };
- throw new InvalidFilterFault(_MESSAGES.get("InvalidFilterType", filler));
+ return filters;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org