public class Bean extends BindingAppender
<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-item> <product>111</product> <quantity>2</quantity> <price>8.90</price> </order-item> <order-item> <product>222</product> <quantity>7</quantity> <price>5.20</price> </order-item> </order-items> </order>
public class Order { private Header header; private List<OrderItem> orderItems; } public class Header { private Long customerNumber; private String customerName; } public class OrderItem { private long productId; private Integer quantity; private double price; }
Smooks smooks = new Smooks(); Bean orderBean = new Bean(Order.class, "order", "/order"); orderBean.bindTo("header", orderBean.newBean(Header.class, "/order") .bindTo("customerNumber", "header/customer/@number") .bindTo("customerName", "header/customer") ).bindTo("orderItems", orderBean.newBean(ArrayList.class, "/order") .bindTo(orderBean.newBean(OrderItem.class, "order-item") .bindTo("productId", "order-item/product") .bindTo("quantity", "order-item/quantity") .bindTo("price", "order-item/price")) ); smooks.addVisitors(orderBean);And the execution code:
JavaResult result = new JavaResult(); smooks.filterSource(new StreamSource(orderMessageStream), result); Order order = (Order) result.getBean("order");
Value
Constructor and Description |
---|
Bean(Class<?> beanClass,
String beanId)
Create a Bean binding configuration.
|
Bean(Class<?> beanClass,
String beanId,
String createOnElement)
Create a Bean binding configuration.
|
Bean(Class<?> beanClass,
String beanId,
String createOnElement,
String createOnElementNS)
Create a Bean binding configuration.
|
Bean(Class<T> beanClass,
String beanId,
Factory<? extends T> factory)
Create a Bean binding configuration.
|
Bean(Class<T> beanClass,
String beanId,
String createOnElement,
Factory<? extends T> factory)
Create a Bean binding configuration.
|
Bean(Class<T> beanClass,
String beanId,
String createOnElement,
String createOnElementNS,
Factory<? extends T> factory)
Create a Bean binding configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
addVisitors(VisitorConfigMap visitorMap)
Add the visitors, associated with this Bean instance, to the visitor map.
|
Bean |
bindTo(Bean bean)
Add a bean binding configuration to this Collection/array bean binding config.
|
Bean |
bindTo(String dataSelector)
Create a binding configuration to bind the data, selected from the message by the
dataSelector, to the target Collection/array Bean beanclass instance.
|
Bean |
bindTo(String bindingMember,
Bean bean)
Add a bean binding configuration for the specified bindingMember (field/method) to
this bean binding config.
|
Bean |
bindTo(String dataSelector,
DataDecoder dataDecoder)
Create a binding configuration to bind the data, selected from the message by the
dataSelector, to the target Collection/array Bean beanclass instance.
|
Bean |
bindTo(String bindingMember,
String dataSelector)
Create a binding configuration to bind the data, selected from the message by the
dataSelector, to the specified bindingMember (field/method).
|
Bean |
bindTo(String bindingMember,
String dataSelector,
DataDecoder dataDecoder)
Create a binding configuration to bind the data, selected from the message by the
dataSelector, to the target Bean member specified by the bindingMember param.
|
static Method |
getBindingMethod(String bindingMember,
Class<?> beanClass)
Get the bean binding class Member (field/method).
|
Bean |
newBean(Class<?> beanClass,
String createOnElement)
Create a Bean binding configuration.
|
Bean |
newBean(Class<?> beanClass,
String beanId,
String createOnElement)
Create a Bean binding configuration.
|
static Bean |
newBean(Class<?> beanClass,
String beanId,
String createOnElement,
String createOnElementNS)
Create a Bean binding configuration.
|
<T> Bean |
newBean(Class<T> beanClass,
String createOnElement,
Factory<T> factory)
Create a Bean binding configuration.
|
<T> Bean |
newBean(Class<T> beanClass,
String beanId,
String createOnElement,
Factory<T> factory)
Create a Bean binding configuration.
|
static <T> Bean |
newBean(Class<T> beanClass,
String beanId,
String createOnElement,
String createOnElementNS,
Factory<T> factory)
Create a Bean binding configuration.
|
getBeanId
public Bean(Class<?> beanClass, String beanId)
beanClass
- The bean runtime class.beanId
- The bean ID.public Bean(Class<T> beanClass, String beanId, Factory<? extends T> factory)
beanClass
- The bean runtime class.beanId
- The bean ID.factory
- The factory that will create the runtime objectpublic Bean(Class<?> beanClass, String beanId, String createOnElement)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.public Bean(Class<T> beanClass, String beanId, String createOnElement, Factory<? extends T> factory)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.factory
- The factory that will create the runtime objectpublic Bean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.createOnElementNS
- The namespace for the element selector used to create the bean instance.public Bean(Class<T> beanClass, String beanId, String createOnElement, String createOnElementNS, Factory<? extends T> factory)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.createOnElementNS
- The namespace for the element selector used to create the bean instance.factory
- The factory that will create the runtime objectpublic static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.createOnElementNS
- The namespace for the element selector used to create the bean instance.public static <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, String createOnElementNS, Factory<T> factory)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.createOnElementNS
- The namespace for the element selector used to create the bean instance.factory
- The factory that will create the runtime objectpublic Bean newBean(Class<?> beanClass, String createOnElement)
Smooks
instance
supplied in the constructor. The beanId is generated.beanClass
- The bean runtime class.createOnElement
- The element selector used to create the bean instance.this
Bean configuration instance.public <T> Bean newBean(Class<T> beanClass, String createOnElement, Factory<T> factory)
Smooks
instance
supplied in the constructor. The beanId is generated.beanClass
- The bean runtime class.createOnElement
- The element selector used to create the bean instance.factory
- The factory that will create the runtime objectthis
Bean configuration instance.public Bean newBean(Class<?> beanClass, String beanId, String createOnElement)
Smooks
instance
supplied in the constructor.beanClass
- The bean runtime class.beanId
- The beanId.createOnElement
- The element selector used to create the bean instance.this
Bean configuration instance.public <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, Factory<T> factory)
Smooks
instance
supplied in the constructor.beanClass
- The bean runtime class.beanId
- The beanId.createOnElement
- The element selector used to create the bean instance.factory
- The factory that will create the runtime objectthis
Bean configuration instance.public Bean bindTo(String bindingMember, String dataSelector)
DataDecoder
through the specified
bindingMember.bindingMember
- The name of the binding member. This is a bean property (field)
or method name.dataSelector
- The data selector for the data value to be bound.public Bean bindTo(String bindingMember, String dataSelector, DataDecoder dataDecoder)
bindingMember
- The name of the binding member. This is a bean property (field)
or method name.dataSelector
- The data selector for the data value to be bound.dataDecoder
- The DataDecoder
to be used for decoding
the data value.this
Bean configuration instance.public Bean bindTo(String bindingMember, Bean bean)
bindingMember
- The name of the binding member. This is a bean property (field)
or method name. The bean runtime class should match thebean
- The Bean instance to be boundthis
Bean configuration instance.public Bean bindTo(Bean bean) throws IllegalArgumentException
IllegalArgumentException
if the check fails.bean
- The Bean instance to be boundthis
Bean configuration instance.IllegalArgumentException
- this
Bean's beanClass (not the supplied bean!) is
not a Collection/array. You cannot call this method on Bean configurations whose beanClass is not a
Collection/array. For non Collection/array types, you must use one of the bindTo meths that specify a
'bindingMember'.public Bean bindTo(String dataSelector)
dataSelector
- The data selector for the data value to be bound.this
Bean configuration instance.public Bean bindTo(String dataSelector, DataDecoder dataDecoder)
dataSelector
- The data selector for the data value to be bound.dataDecoder
- The DataDecoder
to be used for decoding
the data value.this
Bean configuration instance.public void addVisitors(VisitorConfigMap visitorMap)
visitorMap
- The visitor Map.Copyright © 2020. All rights reserved.