Using the JAXB Wizard and Code-Seeder Palette

Constructs JAXB Object

The Constructs action generates code to instantiate JAXB objects. This code generation is useful in automating the generation of a series of getter and setter methods, especially when the JAXB object contains a series of nested objects. The code that is generated will not only instantiate the JAXB Object, but will also populate all the nested objects with initial values. This instantiation and population of values and objects can be done by passing a sample XML file. The Sample XML file needs to conform to the XSD/Schema used to generate the JAXB class. When sample XML file is not provided, all the nested JAXB members objects are instantiated.

ProcedureTo Generate Code Using the Constructs JAXB Object

  1. Drag and drop the Constructs JAXB Object icon into the IDE editor of an existing project.

    The Generate JAXB Constructs code dialog box is displayed.

    Figure 1–2 JAXB Constructs Object

    JAXB Constuct

  2. Enter the JAXB class name with the package name to be instantiated/initialized. You can also use the Find... button to search for the class (as shown below).

    Figure 1–3 Find Class Type

    Find JAXB Type

  3. Enter a sample XML file (if available) for the initialization code to use. Update the auto generated method name if required.

    Figure 1–4 Providing Sample XML File

    Sample XML File

  4. Assuming the XML file conforms to the schema used in generating JAXB classes, a method will be created (as shown below)

    Figure 1–5 Successful Method Created

    Method creation

    If the sample XML file is not provided, the code generated will not populate the default values (as shown below).

    Figure 1–6 Unpopulated Method

    unsuccessful Method creation