org.milyn.delivery
Class DomModelCreator

java.lang.Object
  extended by org.milyn.delivery.DomModelCreator
All Implemented Interfaces:
ContentHandler, DOMVisitBefore, DOMVisitor, SAXVisitAfter, SAXVisitBefore, SAXVisitor, Visitor

public class DomModelCreator
extends Object
implements DOMVisitBefore, SAXVisitBefore, SAXVisitAfter

DOM Node Model creator.

Adds the visited element as a node model.

Mixing DOM and SAX

When used with SAX filtering, this visitor will construct a DOM Fragment of the visited element. This allows DOM utilities to be used in a Streaming environment.

When 1+ models are nested inside each other, outer models will never contain data from the inner models i.e. the same fragments will never cooexist inside two models.

Take the following message as an example:

 <order id='332'>
     <header>
         <customer number="123">Joe</customer>
     </header>
     <order-items>
         <order-item id='1'>
             <product>1</product>
             <quantity>2</quantity>
             <price>8.80</price>
         </order-item>
         <order-item id='2'>
             <product>2</product>
             <quantity>2</quantity>
             <price>8.80</price>
         </order-item>
         <order-item id='3'>
             <product>3</product>
             <quantity>2</quantity>
             <price>8.80</price>
         </order-item>
    </order-items>
 </order>
 
The DomModelCreator can be configured to create models for the "order" and "order-item" message fragments:
 <resource-config selector="order,order-item">
     <resource>org.milyn.delivery.DomModelCreator</resource>
 </resource-config>
 
In this case, the "order" model will never contain "order-item" model data (order-item elements are nested inside the order element). The in memory model for the "order" will simply be:
 <order id='332'>
     <header>
         <customer number="123">Joe</customer>
     </header>
     <order-items />
 </order>
 
Added to this is the fact that there will only ever be 0 or 1 "order-item" models in memory at any given time, with each new "order-item" model overwriting the previous "order-item" model. All this ensures that the memory footprint is kept to a minimum.

Author:
tom.fennelly@gmail.com

Constructor Summary
DomModelCreator()
           
 
Method Summary
 Document popCreator(ExecutionContext executionContext)
           
 void visitAfter(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element after visiting its child elements.
 void visitBefore(Element element, ExecutionContext executionContext)
          Visit the supplied element before visiting its child elements.
 void visitBefore(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element before visiting its child elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomModelCreator

public DomModelCreator()
                throws ParserConfigurationException
Throws:
ParserConfigurationException
Method Detail

visitBefore

public void visitBefore(Element element,
                        ExecutionContext executionContext)
                 throws SmooksException
Description copied from interface: DOMVisitBefore
Visit the supplied element before visiting its child elements.

Specified by:
visitBefore in interface DOMVisitBefore
Parameters:
element - The DOM element being visited.
executionContext - Request relative instance.
Throws:
SmooksException - Element processing failure.

visitBefore

public void visitBefore(SAXElement element,
                        ExecutionContext executionContext)
                 throws SmooksException,
                        IOException
Description copied from interface: SAXVisitBefore
Visit the supplied element before visiting its child elements.

Specified by:
visitBefore in interface SAXVisitBefore
Parameters:
element - The SAX element being visited.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

visitAfter

public void visitAfter(SAXElement element,
                       ExecutionContext executionContext)
                throws SmooksException,
                       IOException
Description copied from interface: SAXVisitAfter
Visit the supplied element after visiting its child elements.

Specified by:
visitAfter in interface SAXVisitAfter
Parameters:
element - The SAX element being visited.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

popCreator

public Document popCreator(ExecutionContext executionContext)


Copyright © 2008. All Rights Reserved.