org.milyn.javabean
Class Value

java.lang.Object
  extended by org.milyn.javabean.BindingAppender
      extended by org.milyn.javabean.Value
All Implemented Interfaces:
org.milyn.delivery.VisitorAppender

public class Value
extends BindingAppender

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");
 

Author:
maurice.zeijen@smies.com
See Also:
Bean

Constructor Summary
Value(String beanId, String data)
          Create a Value binding configuration.
Value(String beanId, String data, Class<?> type)
          Create a Value binding configuration.
 
Method Summary
 void addVisitors(org.milyn.delivery.VisitorConfigMap visitorMap)
          Used by Smooks to retrieve the visitor configuration of this Value Configuration
 Value setDecoder(org.milyn.javabean.DataDecoder dataDecoder)
          The DataDecoder to be used for decoding the data value.
 Value setDefaultValue(String defaultValue)
          The default value for if the data is null or empty
 Value setTargetNamespace(String targetNamespace)
          The namespace for the data selector for the data value to be bound.
 Value setType(Class<?> type)
          Set the binding value data type.
 
Methods inherited from class org.milyn.javabean.BindingAppender
getBeanId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Value

public Value(String beanId,
             String data)
Create a Value binding configuration.

Parameters:
beanId - The bean id under which the value will be stored.
data - The data selector for the data value to be bound.

Value

public Value(String beanId,
             String data,
             Class<?> type)
Create a Value binding configuration.

Parameters:
beanId - The bean id under which the value will be stored.
data - The data selector for the data value to be bound.
type - Data type.
Method Detail

setTargetNamespace

public Value setTargetNamespace(String targetNamespace)
The namespace for the data selector for the data value to be bound.

Parameters:
targetNamespace - The namespace
Returns:
this Value configuration instance.

setDefaultValue

public Value setDefaultValue(String defaultValue)
The default value for if the data is null or empty

Parameters:
targetNamespace - The default value
Returns:
this Value configuration instance.

setType

public Value setType(Class<?> type)
Set the binding value data type.

Parameters:
type - The data type.
Returns:
this Value configuration instance.

setDecoder

public Value setDecoder(org.milyn.javabean.DataDecoder dataDecoder)
The DataDecoder to be used for decoding the data value.

Parameters:
targetNamespace - The DataDecoder
Returns:
this Value configuration instance.

addVisitors

public void addVisitors(org.milyn.delivery.VisitorConfigMap visitorMap)
Used by Smooks to retrieve the visitor configuration of this Value Configuration



Copyright © 2018. All rights reserved.