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
Modifier and Type | Class and Description |
---|---|
protected static class |
Bean.Binding |
Modifier and Type | Field and Description |
---|---|
protected Class<?> |
beanClass |
protected BeanInstanceCreator |
beanInstanceCreator |
protected List<Bean.Binding> |
bindings |
protected String |
createOnElement |
protected boolean |
processed |
protected org.smooks.api.Registry |
registry |
protected static Set<org.smooks.api.converter.TypeConverterFactory<?,?>> |
TYPE_CONVERTER_FACTORIES |
protected List<Bean> |
wirings |
beanId
Constructor and Description |
---|
Bean(Class<?> beanClass,
String beanId,
org.smooks.api.Registry registry)
Create a Bean binding configuration.
|
Bean(Class<?> beanClass,
String beanId,
String createOnElement,
org.smooks.api.Registry registry)
Create a Bean binding configuration.
|
Bean(Class<T> beanClass,
String beanId,
Factory<? extends T> factory,
org.smooks.api.Registry registry)
Create a Bean binding configuration.
|
Bean(Class<T> beanClass,
String beanId,
String createOnElement,
Factory<? extends T> factory,
org.smooks.api.Registry registry)
Create a Bean binding configuration.
|
Modifier and Type | Method and Description |
---|---|
List<org.smooks.api.delivery.ContentHandlerBinding<org.smooks.api.resource.visitor.Visitor>> |
addVisitors()
Add the visitors, associated with this Bean instance, to the visitor map.
|
protected void |
assertBeanClassIsCollection()
Assert that the beanClass associated with this configuration is an array or Collection.
|
protected void |
assertNotProcessed() |
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 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,
org.smooks.api.converter.TypeConverterFactory<?,?> typeConverterFactory)
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.
|
Bean |
bindTo(String dataSelector,
org.smooks.api.converter.TypeConverterFactory<String,?> typeConverterFactory)
Create a binding configuration to bind the data, selected from the message by the
dataSelector, to the target Collection/array Bean beanclass instance.
|
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,
org.smooks.api.Registry registry)
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,
Factory<T> factory,
org.smooks.api.Registry registry)
Create a Bean binding configuration.
|
getBeanId
protected static volatile Set<org.smooks.api.converter.TypeConverterFactory<?,?>> TYPE_CONVERTER_FACTORIES
protected final org.smooks.api.Registry registry
protected final BeanInstanceCreator beanInstanceCreator
protected final Class<?> beanClass
protected final String createOnElement
protected final List<Bean.Binding> bindings
protected boolean processed
public Bean(Class<?> beanClass, String beanId, org.smooks.api.Registry registry)
beanClass
- The bean runtime class.beanId
- The bean ID.public Bean(Class<T> beanClass, String beanId, Factory<? extends T> factory, org.smooks.api.Registry registry)
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, org.smooks.api.Registry registry)
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, org.smooks.api.Registry registry)
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 static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, org.smooks.api.Registry registry)
beanClass
- The bean runtime class.beanId
- The bean ID.createOnElement
- The element selector used to create the bean instance.public static <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, Factory<T> factory, org.smooks.api.Registry registry)
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 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)
org.smooks.javabean.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, org.smooks.api.converter.TypeConverterFactory<?,?> typeConverterFactory)
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 org.smooks.javabean.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, org.smooks.api.converter.TypeConverterFactory<String,?> typeConverterFactory)
dataSelector
- The data selector for the data value to be bound.typeConverter
- The org.smooks.javabean.DataDecoder
to be used for decoding
the data value.this
Bean configuration instance.public List<org.smooks.api.delivery.ContentHandlerBinding<org.smooks.api.resource.visitor.Visitor>> addVisitors()
visitorMap
- The visitor Map.public static Method getBindingMethod(String bindingMember, Class<?> beanClass)
bindingMember
- Binding member name.protected void assertBeanClassIsCollection()
protected void assertNotProcessed()
Copyright © 2024. All rights reserved.