WS Notification and WS Topics in the WS Resources Framework
This article continues our discussion of the WS-Resource Framework, a set of proposed standards that formalizes the relationship between Web services and state. In this part, the third of a multi-part series, we cover the use of notifications and topics. It is excerpted from chapter 8 of the book Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418).
WS Notification and WS Topics in the WS Resources Framework - TopicPathExpressions (Page 5 of 6 )
To this point, we've only mentioned topic expressions in passing. Topic expressions appear in subscribe requests and several other places in WS-Notification. They can contain a wide variety of expression types, from simple, QName-based topic names to path expressions (like hierarchical file paths in a computer's filesystem) to rich wild- card-enabled expression languages. The type of expression is determined by the dialect attribute of a topic expression. The dialect attribute contains a URI that identifies the language used by the topic expression. WS-Topics defines several dialects, and their standard URIs are specified in that document.
The simplest topic expression dialect, identified by the URI http://www.ibm.com/xmlns/stdwip/web-services/WS- Topics/TopicExpression/simple, can contain only QNames of root topics. This language is quite limited in that it can only identify root topics. However, in many circumstances, simple (nonhierarchical) topic spaces are sufficient. Here is an example simple topic expression that identifies the orderPlacement topic:
The second topic expression dialect defined by WS-Topics is a straightforward path language that's similar to file paths in hierarchical directory structures. This path-based dialect is identified by the URI http://www.ibm.com/xmlns/stdwip/web-services/WS- Topics/TopicExpression/concreteTopicPath. This is a so-called concrete topic expression dialect because expressions in this dialect identify exactly one topic. This is more powerful than the simple dialect, in that child topics can be identified. In this dialect, topic expressions are combinations of topic names and topic paths (topic names separated by slashes, /, to denote hierarchical parent topic/child topic structures). Note that this dialect builds on the simple dialect: The concrete topic expression dialect also allows the QName expressions found in the simple dialect.
Here's an example concrete topic expression, identifying the VIPComplaint child topic of the complaint topic:
A third topic expression dialect defined by WS-Topics is the full topic expression dialect. The full topic expression dialect builds on the concrete topic dialect by adding wildcard (*) characters and including a conjunction (|) to allow you to express the logical or of two topic expressions. With a topic expression using this full dialect, you can specify one or more topics in a single expression:
Topic expressions containing a wildcard (*) may identify any number of topics. The wildcard can appear anywhere in the topic expression, either at the beginning of the topic expression, matching any root topic; or part way through a topic expression, matching any child topic at a particular level in the hierarchy.
A topic expression consisting just of the * character matches any topic. If this were the parameter of a subscribe request, it would suggest that the subscriber was interested in all topics supported by that notification producer.
A topic expression containing a wildcard after a / symbol indicates a match for all the topics at a particular level in the topic tree. For example, the topic expression crm:telephoneContact/* matches all the child topics of crm:telephoneContact. The expression crm:telephoneContact/* doesn't match the crm:telephoneContact topic itself. To match an entire subtree of topics rooted at a particular node, you use the //. construct. So the topic expression crm:telephoneContact//. matches all the topics in the entire topic tree rooted at crm:telephoneContact.
The | character evaluates to the set union of the topics from both expressions. This allows a subscriber to use one subscription to receive notifications from a combination of different topics. For example, if the subscriber wanted to subscribe to receive notifications on the crm:telephoneContact and the crm:emailContact topics, they would use the following topic expression: crm:telephoneContact | crm:emailContact.
TopicExpressions and XPath - Although the authors of WS-Topics could have chosen XPath as the language to describe topic paths, it turned out that doing so wasn't straightforward. Early design attempts to make the topic expression language simple XPath (or a subset thereof) turned out to require that the topic space XML document look extremely awkward. So, the designers faced a choice: either specify an XPath subset as the topic expression language and have a very awkward-looking topic space document, or choose to have a straightforward-looking topic model in XML and develop a simple, path-based expression language. On balance, the designers chose the lesser of two evils.