244 Part III Manipulating Messages
Building a Smart Client Application to Manage Business Rules
If you are using an integration solution such as BizTalk Server 2004, you prob-
ably do not need to build a smart client application to manage your business
rules. However, if you are not using such an integration solution, you might
need to build an application to make managing rules an easier task. The alter-
native is to edit your rules in a text reader such as Microsoft Notepad, which can
lead to errors or omissions.
The basic task of the smart client application is to create, modify, and
manage the rules document, which is stored in an XML format. However, cre-
ating a Schematron rules document requires you to perform a number of tasks
in addition to adding, removing, and altering nodes in the XML document. Cre-
ating a rules document also requires that you check the document for validity
against the Schematron schema, test instance documents against it, and store it
in and retrieve it from a handy location. In this section, we will walk through
the class that performs the majority of functions of our business rules editor
(see Figure 10-2). The remainder of the code is available in the code samples
on the book’s companion Web site.
Figure 10-2 Business rules editor.
The Rules panel, found in the upper-left corner of the application, con-
tains various views of the current rules document we are editing or creating.
Selecting the appropriate tab underneath the window will allow you to switch
from one view to another. The XML view of the rule will probably look the
Chapter 10 Managing Business Rules and Processes 245
most familiar to you: it looks as though you are editing the document in Note-
pad or another basic XML editor. The Pattern view and Phase view limit your
view of the document to patterns and phases, respectively, and the Full Tree
view allows you to see the entire document by using a tree control rather than
plain XML. The Input panel allows you to enter test messages and features an
XML and full tree panel as well. The resulting messages are displayed in the
bottom-left panel.
Each report, assert, phase, and pattern has a set of attributes that are filled in
by using the upper-right pane. The attributes for a report are shown in Figure 10-3.
Figure 10-3 Report attributes.
The definitions for the attributes of patterns, phases, reports, and asserts
can be found at the Schematron home page: http://www.ascc.net/xml/resource
The lower-right pane in Figure 10-2 contains the calculator for the busi-
ness rules editor. This allows you to insert various XPath functions into the rules
document, including functions that find specific nodes in the instance docu-
ment, functions that manipulate strings, and functions that perform simple
mathematical tests. To learn more about the XPath functions available, see the
“Transforming Message Contents by Using XPath” section in Chapter 8.
The Schematron class in our application transforms the rules documents
and the instance documents. This class has three separate constructors, which
we will label Schematron Constructor A, Schematron Constructor B, and Sche-
matron Constructor C. The first constructor (which follows) is used when the
rules schema and the Schematron schema both reside in a database. Notice that
the rules document is referenced by the ruleXsdId of the rules document in the
246 Part III Manipulating Messages
Schematron Constructor A
/// <summary>
/// Constructor A. Used where rules xsd and Schematron schema reside
/// in the database.
/// </summary>
/// <param name="newSourceXml">
/// Source xml to validate as xml document.
/// </param>
/// <param name="newRuleXsdId">
/// Database Id of rules schema.
/// </param>
public Schematron(System.Xml.XmlDocument newSourceXml, int newRuleXsdId)
sourceXmlDoc = newSourceXml;
ruleXsdId = newRuleXsdId;
The second constructor (shown next) is used when the rules schema, the
Schematron schema, and the instance document are supplied as System
.Xml.XmlDocument objects.
Schematron Constructor B
/// <param name="newSourceXml">
/// Xml document containing xml to be validated.
/// </param>
/// <param name="newRulesXsd">
/// Xml document containing rules.
/// </param>
/// <param name="newSchematronXslt">
/// Xml document containing schematron schema.
/// </param>
public Schematron(System.Xml.XmlDocument newSourceXml,
System.Xml.XmlDocument newRulesXsd,
System.Xml.XmlDocument newSchematronXslt)
sourceXmlDoc = newSourceXml;
rulesXsdDoc = newRulesXsd;
schematronXsltDoc = newSchematronXslt;
The third constructor (which follows) is used when the rules schema and
the Schematron schema both reside in the file system.

Get Enterprise Integration Solutions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.