SlideShare a Scribd company logo
Component Based Technology
Presentation on:
Java Bean Component Model
By:
Gitansh chopra – 2K11/SE/30
Prashant Thakur – 2K11/SE/50
Javabean Component
• Java bean is a reusable software component that can be
manipulated visually in a builder tool
• Graphic bean and Non-graphic bean
• Javabean is not distributed component like EJB
• Interface of javabean is provided by
1. Design pattern(implicitly)
2. Using a class to implement the BeanInfo or Customizer
interface(explicitly)
Javabean Component
• It is a binary building block
• Development and deployment of a javabean
• Assembly javabeans to build a new javabean or a new
application, applet
• Write glue codes to wire all beans together
• javabean with CORBA as a CORBA client
• Client side javabean
• Javabean for business logic process in MVC on server
• javabean on server is not visible
Interface of a component
• This model defines four types of port:
– methods,
– properties,
– event sources and
– event sinks called listeners.
Read-only property
Write-only property
Property
Method
Event source
Event sink (listener)
Bounded property
v Vetoable property
ro
wo
1 Unicast event source
Ports
Implementations of a Bean
Components
Object
Method
Method call
Binding
A simple implementation A more complex implementation
Components Assembly
• Assembly is one of the key features of Java
Bean though no not specific solution is
provided.
– Different ways of assembling components are
supplied.
Component-based assembly Heterogeneous assembly
Advantages of Java Bean
• Write once, run anywhere
• The properties, events, and methods of a bean that are
exposed to an application builder tool can be
controlled
• They are the interface of the bean.
• They are platform independent
• Configuration setting of a bean can be saved in
persistent storage and restored later
• Bean may register and receive events from other
object and can generate event sent to other objects
(Bean communication)
JavaBean
Component
BeanInfo
Events
Methods
Properties
JARCustomizer
Design Pattern
• All beans should implement the Serializable interface so
that the state can be saved and later restored
• Methods must be made public
• All exposed methods should be threadsafe, possibly
synchronized to prevent more than one thread from calling
method at a given time
• Propertie X is exposed by public setX and getX methods
• Boolean property may be exposed by isX method which
returns a boolean value
• The bean which may trigger event must provide
addEventListener and removeEventListener mehods for
other bean to register with it to be notified
Deployment of Bean
• All java classes can be converted to a bean
• Bean is compressed and saved in the format of jar
file which contains manifest file, class files, gif
files, and other information customization files
• Sun NetBeans, BDK, Visual Café, JBuilder,
Visual Age are the bean builder tools
Criteria to be a bean
• Can this piece of code be used in more than one area?
• Can you quickly think of ways that this piece of code
might be customized?
• Is the purpose of this code easy to explain?
• Does this code module contain all the info it needs to work
itself?
• Does it have good encapsulation?
If you answer all “yes”, You should make the class a bean
JAR file
• JAR file allows you to efficiently deploy a set of classes
and their associated resources.
• JAR file makes it much easier to deliver, install, and
download. It is compressed.
Manifest file
Manifest.tmp
Name: SimpleBean.class
Java-Bean: True
...
Creating and extract a jar file
• Create a jar file
jar cfm simplebean.jar manifest.tmp *.class
• Extracting files from a jar file
jar xf simplebean.jar
Develop a New Bean
• Create a directory for the new bean
• Create the java bean source file(s)
• Compile the source file(s)
• Create a manifest file
• Generate a JAR file
• Start BDK
• Test
Working-dir can be at <bdk>demo where <bdk> is the
installation dir for BDK
Create bean source file -
SimpleBean.java
package simplebean;
import java.awt.*;
import java.io.Serializable;
public class SimpleBean extends Canvas implements
Serializable
{ public SimpleBean(){
setSize(60,40);
setBackground(Color.red);}}
Compile and make jar file
• Javac -d . SimpleBean.java
• Edit a manifest file called manifest.tmp
Name: SimpleBean.class
Java-Bean: True
• jar cfm ..jarssimplebean.jar manifest.tmp
simplebean*.class
[SimpleBean and colorsbean demo]
Introspection
• Process of analyzing a bean to determine the
capability
• Allows application builder tool to present info
about a component to software designer
• Naming convention implicit method
• BeanInfo class to explicitly infer info of a bean
Design Pattern for Properties
Property is a subset of a bean’s state which
determines the appearance and behavior of the
component
• Simple property
• Indexed Property
• Bound Property
• Constrained property
Simple Property
• Simple property has a single value.
• N is the name of the property and T is its type
• public T getN();
• public void setN(T arg)
• For readonly property there is getN() method only
Indexed Property
• One property may consists of multiple values stored in an
array
• public T getN(int index);
• public void setN(int index, T value);
• public T[] getN();
• public void setN(T values[]);
where N may be a double data[] and T is double
Bound Property
• It can generate an event when the property
is changed
• The event is of type PropertyChangeEvent
and is sent to objects that previously
registered an interest in receiving such
notifications
• bean with bound property - Event source
• Bean implementing listener -- event target
Implement Bound Property in a Bean
1. Import java.beans package
2. Instantiate a PropertyChangeSupport object
private PropertyChangeSupport changes = new
PropertyChangeSupport(this);
3. Implement methods to maintain the property change
listener list:
public void
addPropertyChangeListener(PropertyChangeListener l)
{ changes.addPropertyChangeListener(l);}
also removePropertyChangeListener method is needed
Event Source Cont.
4. Modify a property’s setter method to fire a property change
event when the property is changed.
Public void setX(int newX){
int oldx = x;
x = newX;
changes.firePropertyChange(“x”, oldX, newX);}
Implement Bound Property Listener
1. Listener bean must implement PropertyChangeListner
interface
public class MyClass implements PropertyChangeListener,
Serializable
2. It must override this method:
public abstract void propertyChange(PropertyChangeevent evt)
Constrained Property
• It generates an event when an attempt is made to change it
value
• The event type is PropertyChangeEvent
• The event is sent to objects that previously registered an
interest in receiving an such notification
• Those other objects have the ability to veto the proposed
change
• This allows a bean to operate differently according to the
runtime environment
Three Parts in Implementation of
Constrained Property
1. Source bean containing one or more constrained properties
2. Listener objects that implement the
VetoableChangeListener interface. This object either
accepts or rejects the proposed change.
3. PropertyChangeEvent object containing property name, old
value, new value.
Implement Constrained Property in a
Bean
Bean with constrained property must
1. Allow VetoableChangeListener object to register and
unregister its interest in receiving notifications
2. Fire property change at those registered listeners. The
event is fired before the actual property change takes place
Implementation of Constrained Property
in a Bean
1. Import java.beans package
2. Instantiate a VetoableChangeSupport object:
private VetoableChangeSupport vetos=new
VetoableChangeSupport(this);
3. Implement methods to maintain the property change
listener list:
public void
addVetoableChangelistener(VetoableChangelistener l)
{ vetos.addVetoableChangeListener(l);}
Cont.
4. Write a property’s setter method to fire a property change
event:
public void setX(int newX)
{ int oldX=X;
vetos.fireVetoableChange(“X”, oldX, newX);
//if no veto there
X=newX;
changes.firePropertyChange(“X”, oldX, newX); }
Implementing Constrained Property
Listeners
1. Implements the VetoableChangeListener interface which
has an abstract method
Void vetoChange(PropertyChangeEvent evt)
2. Overide this abstract method. This is the method that will
be called by the source bean on each object in the listener
list kept by vetoableChangeSupport object
Persistence
• It has the ability to save a bean to storage and retrieve it at
a later time
• Configuration settings are saved
• It is implemented by Java serialization
• If a bean inherits directly or indirectly from Component
class it is automatically Serializable.
• Transient keyword can be used to designate data members
not be saved ex. Thread reference member
Customizers
• Property sheet may not be the best user interface for a
complex component
• It can provide step-by-step wizard guide to use component
• It can provide a GUI frame with image which visually tells
what is changed such as radio button, check box, ...
• It can customize the appearance and behavior of the
properties

