JBoss.orgCommunity Documentation

Smooks Dev Tools Reference Guide

Version: 1.0.0.GA

November 2008


1. Introduction
1.1. What is Smooks?
1.2. What is Smooks Tools?
1.3. How to install Smooks dev tools?
2. Quick Start
2.1. Download Smooks Java-to-Java Example
2.2. Smooks Configuration File Wizard
2.3. Smooks Editor
2.4. Choosing the Source/Target Data
2.5. Mapping
3. Smooks Graphical Editor Page
3.1. Introducing the areas of graphical editor
3.2. Load Source/Target Data
3.3. Using Graphical Editor for Mapping
3.4. Error Messages
3.5. Properties View
4. Smooks Configuration Editor Page
4.1. Smooks Parse Type
4.2. Import File
4.3. Date Decoder Detail Page
5. Smooks Source Editor Page
5.1. XML Source Editor
5.2. Error Messages GUI

This chapter give you a short introduction to Smooks, Smooks tools and its installation

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.

Tip:

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.

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 opened asking you to connect the root node:


Please, click Yes to connect the root node. If you don't do that, this dialog is 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 also is relevant for XML-to-Java

Now let's do the same operation with the "customerNumber", that is what you should 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 Problems area shows 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" '. As the result 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 the Fix it link and select the first resolve method. The "orderItems" is connected with the "lineItems".

Tip:

Why does the error occur?

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

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

After that, connect "quantity" to the "unitQuantity" and "productId" to the "productCode":


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!

This chapter is packed with useful information about Smooks Graphical Editor Page usage

Smooks Graphical Editor page is one tab of the Smooks Editor.


This Graphical editor allows you to perform drug/drop operations with the nodes of transform data to map the source data to target data.

When you save the changes in the Graphical editor the correct Smooks Configuration file content is generated.

To adjust the properties of the connection lines in the editor, you should use the Properties view (activate it by following to Window > Show View > Other > General > Properties).

For example, if you defined a date decoder in the Smooks Configuration Editor, in the Properties view you can select it as a Mapping type for the "Date" type element.


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.

This section provides information about Smooks Source Editor Page