"JavaBeans component architecture is the platform-neutral architecture for the Java application environment. It's the ideal choice for developing or assembling network-aware solutions for heterogeneous hardware and operating system environments--within the enterprise or across the Internet. In fact, it's the only component architecture you should consider if you're developing for the Java platform".
Sun Microsystems Inc. Note to the developers: This documentation is not included as replacement of the JavaBeans (TM) documentation. Here we describe basic JavaBeans concepts but it is done only to describe BeanExplorer technology. All developers are encouraged to study JavaBeans specification prior or along with BeanExplorer documentation. Visit http://java.sun.com/products/javabeans/ for more details.What is a JavaBean? Bean Info Property Accessor methods Indexed Properties Property attributes
A Java Bean is a reusable software component that can be manipulated visually in a builder tool. Some Java Beans may be simple GUI elements such as buttons and sliders. Other Java Beans may be sophisticated visual software components such as database viewers, or data feeds. Individual Java Beans will vary in the functionality they support, but the typical unifying features that distinguish a Java Bean are: Support for "introspection" so that a builder tool can analyze how a bean works. Support for "customization" so that when using an application builder a user can customize the appearance and behavior of a bean. Support for "events" as a simple communication metaphor than can be used to connect up beans Support for "properties", both for customization and for programmatic use. Support for persistence, so that a bean can be customized in an application builder and then have its customized state saved away and reloaded later.
A bean is not required to inherit from any particular base class or interface. Visible beans must inherit from java.awt.Component so that they can be added to visual containers, but invisible beans aren't required to do this. All the key APIs such as events, properties, and persistence, have been designed to work well both for human programmers and for builder tools. Many beans will have a strong visual aspect, in both the application builder and in the final constructed application, but while this is common it is not required.
A bean implementer who wishes to provide explicit information about their bean may provide a BeanInfo class that implements this BeanInfo interface and provides explicit information about the methods, properties, events, etc, of their bean. A bean implementer doesn't need to provide a complete set of explicit information. You can pick and choose which information you want to provide and the rest will be obtained by automatic analysis using low-level reflection of the bean classes' methods and applying standard design patterns. Similarly to its properties JavaBean itself contains special descriptors named bean descriptor (see BeanDescriptor) which consist of the same set of attributes as property descriptor and additionally have an information about Java class that must be used to customize the JavaBean as a whole. Definition of BeanInfo for the component along with generation of Jave code are a main purposes of BeanInfo Editor provided with BeanExplorer. In addition to standard attributes of the properties BeanExplorer defines additional ones useful in many applications. Most important of these attributes: · Read-only flag that can by dynamically changed when JavaBean is executed · Default values to be used when property contain null value · Help topic identifier to be used for accessing online help In addition to property descriptors BeanInfo allows the developer to obtain event descriptors containing information about the events the JavaBean component can fire; method descriptors containing information about externally visible methods of this JavaBean (note that most JavaBean developers rarely define these). 
The most important feature of a JavaBean is the set of properties. Basically properties are named attributes associated with a bean that can be read or written by calling appropriate methods on the bean. Thus for example, a bean might have a "foreground" property that represents its foreground color. This property might be read by calling a Color getForeground() method and updated by calling a void setForeground(Color c) method. The methods a Java Bean exports are just normal Java methods which can be called from other components or from a scripting environment. By default all of a bean's public methods will be exported, but a bean can choose to export only a subset of its public methods . Properties are always accessed via method calls on their owning object. For readable properties there will be a getter method to read the property value. For writable properties there will be a setter method to allow the property value to be updated. Thus even when a script writer types in something such as b.label = foo there is still a method call into the target object to set the property, and the target object has full programmatic control. So properties need not just be simple data fields, they can actually be computed values. Updates may have various programmatic side effects. For example, changing a bean's background color property might also cause the bean to be repainted with the new color. For simple properties the accessor type signatures are:
void setFoo(PropertyType value); // simple setter
PropertyType getFoo(); // simple getter setFoo and getFoo are simply example names. Accessor methods can have arbitrary names.
In addition to simple single-value properties, bean technology supports indexed properties. An indexed property supports a range of values. Whenever the property is read or written you just specify an index to identify which value you want. Property indexes must be Java ints. int indexes are in practice the most common and useful kind of property index. A component may also expose an indexed property as a single array value. For example, if there is an indexed property "fred" of type string it may be possible from a scripting environment to access an individual indexed value using b.fred[3] and also to access the same property as an array using b.fred. For indexed properties the accessor type signatures are:
void setter(int index, PropertyType value); // indexed setter
PropertyType getter(int index); // indexed getter
void setter(PropertyType values[]); // array setter
PropertyType[] getter(); // array getter
The indexed getter and setter methods may throw a java.lang.ArrayIndexOutOfBoundsException runtime exception if an index is used that is outside the current array bounds. In order to change the size of the array you must use the array setter method to set a new (or updated) array. Though this concept is introduced there's no common understanding of how to use indexed properties provided by Sun and only BeanExplorer utilizes indexed properties to full extent (see Array Properties below). Every property has the set of attributes or metadata associated with it. JavaBeans specification defines the following attributes of properties (see PropertyDescriptor for more details): Programmatic name - name that programmers will use to look up the property; Display name - localized name under which property should be present to humans; Short description - more detailed description of the property useful for instance in tooltips; Editor class - Java class that must be used to edit value of the property; - Various flags:
expert, preferred, hidden - describing how critical is property depending on context where it is used; Bound attribute - allows other components to bind special behaviour to property changes; Constrained attribute - supports the PropertyVetoException; Read/write methods - allows to define getter/setter method as alternative for accessor type signature agreement.
This meta information about properties retrieved using property descriptors (see PropertyDescriptor).
|