The JavaBeans API
JavaBeans technology is a component architecture for the Java 2 Platform, Standard Edition (J2SE). JavaBean components are known as beans. Beans are reusable software programs that you can develop and assemble easily to create sophisticated applications. JavaBeans technology is based on the JavaBeans specification.
The JavaBeans API and its implementation are contained in the
java.beans package. A few of the classes are used by beans while
they run in an application. For example the event classes are used
by beans that fire property and vetoable change events (see
PropertyChangeEvent
). However, most of the classes in
this package are meant to be used by a bean editor that is, a
development environment for customizing and putting together beans
to create an application. In particular, these classes help the
bean editor create a user interface that the user can use to
customize the bean. For example, a bean may contain a property of a
special type that a bean editor may not know how to handle. By
using the PropertyEditor
interface, a bean developer
can provide an editor for this special type.
The java.beans package provides support for long-term
persistence - reading and writing a bean as a textual
representation of its property values. The property values are
treated as beans, and are recursively read or written to capture
their publicly available state. This approach is suitable for
long-term storage because it relies only on public API, rather than
the likely-to-change private implementation. You read and write
beans in XML format using the XMLDecoder
and
XMLEncoder
classes, respectively. One notable feature
of the persistence scheme is that reading in a bean requires no
special knowledge of the bean.
To minimize the resources used by a bean, the classes used by
bean editors are loaded only when the bean is being edited. They
are not needed while the bean is running in an application and
therefore not loaded. This information is kept in what's called a
bean-info (see BeanInfo
). These classes is not
contained in core (real-time) library (rt.jar). You should use
additional (design-time) library (dt.jar). This library contains
bean-info classes for Swing.
Package java.beans.beancontext
provides classes and
interfaces relating to bean context. A bean context is a container
for beans and defines the execution environment for the beans it
contains. There can be several beans in a single bean context, and
a bean context can be nested within another bean context. This
package also contains events and listener interface for beans being
added and removed from a bean context.
Future plans
JSR 273: Design-Time API for JavaBeans <http://jcp.org/en/jsr/detail?id=273>
This JSR extends the JavaBeans specification and APIs to improve design-time functionality for component authors to leverage within the visual design environments in IDEs.
JSR 295: Beans Binding <http://jcp.org/en/jsr/detail?id=295>
This JSR provides an API that allows two properties of two beans to stay in sync.
Source Code & Building
The source code of the JavaBeans API and its implementation resides in the "src/share/classes" directory of the workspace. Java classes are located corresponding to the package hierarchy (eg java.beans.BeanInfo) are in "src/share/classes/java/beans/BeanInfo.java".
Non-public classes reside in:
/src/share/classes/sun/beans
The makefile structure is as follows:
make/java/beans
- builds the JavaBeans API and its implementation inpackages java.beans
and java.beans.beancontext.make/sun/beans
- builds default editors and bean-info classes.
Resources
- JavaBeans Tutorial
- JavaBeans Homepage on java.sun.com