More Related Content

What's hot

Java beans
Java beansJava beans
Java beans
Ramraj Choudhary
 
Java Beans
Java BeansJava Beans
Java Beans
Ankit Desai
 
Beans presentation
Beans presentationBeans presentation
Beans presentation
manjusha ganesan
 
13 java beans
13 java beans13 java beans
13 java beanssnopteck
 
Java beans
Java beansJava beans
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
SURBHI SAROHA
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
Rajkiran Mummadi
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
SURBHI SAROHA
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
Nida Ismail Shah
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examples
Er. Gaurav Kumar
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
Mohammad Faizan
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
Collaboration Technologies
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
SURBHI SAROHA
 

What's hot (20)

Java beans
Java beansJava beans
Java beans
 
Java beans
Java beansJava beans
Java beans
 
Java Beans
Java BeansJava Beans
Java Beans
 
Beans presentation
Beans presentationBeans presentation
Beans presentation
 
13 java beans
13 java beans13 java beans
13 java beans
 
Java beans
Java beansJava beans
Java beans
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examples
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Swing
SwingSwing
Swing
 

Similar to Javabean1

WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
KalsoomTahir2
 
React Native Firebase
React Native FirebaseReact Native Firebase
React Native Firebase
Kobkrit Viriyayudhakorn
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
Spring introduction
Spring introductionSpring introduction
Spring introductionLê Hảo
 
