JBoss.orgCommunity Documentation
Version: 1.1.0.M1
Copyright © 2009 JBoss, a division of Red Hat
November 2008
This chapter give you a short introduction to Smooks, Smooks tools and its installation
Smooks is a Java Framework/Engine for processing XML and non XML data (CSV, EDI, Java, JSON etc).
Transformation: Perform a wide range of Data Transforms. Supports many different Source and Result types -XML/CSV/EDI/Java/JSON to XML/CSV/EDI/Java/JSON.
Java Binding: Bind into a Java Object Model from any data source (CSV, EDI, XML, Java, JSON etc).
Huge Message Processing: Process huge messages (GBs) - Split, Transform and Route message fragments to JMS, File, Database etc destinations. Route multiple message formats to multiple destinations in a single pass over a message.
Message Enrichment: Enrich a message with data from a Database, or other Datasources.
Combine: Combine the above features in different ways e.g. add Message Enrichment as part of a Splitting and Routing process.
For More informations about Smooks, please visit Smooks official site.
Smooks tools is a set of graphical tools for editing Smooks configuration file based on Eclipse.
The Smooks tools was included by the JBoss Tools since 3.0.0 Beta1 version. You can download the JBoss Tools from JBoss download site.
Smooks tools (JBoss Tools) run with the latest Eclipse and other required plug-ins (GEF, EMF, etc.).
You should download the latest IDE for Java EE developers from Eclipse site. It contains many plug-ins ( GEF, EMF, etc. ) required by Smooks dev tools.
Now let's progress to more advanced topics.
This "Quick Start" will show how to use the Smooks tools to create/edit the Smooks configuration file for Java2Java data transformation.
This chapter gives you a brief understanding of the Smooks tools.
Visit here to download the "java-to-java" example project.
The example project is based on Maven, we suggest you to create a new eclipse Java project, copy the example code and .jar files from the example project and paste them into the eclipse Java project.
Select the Smooks Java-to-Java example project that you created and right-click, select the menu New > Other, then find Smooks > Smooks Configuration File. Click the Next button.
The first wizard page is a file path creation page. Select the src folder to be the files container, and input the name newConfig.smooks. Click Next.
The second wizard page is a Smooks configuration file version choose page.Select appropriate one and click finish.
When all the wizard steps are passed, a new Smooks Configuration file is created and the Smooks Configuration Editor will be opened automatically:
To choose the transform data you should click add button in the Input Data section.
After clicking the button the Data Type Selection wizard is opened, and there are two data types on the list: Java and XML.
There will become more and more data types on the list as the development goes on.
Select the Java data type and click Next, you will see the JavaBean class selection page:
Let's select the Order class from the example project as the source JavaBean class and the ListOrder class as the target JavaBean class.When you selected the necessary java classes, click Finish and you should see all added java classes displayed in the Input Data Section .
How to map the java class just added?
First, you should know what to transform:
Bind the "customerName" property of the Order#header to the "customerName" property of LineOrder.
Bind the "customerNumber" property of the Order#header to the "customerId" property of LineOrder.
Bind the "price" property of the OrderItem to the "unitPrice" property of LineItem.
Bind the "productId" property of the OrderItem to the "productCode" property of LineItem.
Bind the "quantity" property of the OrderItem to the "unitQuantity" property of LineItem.
Make sense? You should right click Resource List , select Add Smooks Resource>Java Binding>Bindings
First of all, you should bind Order to LineOrder. To do this one Bindings Item should be added to the Resource List.
Click on it and you should see Bindings Section to the right of Message Filtering Resources.Write lineOrder in the Bean id field.
Select example.trgmodel.LineOrder in the Class field and example.srcmodel.Order in the Name field.Your >Smooks Configuration Editor should look like this:
Now you should bind two values "customerNumber" property of the Order#header to the "customerId" property of LineOrder.To do this right click your just created Bindings Item >Add Smooks Resource>Value .
Please, remember that the root nodes of the source data and target data *MUST* be connected.
This rule is not only for Java-to-Java, but also is relevant for XML-to-Java
Do the same operation with the other properties in this and other classes.
Now, you should save the file and the Smooks tools generate the correct configuration file content.
OK, let run the test class: example.Main. (Please, make sure that the Smooks engine loads the correct configuration file).
Success!
In this section you will explore the details of Smooks Configuration Editor usage
Smooks Configuration Editor is one tab of the Smooks Editor.
You can add/edit/remove the Date Decoder on the Configuration page of the Smooks Editor.
The configuration editor also edits the Smooks parse type and manages the Import Files.
Open the Other Configurations section, we will see there is a set of radio buttons:
Select the needed radio button to change the Smooks parse type.
Open the Other Configurations section, there is an Import Files list under the Smooks parse type buttons (see the figure above).
There are three buttons on the right side of the File Import list. You can click those to add/edit/remove the import files.
If the import file doesn&t exist, the image of the import file is changed to "Error Image". If you double-click the import file in the Import File list, the file is opened with a new default editor.
Date Decoder is a resourceConfig element in the Smooks configuration file. It describes how to transform the "Date" type.
Click the New button to open the New Resource Type wizard dialog.
There are several resource type on the list. Select the Date Decoder and click the Finish button, a new Date Decoder item was added and shown on the resource type list.
There are several parameters in the Date Decoder resourceConfig element:
Format
Locale-Language
Locale-Country
You can modify the parameters of the Date Decoder item with the left detail page.
When you defined a new Date Decoder, then you can use the JavaBean Properties GUI to set it to be the "Java type".
Now when we've learnt Smooks Configuration Editor Page, let's have a look at one more Smooks Editor Page - Smooks Source Editor Page and investigate its functionality
This section provides information about Smooks Source Editor Page
You can use this editor to edit the Smooks Configuration file directly.
If the Smooks tools can't understand the configuration file or the configuration file is illegal (XML structure isn't right for Smooks Configuration file, etc.), the error is underlined.
We hope, our guide will help you to get started with JBoss Smooks Tools. Besides, for additional information you are welcome on JBoss forum.