Installation: Simply unzip the download into a folder of your choice
Steps for Running:
1. Edit the O2XMapper.bat (or O2XMapper.sh) to include the classpath for classes you wish to map.
Run the batch/sh file.
You should see the following screen
By default O2XMapper loads a sample project with 3 sample classes. All the classes are contained in a top level Mapping node, denoted by icon. Each class is denoted by icon. Notice that below each class is a list of fields available for mapping. Each field is denoted by icon. O2XMapper does several validations at Mapping, Class and Field levels. These validations attempt to ensure that all required values are entered correctly. In case of a validation error or warning, the relevant node is marked with icon.
Click on the new icon on the tool bar. This should create a new Mapping project.
Click on the add class icon. This should display a dialog box prompting you to enter the fully qualified name of your class. Remember that the class has to be available in this applications classpath for it to be loaded properly. If everything works properly you will see the class displayed below the Mapping folder on the left tree window. Otherwise you will an error dialog box, with relevant error.
Selecting the class on the tree displays the following
attributes on the right panel
XML Map-To: An optional
field prefilled by O2XMapper, populates the map-to
element in the mapping file.
XML Namespace perfix: An
optional field specifying the namespace prefix for the map-to
element
XML Namespace uri: An optional field specifying
namespace uri
If the Map-to field is not populated, a
validation warning would be displayed. However the warning can be
safely ignored in most cases.
Auto-Complete: Check
this field if you want map only a few fields and let castor do
default mapping for the remaining fields. This maps to the
auto-complete attribute in the Mapping file. See here
for more information.
Selecting a field below the class node will display slightly
more complex options. Lets go through them one by one.
Name:
A read only field indicating the name of this field.
Type:
This is the type of the field as determined through introspection.
In case the return type is a collection, this field is empty and
editable, since the
type of the elements of a collection is
unknown. If the field is left empty, a warning is displayed. This
field maps to the type
attribute in the field element of the mapping file
Transient:
Checking this will ensure that the field is ignored during
marshalling. If required is checked this field is
disabled.
Required: Indicates if the field is required. If
transient is checked, this field is disabled.
Collection:
O2XMapper attempts to examine the type of collection returned by the
field, and pre-selects the relevant type in this selection box. For
array return types the Type field is populated already (since we can
determine the type of the elements). For other types of collection,
type field is left blank.
Specify Get/Set Method: This
checkbox will enable the get/set text fields.
Get Method: This
text field maps to get-method attribute of field
element in the mapping file.
Set Method: This text field
maps to set-method attribute of field
element in the mapping file.
XML Type: This selection
indicates if this field would be represented as an attribute or an
element in the resultant xml. This maps to the type attribute of the
bind-xml
element.
XML Name: This indicates the name of the
resultant xml attribute or element. This maps to the name attribute
of the bind-xml
element.
XML Matches: This field takes a standard regular
expression and allows you to specify all element names this field
should match during unmarshalling. A * will match all xml elements
not already matched by another field. This maps to the matches
attribute of the bind-xml
element
Most of the above options are prefilled with castor defaults. Once you are done editing all the options, you can save the mapping file by clicking the save button on the toolbar. O2XMapper will do one final validation, and display any warnings at the bottom message panel. However the tool des not prevent you from saving, even if you have errors. So it is important to check all classes and ensure there are no warning icons. In case you do see a warning icon, selecting the relevant node will display the nature of error/warning in the bottom message panel. In addition you can validate the entire mapping tree by selecting Project-> Validate All option in the menu bar or by clicking the button on the toolbar.
If you want to simply preview the xml output for your current mapping, use the preview button on the toolbar, This will generate xml output in a tabbed message pane at the bottom. This option is most useful if you are using the auto-complete feature.
If you don't wan't to map all the fields of a class, simply select the class field in the left tree view and select Project->Remove Field from the menu bar. If later you decide to add the field back, use Project->Add Field option.
Thats about all you need to know to get started, Happy mapping!!!