Transcript JavaBeans n

JavaBeans
A component architecture
What is JavaBeans?
NC World (New Computing) Dictionary:



JavaBeans n. 1. JavaSoft technology. 2.
Component object model for creating modular
applications (see object computing)
object computing n. 1. A system delivers
modular programming to the computing
mainstream (see Java)
Java n. 1. A type of object computing system that
allow you to create a variety of objects
The dream of JavaBeans is …..

Development of software by building blocks
through drag & drop
What is JavaBeans?
A Java Bean is a reusable software
component that can be manipulated visually
in a builder tool



JavaBeans is a portable, platform-independent component
model written in the Java programming language, developed
in collaboration with industry leaders.
It enables developers to write reusable components once
and run them anywhere -- benefiting from the platformindependent power of Java technology.
The goal of JavaBeans is to create a system whereby
application developers can take a set of beans from a stock
library and wire them together to make a full application
Features of JavaBeans





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
Persistent Storage
Purpose:
 To use existing data formats and plug into OLE or OpenDoc
documents (e.g., Excel doc inside a Word doc)
 To be “trivial” for the common case of a tiny Bean (by saving
its internal state)
Solutions
 Externalization: provides a Bean with full control over the
resulting data layout.
 Serialization: provides an automatic way of storing out and
restoring the internal state of a collection of Java objects
All bean must support either Serialization or Externalization
Events
A mechanism for propagating state change
notifications between a source object and one
or more target listener objects
Event Adaptors
Motivation: When additional behavior is required
during event delivery, an intermediary “event”
adaptor” class may be defined, and interposed
between an event source and the real event listener.
Examples of Event Adaptors
Implementing an event queuing
mechanism between sources and
listeners
Acting as a filter
Demultiplexing multiple event sources
onto a single event listener
Acting as a generic “wiring manager”
between sources and listeners
Properties
Discrete, named attributes of a Java Bean


that can affect its appearance or its behavior
E.g., “label” in a GUI button to represent the
displayed text
Properties show up in a number of ways:



through scripting environments (like object fields,
e.g., “b.Label=foo”)
by programming through getter and setter
methods
in a property sheet for a user to edit when a
component is customized
Typically a bean’s properties will be persistent
Introspection
A process of understanding which properties,
events, and methods a Java Bean supports at
runtime and in their builder environment
Purpose: to avoid using any separate
specification language for defining the
behavior of a Java Bean.

All of its behavior would be specifiable in Java
Solution Approaches:


Reflection: a low level mechanism to study the methods
supported by a target bean
Design patterns: to deduce from those methods what
properties, events, and public methods are supported
Customization
Ability to customize the appearance and
behavior of the various beans they are using
when a user is composing an application in
an application builder
Two ways


An application builder through GUI property sheet
(= property list + property editor)
Wizards that guide users through the different
steps of customizing a bean (for larger or complex
beans)
Automated -- Using an application
builder to construct an Applet
1. Buying the tools
2. Laying out the applet
 create a new applet and drag-and-drop
beans in the application builder
3. Customizing the beans

Select the button and edit the properties using
the application builder
4. Connecting up the beans
5. Packaging up the applet
6. Trying it out
Manually -- Using beans in a handwritten Applet
1. Loading the tools
2. Laying out the applet
- start to type in the code for a new applet
(“init” method)
3. Customizing the beans
- through calling on the beans’ property
accessor methods (e.g.,
btn.setBackground(java.awt.Color.red);)
4. Connecting up the beans
5. Packaging up the applet
6. Trying it out
FAQ 1
Why are component architectures
useful?

Developers are turning to creating components
rather than monolithic applications to free
themselves from slow, expensive application
development, and to build up a portable, reusable
code base. This enables developers to quickly
attack new market opportunities, new joint
development opportunities, and new ways to sell
smaller packages of software.
* source: http://java.sun.com/beans/faq/faq.general.html
FAQ 2
Is JavaBeans a complete component
architecture?

JavaBeans is a complete component model. It
supports the standard component architecture
features of properties, events, methods, and
persistence. In addition, JavaBeans provides
support for introspection (to allow automatic
analysis of a JavaBeans component) and
customization (to make it easy to configure a
JavaBeans component).
* source: http://java.sun.com/beans/faq/faq.general.html
FAQ 3
Are there JavaBeans components
available that I can buy today?

Yes. A large number of companies, both large and
small, have announced their plans to deliver
JavaBeans-based products including Corel,
EnterpriseSoft, Gemstone, IBM, JScape, K&A
Software, KL Group, Lotus Development, Novell,
ProtoView Development, Rogue Wave, and
Stingray Software among many others. Contact
these companies for information on product
availability. Many more companies have adopted
the JavaBeans component model, take a look at
the JavaBeans Directory. * source: http://java.sun.com/beans/faq/faq.general.html
FAQ 4
What are the security implications for
downloading Beans over the Internet?

JavaBeans does not add any security features to
the Java platform. Rather, JavaBeans components
have full access to the broad range of security
features that are part of the Java platform.
JavaBeans components can be used to build a
range of different kinds of solutions from fullfledged Java desktop applications to web-based
Applets.
* source: http://java.sun.com/beans/faq/faq.general.html
FAQ 5
Does the 100% Pure Java program
ensure compatibility and
interoperability between Beans?

The 100% Pure Java Initiative is a program
designed specifically for developers of Java
software. Sun will provide testing and
marketing support specifically for
JavaBeans components in the first half of
1998.
* source: http://java.sun.com/beans/faq/faq.general.html