1.16 Software Architectures: Chapter 8 - Component Architectures
1.16 Software Architectures: Chapter 8 - Component Architectures
Overview
8.1 Software Components
8.2 Client-Side Component Architecture
JavaBeans
Developing JavaBeans Components
8.3 Foundation for Server-Side Component Architecture
8.4 Server-Side Component Architecture
JavaBeans: Introduction
The JavaBeans technology is the component architecture for the Java platform.
It defines Java software components and how they fit together.
New applications can be build by using components.
Platform independence:
Beans are created according to the JavaBeans API specification.
Beans run in any environment which supports Java.
Platform integration:
Beans can bridge to native component models,
e.g. ActiveX, OpenDoc, LiveConnect.
Software components that use JavaBeans APIs are thus portable to containers
including Netscape, Internet Explorer, Visual Basic, Microsoft Word, Lotus Notes,
etc.
Definition: “A JavaBeans component is a reusable software component that can be
visually manipulated in builder tools.”
Chapter 8 1
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Chapter 8 2
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Classification of Beans
Components can cover a wide range of functionality.
Examples:
Visual components:
Buttons, sliders, GUI controls.
Database viewers, stock data feeds.
In-house customizable mini-applications
Word processors, spreadsheets.
Invisible server beans
JavaBeans Technologies
Key technologies explained subsequently:
Bean events and event handling
Bean properties
Introspection
Customization
Persistence
Distribution
Chapter 8 3
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Events in JavaBeans
Beans are interconnected via events.
The event model is adopted from the JDK 1.1 AWT event model: Observer pattern.
Goals are:
decoupling of Beans
ease of connecting methods to events
strong typing
Bean Properties
Bean property:
A named attribute of a Bean that can affect its behavior or its appearance.
Types of Bean Properties:
Simple
A single value whose changes are independent of changes in any other property.
Bound
A property in which a change results in notifying some other Bean.
Constrained (“vetoable”)
A property in which a change results in validation by another Bean.
The change may be rejected.
Indexed
A range of values instead of a single value is supported.
Accessible via getter/setter methods.
Beans can be interconnected using properties and methods.
Chapter 8 4
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Introspection
Problem:
When you want to include a Bean in your application, you need documentation.
This documentation should be platform independent and machine-readable (so
that a builder tool can use it).
Possible solutions:
Solution 1: Define a format for a structured text file as a component descriptor file.
Solution 2: Analyze the Bean's properties, events, and methods. → Introspection
Bean Customization
Customization allows you to
modify the appearance of a Bean
within an application builder to
make it suits your needs.
Properties are edited through
property sheets.
More complex properties like
colors and fonts have special
pop-up dialogues that coordinate
different controls.
Add property sheets for special
properties.
Customization allows you to
provide editors.
Customization also allows
you to provide customizers
(“wizards”).
Chapter 8 5
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Bean Persistence
The properties of a Bean can be changed.
How to store them?
Make the Bean object persistent.
Java supports persistence through serialization.
Distributed Beans
Distribution of Beans to support enterprise services. Examples:
Workflow applications: A form is passed around, and is filled out incrementally.
Application servers: Monitor sensor data.
Agents: Information plus behavior.
Distributed Computing Technologies:
Database
Protocol Database
JDBC JavaBeans JDBC
Component Server
Chapter 8 6
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Chapter 8 7
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Beans Development
Standard Builder
Components Tools
customize, connect,
use "off-the shelf" create new components
Developer
ship as
Application
Event sources:
Unicast: Allows only one listener to register for events.
Multicast: Allows multiple listeners to register for events.
Chapter 8 8
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Bean 1 Bean 2
Chapter 8 9
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Bean Properties
Properties can be read-only, write-only, or read-write, according to the accessor
methods.
Accessor Methods:
The name of the Bean property and the names of the property accessor methods
are dependent on each other.
For a read-write property prop of type PropType (mind capitalization!):
public PropType getProp () ;
public void setProp (PropType prop) ;
Exceptions:
Boolean properties have isProp () and setProp ().
Indexed properties have
public PropType getProp (int index) ;
public void setProp (int index, PropType prop) ;
public PropType [] getProp () ;
public void setProp (PropType [] props) ;
import java.awt.Color ;
}// ColoredBean
Chapter 8 10
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Introspection
Prerequisites for Introspection:
Reflection.
Naming convention for properties, events, and methods
(the JavaBeans specification calls this “Design Patterns”).
Introspection means...
reading the explicit information from a Bean, and
applying reflection according to the naming conventions to complete it.
Explicit information:
Developers can give specific information about their Bean by supplying an object
whose class implements java.beans.BeanInfo.
It returns information when getBeanInfo() of java.beans.Introspector is
invoked.
Reflection:
Java’s reflection ability allows to inspect objects.
Chapter 8 11
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Bean Customization
Pre-existing property editors (in java.beans.PropertyEditorManager):
BoolEditor ByteEditor
ColorEditor DoubleEditor
FloatEditor FontEditor
IntEditor LongEditor
NumberEditor StringEditor
Programmer-defined property editors:
Implement the PropertyEditor interface.
Define setValue(Object o) in a way that makes a copy of the object.
Provide a null argument constructor.
Support addition and removal of PropertyChangeListeners.
Name your editor propTypeEditor.
Implementing a Customizer is slightly more complicated.
Chapter 8 12
Software Architectures © Softwaresysteme. Alle Rechte vorbehalten.
Bean Persistence
Java supports persistence through serialization.
Serialization:
To make objects serializable, their class must implement the Serializable
interface.
Serializable objects can be written to/read from a stream.
Example: Store to/read from a file.
Serialization includes all fields of an object. Fields that must be excluded have to
be marked transient or static. This is important for
References to other Beans.
Streams.
Threads.
JavaBeans Summary
JavaBeans is the client-side component architecture of Java.
It keeps Java’s platform independence, but integrates into native models.
The technologies JavaBeans builds upon are existing Java features:
Object orientation.
Reflection.
Serialization.
Beans can be created with small effort, existing programs are often already programmed
in a “Bean-like” way.
Chapter 8 13