Class DomModelCreator
- java.lang.Object
-
- org.smooks.engine.resource.visitor.dom.DomModelCreator
-
- All Implemented Interfaces:
ContentHandler
,Producer
,AfterVisitor
,BeforeVisitor
,SaxNgVisitor
,Visitor
public class DomModelCreator extends Object implements BeforeVisitor, AfterVisitor, Producer
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+ model are nested inside each other, outer model will never contain data from the inner model i.e. the same fragments will never cooexist inside two model. 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>
TheDomModelCreator
can be configured to create model for the "order" and "order-item" message fragments:<resource-config selector="order,order-item"> <resource>org.smooks.engine.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" model 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
Constructors Constructor Description DomModelCreator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getProducts()
Get the set of products produced by this producer instance.Document
popCreator(ExecutionContext executionContext)
void
visitAfter(Element element, ExecutionContext executionContext)
Visits the end of anElement
.void
visitBefore(Element element, ExecutionContext executionContext)
Visits the beginning of anElement
.
-
-
-
Constructor Detail
-
DomModelCreator
public DomModelCreator() throws ParserConfigurationException
- Throws:
ParserConfigurationException
-
-
Method Detail
-
getProducts
public Set<String> getProducts()
Description copied from interface:Producer
Get the set of products produced by this producer instance.- Specified by:
getProducts
in interfaceProducer
- Returns:
- The set of products produced by this producer instance.
-
visitBefore
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException
Description copied from interface:BeforeVisitor
Visits the beginning of anElement
.- Specified by:
visitBefore
in interfaceBeforeVisitor
- Parameters:
element
- theElement
representing the beginning of the fragment. TheElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false. TheElement
's child nodes are not traversable.executionContext
- the currentExecutionContext
- Throws:
SmooksException
-
popCreator
public Document popCreator(ExecutionContext executionContext)
-
visitAfter
public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException
Description copied from interface:AfterVisitor
Visits the end of anElement
.- Specified by:
visitAfter
in interfaceAfterVisitor
- Parameters:
element
- theElement
representing the end of the fragment. TheElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false. TheElement
's child nodes are traversable if one of the following conditions are met:max.node.depth
global config parameter is set to 0 or greater than 1, or- this
AfterVisitor
implementsParameterizedVisitor.getMaxNodeDepth()
which returns an integer greater than 1
executionContext
- the currentExecutionContext
- Throws:
SmooksException
-
-