Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Creating an XML Project From an XML Schema

If you have an existing data model (XML schema document), but you do not have a corresponding object model (Java classes for domain objects), use this procedure to create your TopLink project and automatically generate the corresponding object model.


Note:

If you have both XSD and object model classes, you can create an XML project using the procedure described in "Using TopLink Workbench".

Using the TopLink JAXB compiler simplifies JAXB application development with TopLink by automatically generating both the required JAXB files and the TopLink files from your XML schema (XSD) document. Once generated, you can open the TopLink Workbench project to fine-tune XML mappings without having to recompile your JAXB object model.

You can use the TopLink JAXB compiler from TopLink Workbench (see "Using TopLink Workbench") or from the command line (see "Using the Command Line"). Oracle recommends that you use TopLink Workbench.


Note:

Before you compile your generated classes, be sure to configure your IDE classpath to include <ORACLE_HOME>\lib\xml.jar. For example, see Chapter 4, "Using an Integrated Development Environment".

For more information, see the following:

Using TopLink Workbench

To create a new, mapped TopLink Workbench project from an XML schema using JAXB, use this procedure:

  1. From TopLink Workbench, select File > New > Project > From XML Schema (JAXB).

    Figure 21-2 Create TopLink Workbench Project using JAXB Dialog Box

    Description of Figure 21-2  follows
    Description of "Figure 21-2 Create TopLink Workbench Project using JAXB Dialog Box"

  2. Complete each field on the Create TopLink Workbench Project using JAXB dialog box, and then click OK.

Use the following information to enter data in each field of this dialog box:

Field Description
From Use these fields to specify your existing JAXB information.
    Schema File Click Browse and select the fully qualified path to your XSD file.
    JAXB Customization File This in an optional setting. It can be used if you have a standard JAXB configuration file that you wish to use to override the default JAXB compiler behavior. The JAXB customization file contains binding declarations for customizing the default binding between an XSD component and its Java representation.
To Use these fields to specify the location and options of the TopLink Workbench project.
    Output Directory Click Browse and select the path to the directory into which generated files are written. All paths used in the project are relative to this directory.
        Output Source Directory Click Browse and select the path to the directory (relative to the Output Directory) into which generated interfaces, implementation classes, and deployment files are written. Default: directory named source in the specified output directory.
        Output Workbench Project Directory Click Browse and select the path to the directory (relative to the Output Directory) into which the TopLink Workbench project files are written. Default: directory named mw in the specified output directory.
    Package Name for Generated Interfaces The optional name of the package to which generated interfaces belong. This defines your context path. If it is not specified, a package name of jaxbderived.<schema name> is used where <schema name> is the name of the schema specified by the Schema File field.
    Package Name for Generated Implementation Classes The optional name of the package to which generated implementation classes belong. This defines your context path. If it is not specified, a package name of jaxbderived.<schema name> is used where <schema name> is the name of the schema specified by the Schema File field.

The TopLink JAXB compiler generates JAXB-specific files (see "Understanding JAXB-Specific Generated Files") and TopLink-specific files (see "Understanding TopLink-Specific Generated Files").

Optionally, open the generated TopLink Workbench project (see "TopLink Workbench Project"), customize the generated mappings and descriptors, and reexport the TopLink project XML.


Note:

Before you compile your generated classes, be sure to configure your IDE classpath to include <ORACLE_HOME>\lib\xml.jar. For example, see Chapter 4, "Using an Integrated Development Environment".

Using the Command Line

To create a new, mapped Oracle TopLink Workbench project from an XML schema using JAXB from the command line, use the tljaxb.cmd or tljaxb.sh file (located in the <ORACLE_HOME>/toplink/bin directory) as follows:

  1. Using a text editor, edit the tljaxb.cmd or tljaxb.sh file to set proxy settings (if required).

    If you are using a schema that imports another schema by URL and you are operating behind a proxy, then you must uncomment the lines shown in Example 21-2 or Example 21-3 and edit them to set your proxy host (name or IP address) and port:

    Example 21-2 Proxy Settings in tljaxb.cmd

    @REM set JVM_ARGS=%JVM_ARGS% -DproxySet=true -Dhttp.proxyHost= -Dhttp.proxyPort=
    
    

    Example 21-3 Proxy Settings in tljaxb.sh

    # JVM_ARGS="${JVM_ARGS} -DproxySet=true -Dhttp.proxyHost= -Dhttp.proxyPort="
    
    
  2. Execute the tljaxb.cmd or tljaxb.sh file (located in the <ORACLE_HOME>/toplink/bin directory).

    The TopLink JAXB compiler generates JAXB-specific files (see "Understanding JAXB-Specific Generated Files") and TopLink-specific files (see "Understanding TopLink-Specific Generated Files").

    Example 21-4 illustrates how to generate an object model from a schema using the Toplink JAXB compiler. Table 21-1 lists the compiler arguments.

    Example 21-4 Generating an Object Model from a Schema with tljaxb.cmd

    tljaxb.cmd -sourceDir ./app/src -workbenchDir ./app/mw  -schema purchaseOrder.xsd -targetPkg examples.ox.model.if -implClassPkg examples.ox.model.impl
    

    Table 21-1 TopLink JAXB Binding Compiler Arguments

    Argument Description Optional?

    -help

    Prints this usage information.

    Yes

    -version

    Prints the release version of the TopLink JAXB compiler.

    Yes

    -sourceDir

    The path to the directory into which generated interfaces, implementation classes, and deployment files are written.

    Default: directory named source in the specified output directory.

    Yes

    -workbenchDir

    The path to the directory into which the TopLink Workbench project files are written.

    Default: directory named mw in the specified output directory.

    Yes

    -schema

    The fully qualified path to your XSD file.

    No

    -targetPkg

    The name of the package to which both generated interfaces and classes belong. This defines your context path. To specify a different package for implementation classes, set the -implClassPkg argument.

    Default: a package name of jaxbderived.<schema name> where <schema name> is the name of the schema specified by the -schema argument.

    Yes

    -implClassPkg

    The name of the package to which generated implementation classes belong. If this option is set, interfaces belong to the package specified by the -targetPkg argument. This defines your context path.

    Yes

    -interface

    Generate only interfaces. This argument is optional.

    Default: generate both interfaces and implementation classes.

    Yes

    -verbose

    The interfaces and classes generated. This argument is optional.

    Default: not verbose.

    Yes

    -customize

    The fully qualified path and file name of a standard JAXB customization file that you can use to override default JAXB compiler behavior.

    Yes


  3. Optionally, open the generated TopLink Workbench project (see "TopLink Workbench Project") in TopLink Workbench, customize the generated mappings and descriptors, and reexport the TopLink project XML.


    Note:

    Before you compile your generated classes, be sure to configure your IDE classpath to include <ORACLE_HOME>\lib\xml.jar. For example, see Chapter 4, "Using an Integrated Development Environment".