Professional Documents
Culture Documents
JavaBeans Component
Development
SL-292
Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
Module Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Introduction to Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Introspection Addresses Key Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Sample Uses for BeanInfo . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
The Introspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
Summary of the Introspection Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
Naming Conventions for Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Naming Conventions for Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
Naming Conventions for Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
How a Bean Is Analyzed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Beans.instantiate Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
Instantiation Supports Customized Beans and Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
Introspector.getBeanInfo Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Information Discovered by getBeanInfo . . . . . . . . . . . . . . . . . . . 5-18
What Is BeanInfo? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20
SimpleBeanInfo Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
A BeanInfo Class That Affects Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Using getAdditionalBeanInfo . . . . . . . . . . . . . . . . . . . . . . . 5-24
BeanInfo Class That Affects Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25
Details of How a BeanInfo Is Processed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26
Available BeanInfo Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27
Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
Module Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Goals for Bean Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Java Object Serialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
What Is and Is Not Saved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
Input and Output Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Saving Beans to Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
Retrieving Beans From Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Creating a Java Beans Prototype. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Deserialization and Class Loaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
Recap of Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
Exercise: Creating a New Bean Through Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Check Your Progress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13
Think Beyond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14
Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1
Module Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
What Can You Do Through Customization? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Property Sheets and Property Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Review of Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5
The PropertyEditor Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6
Overview of the PropertyEditor Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
Creating Your Own Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8
Null Argument Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9
Preface
Course Goal
Provide you with knowledge and skills to:
• Create reusable Bean components
• Create Bean properties
• Understand how introspection and reflection works
• Work with the Bean event model
• Customize and persist Beans
Course Overview
• Use Bean components to create new applications.
• Beans are created using conventions in the JavaBeans
API specification.
• Beans can bridge to non-Java component models.
• Beans run in any environment where Java technology is
supported.
Persistence Customization
Optional
Transitional Beans
Module-by-Module Overview
• Module 1 – Overview of JavaBeans
• Module 2 – The BeanBox
• Module 3 – The Bean Event Model
• Module 4 – Bean Properties
• Module 5 – Introspection
• Module 6 – Persistence
• Module 7 – Customization
Module-by-Module Overview
• Module 8 – Event Adapters
• Module 9 – Distributed Computing With Beans
• Module 10 – Beans Outside of the BeanBox
• Module 11 – Business Environment for JavaBeans
• Module 12 – Transitional Beans (Optional)
Module
Skills Gained 1 2 3 4
Skill or Objective 1
Skill or Objective 2
Skill or Objective 3
Skill or Objective 4
Introductions
• Name
• Company affiliation
• Title, function, and job responsibility
• Distributed computing experience
• Component development experience
• Application builder tool experience
• Reasons for enrolling in this course
• Expectations for this course
• Discussion
• Laboratory
• Reference
Typeface or
Meaning Example
Symbol
AaBbCc123 The names of commands, Edit your .login file.
files, and directories; Use ls -a to list all files.
on-screen computer output system% You have mail.
Typeface or
Meaning Example
Symbol
AaBbCc123 Book titles, new words or Read Chapter 6 in User’s
terms, or words to be Guide. These are called class
emphasized options.
You must be root to do this.
Module 1
Overview of JavaBeans
Module Overview
• Course map
• Relevance
• Objectives
• References
What Is JavaBeans?
• A Java component model
• JavaBeans APIs
• Extension of Java platform
What Is a Bean?
• Definition
• Features of Beans
• Examples of Beans
• Classes and Beans
Component Architectures
• Why are they useful?
• Services of component models
• Component interface publishing and discovery
• Event handling
• Persistence
• Layout control
• Application builder support
Hashed boundary
around the BeanBox
Bean indicates
the currently selected
Bean
Component-based
application
ActiveX API
OLE OLE
control document
OCX Java
Components control Bean
• Advantages of ActiveX
Think Beyond
Suppose you have written a few Java Beans.
You now wish to test how well your Beans work.
Can you do this within the BDK? Do you need a third-party
builder tool?
Module 2
The BeanBox
Module Overview
• Course map
• Relevance
• Objectives
• References
Hashed boundary
around the BeanBox
Bean
Manipulating a Bean
• Placing a Bean on the BeanBox window
• Selecting a Bean
• Moving a Bean
• Resizing a Bean
Bound Properties
• Source Bean with the bound property
• Target Bean and target property
• Mechanics of connecting them
• Edit ➤ Bind property
• Selecting source property
• Selecting target Bean and target property
• What happens after Beans are connected
Using JAM
• Description of JAM (Just Another Make)
• Jamfile and manifest.tmp templates
and so on
JamfilesSource files course_examples solutions
get_started
jars demo beanbox
sunw
run command
and so on
Think Beyond
• How does the event handling work for Beans?
• How do you define your own events?
• How do you indicate you want to receive a particular
event?
Module 3
Module Overview
• Course map
• Relevance
• Objectives
• References
What Is an Event?
• Definition
• Examples
• Window events
• Mouse events
• Keyboard events
• List events
• Scrolling events
Code Explanation
Key items in the code:
Categories of Events
• Category – XXX
• Action, Item, Mouse motion, Mouse button, Key,
Focus, Adjustment, Component, Window,
Container, Text
• Interface – XXXListener
• ActionListener, ItemListener, and so on
• Event – XXXEvent
• ActionEvent, ItemEvent, MouseEvent, and so on
Listeners
• Identify listeners
• Listener interfaces
• ActionListener Interface
1 package java.awt.event;
2 import java.util.EventListener;
3
4 /**
5 * The listener interface for receiving action events.
6 */
7 public interface ActionListener extends EventListener {
8 /**
9 * Invoked when an action occurs.
10 */
11 public void actionPerformed(ActionEvent e);
12 }
Event Sources
• Common sources
• Creating your own source
• Identifying sources
• addXXXListener
• removeXXXListener
Multicast Syntax
1 private Vector listeners = new Vector();
2
3 public void addStockPriceChangeListener(StockPriceChangeListener spcl) {
4 listeners.addElement(spcl);
5 }
6
7 public void
8 removeStockPriceChangeListener(StockPriceChangeListener spcl) {
9 listeners.removeElement(spcl);
10 }
Unicast Syntax
1 private StockPriceChangeListener listener = null;
2
3 public void addStockPriceChangeListener(StockPriceChangeListener spcl)
4 throwsjava.util.TooManyListenersException
5 {
6 if (listener == null) {
7 listener = spcl;
8 } else {
9 throw new java.util.TooManyListenersException();
10 }
11 }
12
13 public void removeStockPriceChangeListener(StockPriceChangeListener spcl) {
14 if (listener == spcl) {
15 listener = null;
16 }
17 }
Stock Class
1 package sl292.stock;
2
3 public class Stock {
4 String company;
5 String symbol;
6 double price;
7
8 public Stock(String co, String sym, double p) {
9 company = co;
10 symbol = sym;
11 price = p;
12 }
13
14 public void setCompany(String co) { company = co; }
15
16 public String getCompany() { return company; }
17
18 public void setSymbol(String sym) { symbol = sym; }
19
20 public String getSymbol() { return symbol; }
21
22 public double getPrice() { return price; }
23
24 public void setPrice(double p) { price = p;}
25 }
StockPriceChangeEvent Code
1 package sl292.stock;
2
3 import java.util.EventObject;
4
5 public class StockPriceChangeEvent extends EventObject {
6 private Stock stock;
7
8 public StockPriceChangeEvent(Object source, Stock s) {
9 super(source);
10 stock = s;
11 }
12
13 public Stock getStock() { return stock; }
14 }
1 package sl292.stock;
2
3 import java.util.EventListener;
4
5 public interface StockPriceChangeListener extends EventListener {
6 public void priceChange(StockPriceChangeEvent e);
7 }
Think Beyond
In working with the BeanBox, different properties were
displayed in the PropertySheet window for each Bean you
selected on the Composition window.
Module 4
Bean Properties
Module Overview
• Course map
• Relevance
• Objectives
• References
Simple Properties
• Defining simple properties
• Adding simple properties to a Bean
Color property
Radius property
Bound Properties
• Defining bound properties
• PropertyChangeSupport class
• Modifying the property set method
• Fire the PropertyChangeEvent
Constrained Properties
• Overview
• Order things are done in setXXX
• Defining constrained properties
• set method throws PropertyVetoException
• Handling vetos
• What the source Bean is responsible for
Constrained Properties
• Using the VetoableChangeSupport Class
• Utility class similar to PropertyChangeSupport
• What the utility class does for you
• Registering listeners
• Modifying the property set method
• Calls the fireVetoableChange() method of the
VetoableChangeSupport object
PropertyCanvas
views
Think Beyond
• What exactly is introspection?
Module 5
Introspection
Module Overview
• Course map
• Relevance
• Objectives
• References
Introduction to Introspection
• What problem does introspection solve?
• Code integration problem
• JavaBeans vision
• Introspection makes vision a reality
Definitions
• Reflection
• Naming conventions
• Introspection
• BeanInfo
The Introspector
• What is the Introspector?
• Follows a plan for filling out Descriptor classes
• Finds information using BeanInfo classes and
getBeanInfo()
• Uses Reflection API classes
Beans.instantiate Method
• The builder tool instantiates a Bean using:
beanName = "beanco.chart.PieChart";
bean = (Component) Beans.instantiate( classLoader, beanName);
Introspector.getBeanInfo Method
• Called after Beans.instantiate()
• Code similar to:
beanClass = Class.forName("beanco.chart.PieChart");
BeanInfo bi = Introspector.getBeanInfo(beanClass);
Information Discovered by
getBeanInfo
CLASS: sl292.dataTable.DataTableBean
Properties:
rowsintgetRows/setRows
cellSizeintgetCellSize/setCellSize
foregroundclass java.awt.ColorgetForeground/setForeground
backgroundclass java.awt.ColorgetBackground/setBackground
fontclass java.awt.FontgetFont/setFont
nameclass java.lang.StringgetName/setName
colsintgetCols/setCols
constrainedbooleangetConstrained/setConstrained
...
Event sets:
vetoableChangeaddVetoableChangeListener/removeVetoableChangeListener
vetoableChange
mouseaddMouseListener/removeMouseListener
mouseClicked
mousePressed
mouseReleased
mouseEntered
mouseExited
...
Information Discovered by
getBeanInfo
Methods:
public void sl292.dataTable.DataTableBean.
removeVetoableChangeListener(java.beans.VetoableChangeListener)
public synchronized void sl292.dataTable.DataTableBean.setRows
(int) throws java.beans.PropertyVetoException
public boolean sl292.dataTable.DataTableBean.getConstrained()
public void sl292.dataTable.DataTableBean.
addVetoableChangeListener(java.beans.VetoableChangeListener)
public int sl292.dataTable.DataTableBean.getCellSize()
public void sl292.dataTable.DataTableBean.
fireDataTableEvent(sl292.dataTable.DataTableEvent)
public synchronized void sl292.dataTable.DataTableBean.
setCellSize(int)
public synchronized void sl292.dataTable.DataTableBean.setCols(int)
throws java.beans.PropertyVetoException
public synchronized void sl292.dataTable.DataTableBean.
setConstrained(boolean)
public int sl292.dataTable.DataTableBean.getCols()
public int sl292.dataTable.DataTableBean.getRows()
What Is BeanInfo?
• Designed to exist as a template
• A generic BeanInfo class is always built, even when
reflection is used
SimpleBeanInfo Class
• Implements the BeanInfo interface
• Defines methods specified by the interface to return
null:
• getBeanDescriptor()
• getAdditionalBeanInfo()
• getPropertyDescriptors()
• getDefaultPropertyIndex()
• getEventsSetDescriptors()
• getDefaultEventIndex()
• getMethodDescriptors()
• getIcon(int)
JavaBeans Component Development Module 5, slide 21 of 32
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services January 1999, Revision A.4
Sun Educational Services
Using getAdditionalBeanInfo
• How it can be used
1 package sl292.circle;
2 import java.beans.*;
3
4 public class CircleBeanBeanInfo extends SimpleBeanInfo {
5 public BeanInfo[] getAdditionalBeanInfo() {
6 return new BeanInfo[] { new CircleBeanAdditionalInfo() };
7 }
8 }
9 public class CircleBeanAdditionalInfo extends SimpleBeanInfo {
10 public PropertyDescriptor[] getPropertyDescriptors() {
11 try {
12 PropertyDescriptor props[] = {
13 new PropertyDescriptor("radius", CircleBean.class)};
14 props[0].setDisplayName("Radius of circle");
15 props[0].setBound(true);
16 return props;
17 } catch (IntrospectionException ex) {
18 ex.printStackTrace();
19 return super.getPropertyDescriptors();
20 }
21 }
22 }
Additional Information on
Introspection
• Public methods, reflections, and BeanInfo
• Security
Think Beyond
This module has given you a foundation to work from. Here
is a sketch of upcoming modules which will put to use many
of the methods and classes that were discussed in the course
of learning about introspection:
Module 6
Persistence
Module Overview
• Course map
• Relevance
• Objectives
• References
ObjectOutput ObjectOutputStream
java.io.DataInput
ObjectInput ObjectInputStream
Legend
Class
Interface
Extends
Implements
Think Beyond
The BeanBox provides a PropertySheet window for use in
modifying the properties of a Bean and a set of property
editors are also provided.
Module 7
Customization
Module Overview
• Course map
• Relevance
• Objectives
• References
• Customizers
PropertyCanvas
views
PropertyText
views Dialog window
Supporting setValue()
1 public class LabelEditor implements PropertyEditor {
2 String value;
3
4 public void setValue(Object value) {
5 value = (String)value;
6 }
• getTags()
• getAsText()
Extending PropertyEditorSupport
• A utility class that implements PropertyEditor
interface
• When to use
• Provided editors that extend PropertyEditorSupport
• BoolEditor
• StringEditor
• NumberEditor
Customizers
• Customizer use
• Characteristics of customizers
• Naming conventions
Defining BeanInfo
import java.beans.*;
Extending Component/Implementing
Customizer
• Extend Component or its subclasses
• Implement the Customizer interface
• Use a null argument constructor
import java.beans.*;
Defining setObject()
public void setObject(Object beanToCustomize) {
private MyBean bean = (MyBean) beanToCustomize;
// Code to get current properties for "bean" and/or
// Code to build GUI elements for customizer and add them to layout.
}
Example of a Customizer
1 package sunw.demo.buttons;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.beans.*;
6
7 public class OurButtonCustomizer extends Panel
8 implements Customizer, KeyListener
9 {
10 public OurButtonCustomizer() {
11 setLayout(null);
12 }
13
14 public void setObject(Object obj) {
15 target = (OurButton) obj;
16
17 Label t1 = new Label("Caption:", Label.RIGHT);
18 add(t1);
19 t1.setBounds(10, 5, 60, 30);
20
21 labelField = new TextField(target.getLabel(), 20);
22 add(labelField);
23 labelField.setBounds(80, 5, 100, 30);
24
25 labelField.addKeyListener(this);
26 }
Example of a Customizer
40 public void keyTyped(KeyEvent e) {
41 String txt = labelField.getText();
42 target.setLabel(txt);
43 support.firePropertyChange("", null, null); // there’s only one
44 }
45
46 public void keyPressed(KeyEvent e) { }
47
48 public void keyReleased(KeyEvent e) { }
49
50 public void addPropertyChangeListener(PropertyChangeListener pl) {
51 support.addPropertyChangeListener(pl);
52 }
53
54 public void removePropertyChangeListener(PropertyChangeListener pl) {
55 support.removePropertyChangeListener(pl);
56 }
57
58 private PropertyChangeSupport support = new
59 PropertyChangeSupport(this);
60 private OurButton target;
61 private TextField labelField;
62 }
Think Beyond
The next module on adaptors addresses some of the issues
that can occur when trying to handle events that an object has
registered for.
Module 8
Event Adapters
Module Overview
• Course map
• Relevance
• Objectives
• References
XXXEvent
XXXEvent
Event
adapter
(implements
XXXListener
interface; does
decision-making)
Types of Adapters
• Demultiplexing
• Multiplexing
• Common uses of adapters
Adapter Diagrams
Event
source1 Fire
event
Forward
Event Fire Demultiplexing event Interested
source2 event adapter or call object
specific
method
Event Fire
source3 event
Interested
Fire object
event
Fire
event Interested
object
• Description of application
• Appl.java
• Widgets.java
• ActionAdapter.java
Multiplexing Adapters
Overview of multiplexer exercise:
• Receives DataEvent from test button
• Generates DataTableEvent
• Fires DataTableEvent to:
• XAxis DataTableBean
• YAxis DataTableBean
• Table DataTableBean
YAxis
Test button
fires DataEvent DataTableBean
Multiplexing
adapter
Table
DataTableBean
XAxis
DataTableBean
Think Beyond
• How can Beans be used in a distributed systems?
Module 9
Distributed Computing
With Beans
Module Overview
• Course map
• Relevance
• Objectives
• References
Database Database
J protocol
server
JavaBeans D
component B
C
JavaBeans IIOP
CORBA
component
server
JavaBeans RMI
component
Java
Server
Definition of JDBC
• JDBC API and drivers
Application
makes calls to JDBC
JDBC driver
implements API for
specific database
Database
DriverManager
Driver Driver
Connection Connection
Connection Statement
ResultSet
ResultSet ResultSet
Advantages of DataBase-Related
Beans
• Value-add to end user
• No need to understand SQL syntax to obtain data
Definition of RMI
• Overview diagram
Implementation
Class
Client Server
Application Object
Implementation
Method Call
Method Results
QuoteMonitor
RMI Bean
Server
application
Stubs Skeletons
Transport Transport
DataFactory
Constructs
DataEvent Get data information Creates
from data
retrieved
from server Data
instance
DataFactory.java DataFactoryImpl.java
(interface)
Data DataImpl.java
Data.java
(interface) instance
Data.java File
1 package sl292.rmilab;
2
3 import java.rmi.*;
4 import java.awt.Dimension;
5
6 public interface Data extends Remote{
7
8 public String getID() throws RemoteException;
9
10 public String getXLabel() throws RemoteException;
11
12 public String getYLabel() throws RemoteException;
13
14 public String [] getXAxis() throws RemoteException;
15
16 public String [] getYAxis() throws RemoteException;
17
18 public Dimension getSize() throws RemoteException;
19
20 public String [] [] getDataValues() throws RemoteException;
21 }
DataFactory.java File
1 package sl292.rmilab;
2
3 import java.rmi.*;
4
5 public interface DataFactory extends Remote{
6
7 public Data getData(String id) throws RemoteException;
8 public String [] getDataList() throws RemoteException;
9 public void addData(DataImpl dImpl) throws RemoteException;
10 }
CORBA/JavaIDL (Optional)
• Definition of JavaIDL
• What is IDL
• CORBA and RMI
Think Beyond
You have been running and testing Bean components using
the BeanBox. The BeanBox is not considered an application
builder tool.
Module 10
Module Overview
• Course map
• Relevance
• Objectives
• References
% java MyMolSer
% java BeanUnSer
sunw.demo.molecule.moleculeSerFile
Private key
Certificate
• Applet code:
1 package sl292.twoSimpleBeans;
2
3 import java.awt.Frame;
4 import java.awt.BorderLayout;
5 import java.applet.Applet;
6 import java.beans.*;
7 import java.io.*;
8
9 public class LabelChanger extends Applet {
10 public void init() {
11 MyButton myButton = null;
12 MyText myText = null;
13 try {
14 ClassLoader cl = this.getClass().getClassLoader();
15 myText = (MyText) Beans.instantiate(cl,
16 "sl292.twoSimpleBeans.MyText");
17 myButton = (MyButton) Beans.instantiate(cl,
18 "sl292.twoSimpleBeans.MyButton");
19 } catch (Exception e) {
20 throw new Error(e.toString());
21 }
Think Beyond
You have seen in this module how Beans are built, how they
are assembled into applets and applications, and how they are
delivered. You have seen the specific connecting code that is
required to glue these Beans together.
In the next module, you will see a broader display of the sort
of tools that are becoming available to enable the use of Beans
in the business environment.
Module 11
Business Environment
for JavaBeans
Module Overview
• Course map
• Relevance
• Objectives
• References
• Enterprise JavaBeans
• Review of Services
InfoBus Technology
• InfoBus technology and JavaBeans
• InfoBus architecture overview
• Data producers
• Data consumers
• Data controllers
Development Environments
• Integrated development environments (IDEs)
• Rapid application development (RAD)
Think Beyond
• What do you do if your Beans need to run in an
environment that does not support JDK 1.1?
Module 12
Transitional Beans
Module Overview
• Course map
• Relevance
• Objectives
ButtonPushEvent Class
1 package demo;
2
3 /**
4 * JDK1.1 Event Model
5 * This class describes the event that gets generated when
6 * OurButton gets pushed.
7 */
8
9 public class ButtonPushEvent extends sunw.util.EventObject {
10 public ButtonPushEvent(java.awt.Component source) {
11 super(source);
12 }
13 }
Listener Interface
1 package demo;
2
3 /**
4 * This interface describes the method that gets called when
5 * an OurButton gets pushed.
6 */
7
8 public interface ButtonPushListener extends sunw.util.EventListener {
9 public void push(ButtonPushEvent e);
10 }
Flipper Applet
33 // Add ourself as an event handler object for button pushes.
34 btn.addButtonPushListener(this);
35 }
36
37 /**
38 * This methods catches a button push event and uses it to
39 * flip the color off our JellyBean between two choices.
40 */
41
42 public void push(ButtonPushEvent evt) {
43 if (jb.getColor() == firstColor) {
44 jb.setColor(secondColor);
45 } else {
46 jb.setColor(firstColor);
47 }
48 }
49
50 private Color firstColor = Color.green;
51 private Color secondColor = Color.blue;
52 private JellyBean jb;
53 private OurButton btn;
54 }
Things to Remember
• Define JDK 1.1 event X
• Define listener interface Y
• Define AWT 1.0.2 component as source for X
• Catch 1.0.2 events and generate event X
• Notify listeners
• Create JDK 1.1 listener for X