Sunteți pe pagina 1din 21

Java Beans

SEED Infotech Pvt. Ltd. 1


Objectives of This Session

Describe the need for components in software


production
State what is a Bean
Demonstrate the life cycle from bean development to
a simple bean deployment in the customer’s
application
State the different types of bean properties
Demonstrate the bean event model

SEED Infotech Pvt. Ltd. 2


Need for components

Components are software pieces that can be


combined to create applications.
Components allow for rapid application
development.
If a developer knows the services provided by a
component, he never needs to know its
implementation details.

SEED Infotech Pvt. Ltd. 3


Advantages of using components

Complexity is reduced/hidden.
Reusability
Time to deliver the product is reduced.
Quality is improved.

SEED Infotech Pvt. Ltd. 4


Java Bean

A Java Bean is a reusable software component


that can be manipulated visually in a builder tool.
It’s a portable, platform-independent component
model written in Java.

SEED Infotech Pvt. Ltd. 5


Steps to create and use a bean

Write a java class/classes giving some utility.


Compile.
Write a manifest file- depicting the bean class.
Add all the classes or files related to your component in a
JAR.
Test the component in some testing tool for example BDK.
Write some application requiring the utility. Add the path of
the jar in the classpath. Create object of the bean class and
invoke the corresponding method.

SEED Infotech Pvt. Ltd. 6


Java Beans features

Introspection
Customization
Event Support
Property Manipulation
Persistence

SEED Infotech Pvt. Ltd. 7


Java Beans

Properties
Methods
Events

SEED Infotech Pvt. Ltd. 8


Java Beans

Simple Properties
Boolean Properties
Indexed Properties
Bound Properties
Constrained Properties

SEED Infotech Pvt. Ltd. 9


Java Beans

Simple Properties

X getPropertyName( )
void setPropertyName(X x )

public void setFileName(String f)


public String getFileName()

SEED Infotech Pvt. Ltd. 10


Java Beans

Boolean Properties

public boolean isPropertyName( )


public void setPropertyName(boolean b )

SEED Infotech Pvt. Ltd. 11


Java Beans

Indexed Properties

X[ ] getPropertyName( )
void setPropertyName(X[ ] x )
X getPropertyName( int i )
void setPropertyName(int i , X x )

SEED Infotech Pvt. Ltd. 12


Bound Properties

private PropertyChangeSupport pcs = new


PropertyChangeSupport( this)
public void
addPropertyChangeListener(PropertyChangeListener l)
public void
removePropertyChangeListener(PropertyChangeListener l)
pcs.firePropertyChange(String property name, Object oldVal,
Object newVal)
somebean.addPropertyChangeListener(this);
void propertyChange(PropertyChangeEvent e )

SEED Infotech Pvt. Ltd. 13


Constrained Properties

private VetoableChangeSupport pcs = new


VetoableChangeSupport( this)
public void
addVetoableChangeListener(VetoableChangeListener l)
public void
removeVetoableChangeListener(VetoableChangeListener l)
pcs.fireVetoableChange(String property name, Object oldVal,
Object newVal)
somebean.addVetoableChangeListener(this);
void VetoableChange(PropertyChangeEvent e )

SEED Infotech Pvt. Ltd. 14


Java Beans

Write a java class


Have a default constructor
Write properties according to Naming Pattern
Compile and get all the .class files in one dir
Create a manifest file
Jar all the files together
Load it in the Builder

SEED Infotech Pvt. Ltd. 15


JAR

Some options of this command:


c : Create a new archive
v : generate a verbose output
f : first file is a jar file
m : a manifest file follows

SEED Infotech Pvt. Ltd. 16


Manifest file

Used by jar utility to describe the contents of the


jar file.
Sample .mf file
Name: SomeBean.class
Java-Bean: True

SEED Infotech Pvt. Ltd. 17


Beans Development Kit (BDK)

BeanBox
Properties
ToolBox
Sample Beans

SEED Infotech Pvt. Ltd. 18


JavaBean life cycle

Development
Design time
Run time

SEED Infotech Pvt. Ltd. 19


BDK

Support early development of Java Beans


is a test container for your Java Beans.
Allows programmers to preview how a bean will
be displayed & manipulated in a builder tool.

SEED Infotech Pvt. Ltd. 20


Windows of BeanBox

Toolbox window: contains demo Java Beans


BeanBox window: used to test a bean.
Properties window: allows to customize the
currently selected bean
Method tracer window: displays simple
debugging messages & helps trace method calls.

SEED Infotech Pvt. Ltd. 21

S-ar putea să vă placă și