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
 

Working With Classes

Using TopLink Workbench, you can create Java classes and packages. This section includes information on the following:

Creating Classes

Oracle recommends that you develop your Java classes using an IDE such as Oracle JDeveloper and import these existing classes into TopLink Workbench (see "Importing and Updating Classes")

However, it is sometimes convenient to create and configure classes in TopLink Workbench: for example, when generating an object model from a database schema.

This section includes information on using TopLink Workbench to create Java classes.

For more information on using TopLink Workbench to edit classes, see "Creating Classes".

Using TopLink Workbench

To create new classes and packages from within TopLink Workbench, use this procedure:

  1. Create New Class button.
    Select the project in the Navigator and click Create New Class.

    You can also right-click the project in the Navigator and choose Create New Class from the context menu or choose Selected > Create New Class from the menu.

    Figure 5-34 Add New Class Dialog Box

    Description of Figure 5-34  follows
    Description of "Figure 5-34 Add New Class Dialog Box"

Use the following information to enter data in each field on the Add New Class dialog box:

Field Description
Package Name Choose an existing package or enter a new package name. If blank, TopLink Workbench uses the default package name.
New Class Name Enter a class name. The New Class Name must be unique within the package.

For more information on using TopLink Workbench to edit classes, see "Configuring Classes".

Configuring Classes

Oracle recommends that you develop your Java classes using an IDE such as Oracle JDeveloper and import these existing classes into TopLink Workbench (see "Importing and Updating Classes")

However, it is sometimes convenient to create (see "Creating Classes") and configure classes in TopLink Workbench: for example, when generating an object model from a database schema.

This section describes using TopLink Workbench to edit classes, including the following:

Configuring Class Information

This section includes information on Using TopLink Workbench to configure class information.

Using TopLink Workbench

To configure class and superclass information, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Class tab.

    Figure 5-35 Class Tab, Class Information Fields

    Description of Figure 5-35  follows
    Description of "Figure 5-35 Class Tab, Class Information Fields"

Use the following information to enter data in each field on the tab:

Field Description
Name The name of the class. This field is for display only.
Superclass Click Browse and select a class and package that contains the class (that is, the superclass).

Configuring Class Modifiers

This section includes information on Using TopLink Workbench to configure class modifiers.

Using TopLink Workbench

To configure class modifiers, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Class tab.

    Figure 5-36 Class Tab, Class Modifier Fields

    Description of Figure 5-36  follows
    Description of "Figure 5-36 Class Tab, Class Modifier Fields"

Use the following information to enter data in each field on the tab:

Field Description
Access Modifiers Use to specify whether the class is accessible publicly or not.

Only public classes are visible to the Oracle TopLink Workbench.

Other Modifiers Specify if the class is Final or Abstract, or both. Final classes are not included in the superclass selection lists for other classes to extend.

Configuring Class Interfaces

This section includes information on Using TopLink Workbench to specify the interfaces implemented by a class. You can choose any interface in the TopLink Workbench classpath (see "Configuring Project Classpath").

Although you may add interfaces to a project directly (see "Importing and Updating Classes"), you do not need to do so in order to configure a class to implement an interface.

Using TopLink Workbench

To implement interfaces, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Class tab.

    Figure 5-37 Class Tab, Interfaces Implemented Fields

    Description of Figure 5-37  follows
    Description of "Figure 5-37 Class Tab, Interfaces Implemented Fields"

Use the following information to enter data in each field on the Interfaces Implemented tab:

Field Description
Interfaces Implemented To add an interface, click Add and select the interface and package.

To remove an interface, select the interface and click Remove


Adding Attributes

This section includes information on Using TopLink Workbench to add an attribute to a class.

Using TopLink Workbench

To add a new attribute (field) to the descriptor, click Add.

To delete an existing attribute, select the attribute and click Remove.

To rename an existing attribute, select the attribute and click on Rename.

The Attributes tab contains the following tabs:

  • General

  • Accessors

Configuring Attribute Modifiers

This section includes information on Using TopLink Workbench to configure attribute modifiers.

Using TopLink Workbench

To specify access modifiers, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Attributes tab. The Attributes tab contains two sub-tabs.

  4. Click the General tab.

    Figure 5-38 Attributes Tab, Modifiers Fields

    Description of Figure 5-38  follows
    Description of "Figure 5-38 Attributes Tab, Modifiers Fields"

