Generated Code

With the Visual Composition Editor, you lay out beans graphically and specify their interaction using a high-level connection model. When you save your composition, VisualAge generates Java code that maps this graphical representation to the JavaBeans component model and to the APIs for the beans themselves. The resulting generated code is best understood if you are familiar with the JavaBeans component model; in fact, it is quite similar to code that an expert JavaBeans programmer would have written by hand. If you are interested in understanding more about the code generated by VisualAge, read the JavaBeans specification first; then read the rest of this section and look at the code generated by VisualAge for different visual compositions.

Some items are generated only once; others are regenerated every time the product detects a relevant change. Some items are generated only if you have indicated to VisualAge that you want certain capabilities present in your bean. Methods that are regenerated whenever the product detects a relevant change are indicated by [Eye icon] to the right of the method signature.
Note:The code resides in the VisualAge repository, not as code files in your working directory. To get a copy of your code or compiled class in a file, you must export the class.

Code Generated from Visually Composed Beans

When you compose your bean visually, VisualAge generates much of the user interface code for you. The connections you make between beans are often sufficient to define behavior at run time. If not, you can extend it by adding your own code.

In addition to other items generated for all classes, VisualAge generates the following code for a composite bean. This code is generated when you save the bean, select Re-generate Code from the Bean menu of the Visual Composition Editor, or select (Run icon) Run:

VisualAge also generates the following methods if they do not exist:

Generated Feature Code

The term feature refers to an element of the bean interface. Features can be properties, methods, or events. To add features to the interface, use SmartGuides available from the BeanInfo page.

The following items are generated for each feature added from the BeanInfo page.

In addition, VisualAge creates a BeanInfo class when you add the first feature. After that, VisualAge updates the BeanInfo class to reflect each feature changed from the BeanInfo page.

Generated BeanInfo Descriptor Code (an advanced topic)

BeanInfo code defines the public interface of your bean in a standard way. Specifying BeanInfo code enables your bean to be used with any development tool, including VisualAge, that supports the JavaBeans specification. With BeanInfo code available, enabled tools can query an instance of your bean for information about its interface, regardless of underlying implementation.

VisualAge generates BeanInfo class code as needed to capture the interface details you specify on the BeanInfo page for your bean. If a BeanInfo class does not exist for the bean, VisualAge uses the process of reflection, matching interface features against Java design templates, to create the class. If a BeanInfo class does exist, VisualAge generates BeanInfo code only for interface elements defined as bean features (properties, methods created from the BeanInfo page, and events). For more information about reflection, see the JavaBeans specification .

The following items are generated when you add features to the bean from the BeanInfo page:

How Generated Code Coexists with User-Written Code

Generated code falls into the following categories:

Items generated only if they do not exist. These include main(java.lang.String[]), handleException(java.lang.Throwable), and getAppletInfo( ). You can write your own versions or modify generated versions; VisualAge preserves your code.

Items regenerated around handwritten changes. Most code of interest falls into this category. These methods contain the reminder comment WARNING: THIS METHOD WILL BE REGENERATED. and are indicated by [Eye icon] to the right of each method signature. The rest of this section describes how VisualAge handles this type of generated code.

In general, VisualAge preserves handwritten changes to basic class declarations, as follows:

You can add lines of code in designated areas of generated methods. VisualAge indicates these areas in the generated code with comment lines similar to the following:

//user code begin {1}
//user code end

If a generated method does not include comment lines like these, any code you add will be overwritten the next time the bean is saved.


Related concepts
How Classes and Beans Are Related
Visual Composition Editor Overview

Related procedures
Working with Beans Visually
Connecting Beans
Defining Bean Interfaces for Visual Composition

Related references
Example of Generated Feature Code
Example of Code Generated from Visual Composite
Beans for Visual Composition