Java Beans

farflungconvyancerSoftware and s/w Development

Dec 2, 2013 (3 years and 6 months ago)

75 views

1
Java Beans
Mark Morrissey
CSE 581
Spring 1999
Morrissey / CSE 58x Building Software Systems with Components 2
java.lang
java.beans
java.io
java.io
Object
Exception
Serializable
EventListener
EventObject
CLASS
INTERFACE
extends implements
Beans
FeatureDescriptor
PropertyEditorSupport
Introspector
PropertyChangeSupport
PropertyEditorManager
SimpleBeanInfo
VetoableChangeSupport
IntrospectionException
PropertyVetoException
BeanDescriptor
ParameterDescriptor
PropertyDescriptor
MethodDescriptor
EventSetDescriptor
PropertyChangeEvent
IndexedPropertyDescriptor
PropertyEditor
BeanInfo
Customizer
Visibility
VetoabilityChangeListener
PropertyChangeListener
KEY:
2
Morrissey / CSE 58x Building Software Systems with Components 3
Bean Concepts

Beans are designed to be true components that are visually
composed

However, beans are not language independent

Builder tools discover a beans properties, methods, and
events by introspection. Beans support introspection in two
ways:

design patterns - specific naming conventions

providing the
BeanInfo
interface

A Beans appearance and behavior can be customized at
design time through properties

Customization of properties occurs through either property
editors or sophisticated Bean customizers
Morrissey / CSE 58x Building Software Systems with Components 4
Bean Concepts

Events are used to communicate between beans. There are
source and listener beans.

Persistence enables beans to save their state and restore the
state later

Beans can be distributed remotely and communicate via
Java RMI
3
Morrissey / CSE 58x Building Software Systems with Components 5
Introspection

Allows an assembly tool to discover certain features of a
bean

JavaBeans use design patterns for exposing these features

Bean design patterns specify the rules for forming the
method signature, return type, and even its name

Properties are read/set in what are called getter and
setter functions

public <PropertyType> get<PropertyName>();

public void set<PropertyName> (PropertyType a);

Convention names can be avoided using BeanInfo
interface
Morrissey / CSE 58x Building Software Systems with Components 6
BeanInfo

Can be used to avoid method pattern naming conventions

If implemented, allows assembly tools to query a bean
instance explicitly for relevant interfaces names for

property getters / setters

event source and registration methods

listener methods

Signature rules are not avoided, just naming conventions
4
Morrissey / CSE 58x Building Software Systems with Components 7
Properties

A property is a discrete named attribute that can affect a
beans appearance or behavior

Properties are typically exposed using getter / setter
methods, property sheets or even the BeanInfo interface

Properties can be customized at assembly time and / or run
time

Properties exposed this way are typically persistent
component properties

For arrays of properties, the typical approach is to use
indexed properties
Morrissey / CSE 58x Building Software Systems with Components 8
Properties

Properties can also be bounds

When a bound property changes, a PropertyChangeEvent
is generated that encapsulates the locale-independent
name, old and new values

Properties can also be constrained

When a constrained property is changed, a
VetoableChangeEvent is generated and listeners can veto
the change via a PropertyVetoException
5
Morrissey / CSE 58x Building Software Systems with Components 9
Java Archive Files

A Java Archive (JAR) file is a ZIP-format archive file

like ZIP files, it can contain a manifest

The idea is to decrease the file footprint so as to download
the file faster

Also allows multiple files to be transferred at one time
Morrissey / CSE 58x Building Software Systems with Components 10
AWT Enhancements for Beans

Show up in Java 1.1

Delegation-based event model

Data Transfer and Clipboard support

Lightweight user interface framework

Printing
6
Morrissey / CSE 58x Building Software Systems with Components 11
Dele
g
ation-based Event Model

Really a forwarding-based model

The previous model used inheritance from classes and
overriding event handler methods

Created possible errors through super.() calls

Made local error handling too complex and error-prone

The new event model introduced the concept of event
sources and even listeners

Object connection and composition are used in favor of
implementation inheritance
Morrissey / CSE 58x Building Software Systems with Components 12
Data Transfer and Clipboard

Implements the idea of a universal data transfer service

Same as COM

Uses Internet MIME types to interact with non-Java applications

Java applications can also directly use Java classes

The use of MIME types allows for universal specification
of the data type

MIME is fully extensible, you can define your own MIME type

Allows distributed applications to agree on a new type without
having to invent a new way of transferring and representing the
type
7
Morrissey / CSE 58x Building Software Systems with Components 13
Li
g
htwei
g
ht UI Framework

Allows for cross-platform standardization of look and feel

Previously, so called peer classes were used for UI
components

Tightly coupled UI with local environment

Allowed UI to drift from cross-platform nature of Java

New method allows look and feel to be independent of
native environment
Morrissey / CSE 58x Building Software Systems with Components 14
Printin
g

Oops! Printing wasnt really there before 1.1

Simple components get printing for free

Print model isnt really sophisticated, but should get better

This is one area where MS components are way ahead of
beans
8
Morrissey / CSE 58x Building Software Systems with Components 15
Ob
j
ect Serialization

Prior to 1.1, only primitive types could be used for
serialization

Serialization services are now implemented via the
java.io.Serializable and java.io.Externalizable interfaces

Serializable fields no longer have to be primitive types, but
can refer to whole caches, object webs, etc.

To avoid making a field serializable, use the transient
modifier

Possible to write your own routines for serialization