Use the following information to enter data in each field on the tab:

Field Description

Access Modifiers
Specify how the attribute is accessible:
  • Public icon.

    Public

  • Protected icon.

    Protected – only visible within its own package and subclasses.

  • Private icon.

    Private – not visible for subclasses

  • Default icon.

    Default – only visible within its own package


Other Modifiers
Specify whether the attribute is Final, Static, Transient, or Volatile.

Note: Selecting some modifiers may disable others.


Configuring Attribute Type Information

This section includes information on Using TopLink Workbench to configure attribute type information.

Using TopLink Workbench

To specify attribute type information, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Attributes tab. The Attributes tab contains two sub-tabs.

  4. Click the General tab.

    Figure 5-39 Attributes Tab, Type Information Fields

    Description of Figure 5-39  follows
    Description of "Figure 5-39 Attributes Tab, Type Information Fields"

Use the following information to enter data in each field on the tab:

Field Description
Type Click Browse and select a class and package for the attribute.
Type Dimensionality Specify the length of an array. This field applies only if Type is an array.
Value Type Click Browse and select a class and package for the attribute.

This field applies for ValueHolderInterface types only.

Map Key Type Click Browse and select a class and package for the attribute.

This field applies for Map types only.

Map Value Type Click Browse and select a class and package for the attribute.

This field applies for Map types only.

Element Type Click Browse and select a class and package for the attribute.

This field applies for List types only.


Configuring Attribute Accessing Methods

This section includes information on Using TopLink Workbench to configure attribute accessing methods. If you change an attribute and regenerate the accessing methods, TopLink does not remove any previously generated methods.

Using TopLink Workbench

To specify attribute accessing methods, use this procedure:

Use the following information to complete the fields on the Accessors tab:

Field Description
Get Method Choose the get method for the attribute.

This field applies for non-Collection types only.

Set Method Choose the set method for the attribute.

This field applies for non-Collection types only.

Add Method Choose the add method for the attribute.

This field applies for List and Map types only.

Remove Method Choose the remove method for the attribute.

This field applies for List and Map types only.

Value Holder Get Method Choose the method used to return the ValueHolderInterface type.

This field applies for ValueHolderInterface types only.

Value Holder Set Method Choose the method used to set the ValueHolderInterface type.

This field applies for ValueHolderInterface types only.

Value Get Method Choose the method used to return the actual value.

This field applies for ValueHolderInterface types only.

Value Set Method Choose the method used to set the actual value.

This field applies for ValueHolderInterface types only.


Adding Methods

This section includes information on Using TopLink Workbench to add a method to a class.

Using TopLink Workbench

To add or remove methods, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Methods tab.

    Figure 5-40 Class Info – Methods Tab

    Description of Figure 5-40  follows
    Description of "Figure 5-40 Class Info – Methods Tab"

To add a new method to the descriptor, click Add.

To delete an existing method, select the method and click Remove.

To rename an existing method, select the method and click Rename.

Configuring Method Modifiers

This section includes information on Using TopLink Workbench to configure method modifiers.

Using TopLink Workbench

To specify access modifiers, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Methods tab.

    Figure 5-41 Methods Tab, Modifiers Fields

    Description of Figure 5-41  follows
    Description of "Figure 5-41 Methods Tab, Modifiers Fields"

Use the following information to enter data in each field on the tab:

Field Description

Access Modifiers
Specify how the method can be accessed:
  • Protected icon.

    Public

  • Protected icon.

    Protected – only visible within its own package and subclasses.

  • Private icon.

    Private – not visible for subclasses.

  • Default icon.

    Default – only visible within its own package.


Other Modifiers
Specify whether the method is Abstract, Final, Synchronized, Static, or Native.

Note: Selecting some modifiers may disable others.


Configuring Method Type Information

This section includes information on Using TopLink Workbench to configure method type information.

Using TopLink Workbench

To specify method type information, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Methods tab.

    Figure 5-42 Methods Tab, Type Information Fields

    Description of Figure 5-42  follows
    Description of "Figure 5-42 Methods Tab, Type Information Fields"

Use the following information to enter data in each field on the tab:

Field Description

Return Type
Click Browse and select a class and package for the method.

Type Dimensionality
Specify the length of an array. This field applies only if Type is an array.

Configuring Method Parameters