Java EE web project introduction
Java EE web project introductionJava EE web project introduction
Java EE web project introduction
Ondrej Mihályi
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAjit Koti
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
Luigi Viggiano
 
Rmi, corba and java beans
Rmi, corba and java beansRmi, corba and java beans
Rmi, corba and java beansRaghu nath
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Biothings presentation
Biothings presentationBiothings presentation
Biothings presentation
Cyrus Afrasiabi
 
Yapi.js, An Adaptive Streaming Web Player
Yapi.js, An Adaptive Streaming Web PlayerYapi.js, An Adaptive Streaming Web Player
Yapi.js, An Adaptive Streaming Web Player
Jesse (Chien Chen) Chen
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Shekhar Gulati
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
Dave Haeffner
 

Similar to Javabean1 (20)

Unit4wt
Unit4wtUnit4wt
Unit4wt
 
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
React Native Firebase
React Native FirebaseReact Native Firebase
React Native Firebase
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Java EE web project introduction
Java EE web project introductionJava EE web project introduction
Java EE web project introduction
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
 
Rmi, corba and java beans
Rmi, corba and java beansRmi, corba and java beans
Rmi, corba and java beans
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Biothings presentation
Biothings presentationBiothings presentation
Biothings presentation
 
Yapi.js, An Adaptive Streaming Web Player
Yapi.js, An Adaptive Streaming Web PlayerYapi.js, An Adaptive Streaming Web Player
Yapi.js, An Adaptive Streaming Web Player
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 

More from Saransh Garg

Technical non-technical-requirement-of-cots-selection
Technical non-technical-requirement-of-cots-selectionTechnical non-technical-requirement-of-cots-selection
Technical non-technical-requirement-of-cots-selectionSaransh Garg
 
Selecting with multiple interfaces
Selecting with multiple interfacesSelecting with multiple interfaces
Selecting with multiple interfacesSaransh Garg
 
Selecting cots vendor in cbse process
Selecting cots vendor in cbse processSelecting cots vendor in cbse process
Selecting cots vendor in cbse processSaransh Garg
 
Predicting system trustworthyness
Predicting system trustworthynessPredicting system trustworthyness
Predicting system trustworthynessSaransh Garg
 
Koala component model (1)
Koala component model (1)Koala component model (1)
Koala component model (1)Saransh Garg
 
Integration in component based technology
Integration in component based technologyIntegration in component based technology
Integration in component based technologySaransh Garg
 
Embedded system.pptx
Embedded system.pptxEmbedded system.pptx
Embedded system.pptxSaransh Garg
 
Composition of cots
Composition of cotsComposition of cots
Composition of cotsSaransh Garg
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systemsSaransh Garg
 
Component object model and
Component object model andComponent object model and
Component object model andSaransh Garg
 
Component based models and technology
Component based models and technologyComponent based models and technology
Component based models and technologySaransh Garg
 
Cbt component based technology architectures
Cbt   component based technology architecturesCbt   component based technology architectures
Cbt component based technology architecturesSaransh Garg
 
Architecture support for component
Architecture support for component Architecture support for component
Architecture support for component Saransh Garg
 

More from Saransh Garg (18)

Technical non-technical-requirement-of-cots-selection
Technical non-technical-requirement-of-cots-selectionTechnical non-technical-requirement-of-cots-selection
Technical non-technical-requirement-of-cots-selection
 
Selecting with multiple interfaces
Selecting with multiple interfacesSelecting with multiple interfaces
Selecting with multiple interfaces
 
Selecting cots vendor in cbse process
Selecting cots vendor in cbse processSelecting cots vendor in cbse process
Selecting cots vendor in cbse process
 
Scs.pptx repaired
Scs.pptx repairedScs.pptx repaired
Scs.pptx repaired
 
