- How JavaBeans Components Are Used in Java Builder Tools
- Examples of Using JavaBeans Components in JBuilder and Forte
How JavaBeans Components Are Used in Java Builder Tools
Because a JavaBeans component is a Java class, it can be used wherever a class is applicable. You can create a JavaBeans component, access its properties, and invoke its methods in a scripting environment, just as you use regular classes. Nevertheless, JavaBeans components are specially designed for use in a builder tool that enables the bean user to visually manipulate the beans during design time. The builder tool may be a Java IDE such as Forte or JBuilder, a non-Java IDE such as Microsoft Visual Basic or Borland Delphi, a Web page builder such as Microsoft FrontPage, or even a word processor such as Microsoft Word.
A builder tool can discover the contents (properties, methods, and events) and expose them to the bean user for visual manipulation during design time. The contents are presented on a user interface, referred to as a component inspector (or simply inspector, in Forte), on which the user can update property values and register events of the bean. The JavaBeans architecture provides a core API to support builder tools that find out what is inside the beans.
A builder tool usually has an internal component, referred to as a reflector, which is responsible for communication between the bean and the component inspector during design time. The reflector analyzes the bean and presents its properties and events on the component inspector. When the bean user modifies the properties, the reflector applies the changes to the bean by invoking the set method of the properties. The relationship of the component inspector, reflector, and bean is illustrated in Figure 2.
Figure 2 During design time, the user interacts with the inspector, and the reflector controls the execution of the bean. During runtime, the bean runs just like a regular object.
The component inspector and the reflector are used during design time and play no role at runtime. If the bean follows the naming patterns for properties and events, the reflector automatically recognizes and presents it on the component inspector. If not, you have to provide a bean information class that implements the BeanInfo interface to describe the properties and events of the bean to the reflector for the inspector to reveal the properties and events to the user.