This section includes information on Using TopLink Workbench to configure method parameters.

Using TopLink Workbench

To specify additional method parameters, use this procedure:

  1. Select a class in the Navigator. Its properties appear in the Editor.

  2. Click the Class Info tab in the Editor.

  3. Click the Methods tab.

    Figure 5-43 Attributes Tab, Class Modifier Fields

    Description of Figure 5-43  follows
    Description of "Figure 5-43 Attributes Tab, Class Modifier Fields"

Use the following information to enter data in each field on the tab:

Field Description
Type Click Browse and select a class and package for the method.
Dimensionality Specify the length of an array. This field applies only if Type is an array.

Importing and Updating Classes

This section includes information on Using TopLink Workbench to import and update Java classes.

You can import Java classes and interfaces created in any IDE.

You can import any class on the system classpath or project classpath.

If a class exists on both the system classpath and the project classpath, TopLink Workbench will update the class from the system classpath. To update or refresh from the project classpath, remove the class from the system classpath and restart TopLink Workbench.

For more information, see "Configuring Project Classpath".

Using TopLink Workbench

Use this procedure to update or refresh the classes in the TopLink Workbench project.

  1. Define the available classes and packages for the project on the General tab. See "Configuring Project Classpath" for information on classes and packages.

  2. Add or Refresh Class button.
    Click Add or Refresh Class. The Select Classes dialog box appears.

    You can also update the classes by choosing Selected > Add or Refresh Classes from the menu.

    Figure 5-44 Select Classes Dialog Box

    Description of Figure 5-44  follows
    Description of "Figure 5-44 Select Classes Dialog Box"

Select the packages or classes (or both) to import into the project and click OK. TopLink Workbench adds the new classes to your project in the Navigator.

By default, TopLink Workbench creates the following descriptor types for each package and class (depending on your project type):

See Chapter 27, "Creating a Descriptor" for more information.


Note:

If the class exists on both the system classpath and the project classpath, TopLink Workbench will update the class from the system classpath. To update or refresh from the project classpath, remove the class from the system classpath and restart TopLink Workbench.

To Remove a Class from a Project:

Remove Class button.

Select the descriptor and click Remove, or choose Selected > Remove from the menu.

Managing Nondescriptor Classes

Some of the mappings in your TopLink project may reference classes that do not have TopLink descriptors or are not included in the project.

To add, remove, or refresh Java classes that do not have TopLink descriptors, use this procedure:

From the menu, select Workbench > Manage Non-Descriptor Classes. The Manage Non-Descriptor Classes dialog box appears.

You can access the dialog box by right-clicking the TopLink project icon in the Navigator and selecting Manage Non-Descriptor Classes from the context menu.

Figure 5-45 Manage Non-Descriptor Classes Dialog Box

Description of Figure 5-45  follows
Description of "Figure 5-45 Manage Non-Descriptor Classes Dialog Box"

Select one of the following options:

  • To add new classes, click Add. The Select Classes dialog box appears.

  • To add new classes, click Add. The Select Classes dialog box appears (see Figure 5-44.

    Only classes that have been added to the project's class path can be added as nondescriptor classes. See "Configuring Project Classpath" for more information.

  • To delete an existing class, select the class and click Remove.

  • To refresh the classes (for example, if you edited the classes in an IDE), click Refresh.

Renaming Packages

When you add classes to a project, TopLink Workbench shows the classes contained in the package to which they belong (see "Using the Navigator").

You can use TopLink Workbench to change the package statements in all the Java classes of a selected package (to move the all the classes contained by the selected package to a new package). This is useful if you are refactoring an existing TopLink Workbench project.


Note:

The TopLink Workbench package rename feature is not intended for migrating projects from older versions of TopLink: for this, you must still use the TopLink Package Renamer. The Package Renamer updates import statements for TopLink classes: it does not change the package statements in user application classes.

For information on the TopLink Package Renamer, refer to Oracle TopLink Release Notes and Oracle TopLink Getting Started Guide for more information.


For more information on using TopLink Workbench to edit classes, see "Configuring Classes".

Using TopLink Workbench

To change the package of an existing class in TopLink Workbench, use this procedure:

Enter the package name and click OK. TopLink Workbench changes the name of the package in the Navigator window.

For more information on using TopLink Workbench to edit classes, see "Configuring Classes".