JBoss.orgCommunity Documentation

Chapter 2. Quick Start

2.1. Download Smooks Java-to-Java example
2.2. Smooks configuration file wizard
2.3. Smooks form Editor
2.4. Choosing the source/target data
2.5. Mapping

This "Quick Start" will show how to use the Smooks tools to create/edit the Smooks configuration file for Java2Java data transformation.

This chapter should give you a brief understanding of the Smooks dev tools.

Visit here to download the "java-to-java" example project.

Tip:

The example project is base on Maven, you suggest you to create a new eclipse Java project and copy the example code and .jar files from the example project paste them into the eclipse Java project.

Select the Smooks Java-to-Java example project what you created and right-click, select the menu: "New" -> "Other...", find the "Smooks Configuration File" wizard. Click "Next" button.


The first wizard page is a file path creation page. Select the "src" to be the files container, and input "smooks-newconfig.smooks". Click "Next".


The second wizard page is a transform data type choose page.

Note

As the quick start introduces how to create/edit the Java-to-Java Smooks configuration file, it's necessary that "Java" type is the source/target transform data type please.


When all the wizard steps are passed, a new Smooks configuration file is created and the Smooks editor will be opened automatically.

You will see the "Smooks Form Editor":


This editor contains several parts:

Click the data selection links to choose the transform data. The "Data Selection Wizard" is opened, and there are two data types on the list: XML and Java.


Select the "JavaBean Data Type" and click "Next", you will see a java class selection page:


When you select all the necessary java classes, click "Finish" and the structure of the java class will be displayed on the Source data tree. Please, do the same with a target data link.


As you see, the source/target data tree displays the structure of the java class.

How to map it?

First, you should know what to transform:

Make sense?

OK, let's select the "customerName" item of the "header" item on the source data tree and start to drag it. When the drag item crosses the Mapping graphical area, you will see a connection line. Drop the item onto the "customerName" of the "LineOrder" on the target data view.

Now a dialog is oped asking you to connect the root node:


Please, click "Yes" to connect the root node, if you didn't do that, this dialog will be opened again when you connect other nodes.

Note

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 the same is also relevant for XML-to-Java

Now let's do the same operation with the "customerNumber", that is what you want to see:


Next, you are going to bind the properties of the "OrderItem" to the properties of the "LineItem".

Select the "price" and drag it onto the "unitPrice" of the other side tree viewer. The error message display area will show an error:


How to deal with the error ?

Please click the "Fix it" link, a menu is popped-up with several "resolve methods" on it.

Select the first resolve method: 'Connect the "OrderItem" to the "LineItem" ', then the "OrderItem" is connected with the "LineItem".

But the notify message area still shows some other errors:


OK, let's deal with the fire error ---- Click "Fix it" link and select the first resolve method. The "orderItems" is connected with the "lineItems".

Tip

Why does the occur error?

You will find that, if you only connect the property node without connecting the parent node of the property, the "connection error" occur

The connection of the "price-to-unitPrice" is the "Binding Connection", but it needs a "Instance Creation Connection" -the connection of the "OrderItem-to-LineItem".

After that, connect the quantity to the unitQuantity ; connect the productId to the productCode:


Now, you should save the file and the Smooks tools will 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!