Programmatic Value Configurator.
This class can be used to programmatically configure a Smooks instance for creating value
objects using the Smooks DataDecoders.
This class uses a Fluent API (all methods return the Bean instance), making it easy to
string configurations together.
Example
Taking the "classic" Order message as an example and getting the order number and
name as Value Objects in the form of an Integer and String.
The Message
<order xmlns="http://x">
<header>
<y:date xmlns:y="http://y">Wed Nov 15 13:45:28 EST 2006</y:date>
<customer number="123123">Joe</customer>
<privatePerson></privatePerson>
</header>
<order-items>
<!-- .... --!>
</order-items>
</order>
The Binding Configuration and Execution Code
The configuration code (Note: Smooks instance defined and instantiated globally):
Smooks smooks = new Smooks();
Value customerNumberValue = new Value( "customerNumber", "customer/@number")
.setDecoder("Integer");
Value customerNameValue = new Value( "customerName", "customer")
.setDefault("Unknown");
smooks.addVisitors(customerNumberValue);
smooks.addVisitors(customerNameValue);
And the execution code:
JavaResult result = new JavaResult();
smooks.filterSource(new StreamSource(orderMessageStream), result);
Integer customerNumber = (Integer) result.getBean("customerNumber");
String customerName = (String) result.getBean("customerName");