org.osesb.msgrouting
Class DroolsXMLMessageTypeHelper

java.lang.Object
  extended by org.osesb.msgrouting.AbstractXMLMessageTypeHelper
      extended by org.osesb.msgrouting.DefaultXMLMessageTypeHelper
          extended by org.osesb.msgrouting.DroolsXMLMessageTypeHelper

public class DroolsXMLMessageTypeHelper
extends DefaultXMLMessageTypeHelper

DroolsXMLMessageTypeHelper extends DefaultXMLMessageTypeHelper with a getMessageType() method that incorporates a Drools rule.

DefaultXMLMessageTypeHelper is the default XMLMessageTypeHelper class and is constructed with a XMLMessageTypeXPathExpressionListConfiguration. DefaultXMLMessageTypeHelper applies the configured XPath expressions to a XML message until a messageType is determined. DefaultXMLMessageTypeHelper#getMessagetype() returns the messageType as a QName, where the namespaceURI is the XML document namespace (if any) and the localPart is the value for the element or attribute that is given by a XPath expression that is configured in the XMLMessageTypeXPathExpressionListConfiguration.

DroolsXMLMessageTypeHelper is constructed with a DroolsXMLMessageTypeHelperConfiguration, which combines XMLMessageTypeXPathExpressionListConfiguration and DroolsRuleApplierConfiguration.

DroolsXMLMessageTypeHelper allows for more complex determination of the messageType for a XML message as follows:

  1. DroolsXMLMessageTypeHelper#getMessageType() invokes the ancestor method to determine a messageType based on namespace and the value for an element or attribute value. Note that the messageType returned by the ancestor can be null; the ancestor is not required to return a messageType.
  2. DroolsXMLMessageTypeHelperConfiguration configures additional XPath expressions, which are passed to an instance of org.osesb.drools.XMLDroolsRuleApplier. XMLDroolsRuleApplier applies the XPath expressions to the XML and creates a org.osesb.utilities.xml.XMLNode for each extracted value. The XMLNodes are passed to the configured Drools rule as facts.
  3. The namespace for the XML and the messageType returned by the ancestor are passed to the Drools WorkingMemory as global objects.
  4. The configured Drools rule uses the XMLNodes extracted from the XML, the namespace for the XML, and the messageType returned by the ancestor to determine the messageType.


Field Summary
protected  DroolsXMLMessageTypeHelperConfiguration droolsXMLMessageTypeHelperConfiguration
          The DroolsXMLMessageTypeHelperConfiguration which combines XMLMessageTypeXPathExpressionListConfiguration and DroolsRuleApplierConfiguration.
protected  XMLDroolsRuleApplier xmlDroolsRuleApplier
          XMLDroolsRuleApplier applies Drools rules to the values extracted from XML using XPath Expressions.
 
Fields inherited from class org.osesb.msgrouting.DefaultXMLMessageTypeHelper
documentNamespaceHelper, log, saxXPathElementHandler, thisClassName, xmlMessageTypeXPathExpressionListConfiguration
 
Fields inherited from class org.osesb.msgrouting.AbstractXMLMessageTypeHelper
debugFlag
 
Constructor Summary
DroolsXMLMessageTypeHelper(DroolsXMLMessageTypeHelperConfiguration droolsXMLMessageTypeHelperConfiguration)
          Creates a new instance of DefaultXMLMessageTypeHelper.
 
Method Summary
 javax.xml.namespace.QName getMessageType(java.lang.String xmlText)
          Get a message type from a XML message according to the following plan:

Invokes the ancestor method, which returns the messageType as a QName, where the namespaceURI is the XML document namespace (if any) and the localPart is the value for the element or attribute that is given by a XPath expression that is configured in the XMLMessageTypeXPathExpressionListConfiguration. DroolsXMLMessageTypeHelperConfiguration configures additional XPath expressions, which are passed to an instance of org.osesb.drools.XMLDroolsRuleApplier.

 XMLDroolsRuleApplier getXmlDroolsRuleApplier()
          Get the XMLDroolsRuleApplier used by this DroolsXMLMessageTypeHelper.
static void main(java.lang.String[] args)
          Main method for testing.
 
Methods inherited from class org.osesb.msgrouting.DefaultXMLMessageTypeHelper
getNamespaceQualifiedMessageType, getUnqualifiedMessageType, parseForMessageType, setDebugFlag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

droolsXMLMessageTypeHelperConfiguration

protected DroolsXMLMessageTypeHelperConfiguration droolsXMLMessageTypeHelperConfiguration
The DroolsXMLMessageTypeHelperConfiguration which combines XMLMessageTypeXPathExpressionListConfiguration and DroolsRuleApplierConfiguration.


xmlDroolsRuleApplier

protected XMLDroolsRuleApplier xmlDroolsRuleApplier
XMLDroolsRuleApplier applies Drools rules to the values extracted from XML using XPath Expressions. In this case the Drools rules are written to return a messageType for the XML.

Constructor Detail

DroolsXMLMessageTypeHelper

public DroolsXMLMessageTypeHelper(DroolsXMLMessageTypeHelperConfiguration droolsXMLMessageTypeHelperConfiguration)
                           throws java.lang.Exception
Creates a new instance of DefaultXMLMessageTypeHelper.

Parameters:
droolsXMLMessageTypeHelperConfiguration - which combines XMLMessageTypeXPathExpressionListConfiguration and DroolsRuleApplierConfiguration.
Throws:
java.lang.Exception - if constructed with a null DroolsXMLMessageTypeHelperConfiguration or if an error occurs while creating an instance of org.osesb.drools.XMLDroolsRuleApplier.
Method Detail

getMessageType

public javax.xml.namespace.QName getMessageType(java.lang.String xmlText)
                                         throws java.lang.Exception,
                                                MessageTypeNotFoundException
Get a message type from a XML message according to the following plan:

  1. Invokes the ancestor method, which returns the messageType as a QName, where the namespaceURI is the XML document namespace (if any) and the localPart is the value for the element or attribute that is given by a XPath expression that is configured in the XMLMessageTypeXPathExpressionListConfiguration.
  2. DroolsXMLMessageTypeHelperConfiguration configures additional XPath expressions, which are passed to an instance of org.osesb.drools.XMLDroolsRuleApplier. XMLDroolsRuleApplier applies the XPath expressions to the XML and creates a org.osesb.utilities.xml.XMLNode for each extracted value. The XMLNodes are passed to the configured Drools rule as facts.
  3. The namespace for the XML and the messageType returned by the ancestor are passed to the Drools WorkingMemory as global objects.
  4. The configured Drools rule uses the XMLNodes extracted from the XML, the namespace for the XML, and the messageType returned by the ancestor to determine the messageType.

Overrides:
getMessageType in class DefaultXMLMessageTypeHelper
Parameters:
xmlText - The XML text to extract the message type from.
Returns:
A QName that represents the message type.
Throws:
java.lang.Exception - if there was a general error extracting the message type.
MessageTypeNotFoundException - if the message type could not be dtermined using the configured Drools rules.

getXmlDroolsRuleApplier

public XMLDroolsRuleApplier getXmlDroolsRuleApplier()
Get the XMLDroolsRuleApplier used by this DroolsXMLMessageTypeHelper.

Returns:
the XMLDroolsRuleApplier used by this DroolsXMLMessageTypeHelper.

main

public static void main(java.lang.String[] args)
Main method for testing.

Parameters:
args - The test data directory.