Incorporating User-Written Code into Visual Composites

Although VisualAge enables you to compose and generate user interface beans, you will probably want to write other beans yourself at some point. These are typically nonvisual beans that provide business logic. You can either create a new bean and write the code to support its features, or you can define bean interface features for code you have already written.

If you just need to extend the function of the bean, you can probably accomplish this by using code connections. As a last resort, you can modify generated code for the bean.

Assembling a Bean from Generated and User-Written Code

Before you get started, read the related conceptual topic about generated code.

  1. Design the bean interface.
  2. Define the bean interface in the BeanInfo page. VisualAge generates source code for the interface features in the bean class. It also generates descriptor methods for the bean and its features in an associated BeanInfo class.
  3. Modify the feature code to provide the behavior you want.

Modifying Generated Feature Code

For properties, generated feature code is usually sufficient without modification. For method features, you must modify the feature code to add the behavior you want your bean to provide.

You can modify the feature code in the Source pane of either the Methods page or the BeanInfo page. If you choose to modify feature code for visual composites, be sure to stick to the designated user-code areas marked. Otherwise, VisualAge will overwrite your code the next time the bean is saved.

If you need to modify the signature for a method that supports a feature, follow these steps:

  1. Remove the feature in the the BeanInfo page.
  2. Modify or replace the method in the Methods page.
  3. Add the feature again in the the BeanInfo page.

Adapting User-Written Classes for Use as Beans

Before you get started, read the related conceptual topic about generated code.

  1. If you wrote a class outside of VisualAge, import the class. VisualAge interprets the bean interface using introspector design patterns.
  2. From the BeanInfo page, extend the bean interface with new features as needed. VisualAge generates a BeanInfo class when you add the first new feature. The BeanInfo class contains bean information for the bean, for the features you imported and for each new feature you add.

    If you add public methods on the Methods page, you can add them as features on the BeanInfo page. To add methods as features, select Add Available Features from the Features menu. Then, select the methods you want to add as features.

If you add a new method feature with the same name as a method you have already written, VisualAge uses the existing method. Otherwise, it generates a new method stub.


Related concepts
Visual, Nonvisual, and Composite Beans
Code Connections
Generated Code

Related procedures
Defining Bean Interfaces for Visual Composition
How Generated Code Coexists with User-Written Code
Importing Classes from the File System

Related references
Generated BeanInfo Descriptor Code (an advanced topic)