Repo for cbt
Repo for cbtRepo for cbt
Repo for cbt
 
Rbce
Rbce Rbce
Rbce
 
Predicting system trustworthyness
Predicting system trustworthynessPredicting system trustworthyness
Predicting system trustworthyness
 
Koala component model (1)
Koala component model (1)Koala component model (1)
Koala component model (1)
 
Integration in component based technology
Integration in component based technologyIntegration in component based technology
Integration in component based technology
 
Embedded system.pptx
Embedded system.pptxEmbedded system.pptx
Embedded system.pptx
 
Cots integration
Cots integrationCots integration
Cots integration
 
Corba model ppt
Corba model pptCorba model ppt
Corba model ppt
 
Composition of cots
Composition of cotsComposition of cots
Composition of cots
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systems
 
Component object model and
Component object model andComponent object model and
Component object model and
 
Component based models and technology
Component based models and technologyComponent based models and technology
Component based models and technology
 
Cbt component based technology architectures
Cbt   component based technology architecturesCbt   component based technology architectures
Cbt component based technology architectures
 
Architecture support for component
Architecture support for component Architecture support for component
Architecture support for component
 

Javabean1

  • 1. Component Based Technology Presentation on: Java Bean Component Model By: Gitansh chopra – 2K11/SE/30 Prashant Thakur – 2K11/SE/50
  • 2. Javabean Component • Java bean is a reusable software component that can be manipulated visually in a builder tool • Graphic bean and Non-graphic bean • Javabean is not distributed component like EJB • Interface of javabean is provided by 1. Design pattern(implicitly) 2. Using a class to implement the BeanInfo or Customizer interface(explicitly)
  • 3. Javabean Component • It is a binary building block • Development and deployment of a javabean • Assembly javabeans to build a new javabean or a new application, applet • Write glue codes to wire all beans together • javabean with CORBA as a CORBA client • Client side javabean • Javabean for business logic process in MVC on server • javabean on server is not visible
  • 4. Interface of a component • This model defines four types of port: – methods, – properties, – event sources and – event sinks called listeners. Read-only property Write-only property Property Method Event source Event sink (listener) Bounded property v Vetoable property ro wo 1 Unicast event source Ports
  • 5. Implementations of a Bean Components Object Method Method call Binding A simple implementation A more complex implementation
  • 6. Components Assembly • Assembly is one of the key features of Java Bean though no not specific solution is provided. – Different ways of assembling components are supplied. Component-based assembly Heterogeneous assembly
  • 7. Advantages of Java Bean • Write once, run anywhere • The properties, events, and methods of a bean that are exposed to an application builder tool can be controlled • They are the interface of the bean. • They are platform independent • Configuration setting of a bean can be saved in persistent storage and restored later • Bean may register and receive events from other object and can generate event sent to other objects (Bean communication)
  • 9. Design Pattern • All beans should implement the Serializable interface so that the state can be saved and later restored • Methods must be made public • All exposed methods should be threadsafe, possibly synchronized to prevent more than one thread from calling method at a given time • Propertie X is exposed by public setX and getX methods • Boolean property may be exposed by isX method which returns a boolean value • The bean which may trigger event must provide addEventListener and removeEventListener mehods for other bean to register with it to be notified
  • 10. Deployment of Bean • All java classes can be converted to a bean • Bean is compressed and saved in the format of jar file which contains manifest file, class files, gif files, and other information customization files • Sun NetBeans, BDK, Visual Café, JBuilder, Visual Age are the bean builder tools
  • 11. Criteria to be a bean • Can this piece of code be used in more than one area? • Can you quickly think of ways that this piece of code might be customized? • Is the purpose of this code easy to explain? • Does this code module contain all the info it needs to work itself? • Does it have good encapsulation? If you answer all “yes”, You should make the class a bean
  • 12. JAR file • JAR file allows you to efficiently deploy a set of classes and their associated resources. • JAR file makes it much easier to deliver, install, and download. It is compressed.
  • 14. Creating and extract a jar file • Create a jar file jar cfm simplebean.jar manifest.tmp *.class • Extracting files from a jar file jar xf simplebean.jar
  • 15. Develop a New Bean • Create a directory for the new bean • Create the java bean source file(s) • Compile the source file(s) • Create a manifest file • Generate a JAR file • Start BDK • Test Working-dir can be at <bdk>demo where <bdk> is the installation dir for BDK
  • 16. Create bean source file - SimpleBean.java package simplebean; import java.awt.*; import java.io.Serializable; public class SimpleBean extends Canvas implements Serializable { public SimpleBean(){ setSize(60,40); setBackground(Color.red);}}
  • 17. Compile and make jar file • Javac -d . SimpleBean.java • Edit a manifest file called manifest.tmp Name: SimpleBean.class Java-Bean: True • jar cfm ..jarssimplebean.jar manifest.tmp simplebean*.class [SimpleBean and colorsbean demo]
  • 18. Introspection • Process of analyzing a bean to determine the capability • Allows application builder tool to present info about a component to software designer • Naming convention implicit method • BeanInfo class to explicitly infer info of a bean
  • 19. Design Pattern for Properties Property is a subset of a bean’s state which determines the appearance and behavior of the component • Simple property • Indexed Property • Bound Property • Constrained property
  • 20. Simple Property • Simple property has a single value. • N is the name of the property and T is its type • public T getN(); • public void setN(T arg) • For readonly property there is getN() method only
  • 21. Indexed Property • One property may consists of multiple values stored in an array • public T getN(int index); • public void setN(int index, T value); • public T[] getN(); • public void setN(T values[]); where N may be a double data[] and T is double
  • 22. Bound Property • It can generate an event when the property is changed • The event is of type PropertyChangeEvent and is sent to objects that previously registered an interest in receiving such notifications • bean with bound property - Event source • Bean implementing listener -- event target
  • 23. Implement Bound Property in a Bean 1. Import java.beans package 2. Instantiate a PropertyChangeSupport object private PropertyChangeSupport changes = new PropertyChangeSupport(this); 3. Implement methods to maintain the property change listener list: public void addPropertyChangeListener(PropertyChangeListener l) { changes.addPropertyChangeListener(l);} also removePropertyChangeListener method is needed
  • 24. Event Source Cont. 4. Modify a property’s setter method to fire a property change event when the property is changed. Public void setX(int newX){ int oldx = x; x = newX; changes.firePropertyChange(“x”, oldX, newX);}
  • 25. Implement Bound Property Listener 1. Listener bean must implement PropertyChangeListner interface public class MyClass implements PropertyChangeListener, Serializable 2. It must override this method: public abstract void propertyChange(PropertyChangeevent evt)
  • 26. Constrained Property • It generates an event when an attempt is made to change it value • The event type is PropertyChangeEvent • The event is sent to objects that previously registered an interest in receiving an such notification • Those other objects have the ability to veto the proposed change • This allows a bean to operate differently according to the runtime environment
  • 27. Three Parts in Implementation of Constrained Property 1. Source bean containing one or more constrained properties 2. Listener objects that implement the VetoableChangeListener interface. This object either accepts or rejects the proposed change. 3. PropertyChangeEvent object containing property name, old value, new value.
  • 28. Implement Constrained Property in a Bean Bean with constrained property must 1. Allow VetoableChangeListener object to register and unregister its interest in receiving notifications 2. Fire property change at those registered listeners. The event is fired before the actual property change takes place
  • 29. Implementation of Constrained Property in a Bean 1. Import java.beans package 2. Instantiate a VetoableChangeSupport object: private VetoableChangeSupport vetos=new VetoableChangeSupport(this); 3. Implement methods to maintain the property change listener list: public void addVetoableChangelistener(VetoableChangelistener l) { vetos.addVetoableChangeListener(l);}
  • 30. Cont. 4. Write a property’s setter method to fire a property change event: public void setX(int newX) { int oldX=X; vetos.fireVetoableChange(“X”, oldX, newX); //if no veto there X=newX; changes.firePropertyChange(“X”, oldX, newX); }
  • 31. Implementing Constrained Property Listeners 1. Implements the VetoableChangeListener interface which has an abstract method Void vetoChange(PropertyChangeEvent evt) 2. Overide this abstract method. This is the method that will be called by the source bean on each object in the listener list kept by vetoableChangeSupport object
  • 32. Persistence • It has the ability to save a bean to storage and retrieve it at a later time • Configuration settings are saved • It is implemented by Java serialization • If a bean inherits directly or indirectly from Component class it is automatically Serializable. • Transient keyword can be used to designate data members not be saved ex. Thread reference member
  • 33. Customizers • Property sheet may not be the best user interface for a complex component • It can provide step-by-step wizard guide to use component • It can provide a GUI frame with image which visually tells what is changed such as radio button, check box, ... • It can customize the appearance and behavior of the properties