Chapter 11 JavaBeans - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter 11 JavaBeans

Description:

Compete with other visual programming and component systems (which are often specific ... causes a Beans to react when a property in another Bean changes value. ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 36
Provided by: ericb175
Category:

less

Transcript and Presenter's Notes

Title: Chapter 11 JavaBeans


1
Chapter 11JavaBeans
2
Process Phases Discussed in This Chapter
Requirements Analysis
Design
Architecture
Framework
Detailed Design
Implementation
Key
secondary emphasis
main emphasis
x
x
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
3
Learning Goals for This Chapter
Understand
  • what JavaBeans (Beans) are
  • the life-cycle of a Bean
  • Bean containers
  • create JavaBeans
  • connect Beans in BeanBox
  • create applications that use Beans

Be able to
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
4
Java Beans Design Goals 1
  • Create a component technology within Java
  • capitalize on Java portability
  • Include GUI components
  • but not limited to GUI (e.g. server bean)
  • Compete with other visual programming and
    component systems
  • (which are often specific to an O.S.)
  • usually Windows
  • require installation of some kind

5
Beans Design Goals 2
  • Light weight for Internet applications
  • Secure
  • use Java security model
  • Easy efficient to distribute
  • Provide mechanism which enables development
    environment (container) to determine methods,
    properties events

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
6
Design Goal At Work ? Reusability ?
Facilitate the easy reuse of Java code.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
7
Output Of Chair Maker Estimator
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
8
Bean Phases
Phase 1. Create Bean Classes Source subject to
rules
Design / implementation time.
Phase 2. Create Bean from Multiple Bean
Classes Combine Bean classes to make new Beans
create manifest compile
Instance creation time.
Phase 3. Create Bean Instance Instantiate
object(s), usually in a Bean environment
(container)
--------
Phase 4a. Combine Beans in Bean Container to Make
Application Combine with other Beans to produce
application
Assembly time.
- or -
Deployment time.
Phase 4b. Deploy Bean and Use in
Applications Place application, Beans and
required software on target platform
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
9
Key Concept ? Ways to use Beans ?
-- within environments connected to other Beans
within applications.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
10
Amenities Afforded by Bean Environments
  • Detection of the Beans properties
  • Read only or-
  • Writeable
  • Detection of listeners supported
  • So events on the Bean can be handled
  • Ability to easily create instances
  • and display an image if an awt or swing object
  • Set property values visually
  • Ability to store instances

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
11
Required Bean Rules 1 of 2
  • Java source consists of Java classes
  • -containing null constructor
  • MyClass()
  • - implementing Serializable interface
  • - obeying standards shown below for
  • accessor methods
  • Listener registration
  • Event classes

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
12
Required Bean Rules2 of 2
  • To have property myProp, include methods
  • lttypegt getMyProp() // to access myProp
  • void setMyProp( lttypegt p ) // to change
  • For boolean property
  • boolean isMyProp()
  • Name for event classes to be XXXEvent
  • extends Event
  • Listeners must implement java.util.EventListener
  • Name must end in Listener as in XXXListener
  • added with public void addXXXListener(...)
  • removed with public void removeXXXListener(...
    )

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
13
JARing a Bean
jar cfm Bean0.jar manifest.txt Bean0.class
Creating a JAR file
First argument is name of the new JAR file
Second argument is name of manifest file
List all .class files to be included
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
14
BeanBox Environment
15
Adding a Bean to the BeanBox
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
16
Bean1
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
17
Setting Color
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
18
Design Goal At Work ? Reusability ?
Be able to use Chairmaker Bean alone. Avoid
having it refer to any other non-API class.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
19
Initial Form of Properties Panel
(green in color)
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
20
Design Goal At Work ? Reusability ?
Utilize Chairmaker with TicTock events. This
avoids compromising either Bean.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
21
Beginning to Use ChairMaker
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
22
Setting ChairMaker to Add a Chair Leg
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
23
An Output Of ChairMaker Bean
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
24
Output Of ChairMaker Bean From Button Action
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
25
Using a Bean in an Application Output
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
26
Design Goal At Work ? Reusability ?
We want to associate Beans even when there is no
external event such as a mouse click.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
27
Property Change Event Demonstration
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
28
Property Change Event Demonstration 2
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
29
Bound Property Demonstration
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
30
Key Concept ? Bound Properties ?
-- causes a Beans to react when a property in
another Bean changes value.
31
Embedding Beans in JSP
ltjspuseBean id"object name"
1 scope"pagerequestsessionapplication"
2 class"fully qualified classname" 3 lt/
jspuseBean gt 1 Bean instance name as in
MyClass myName . 2 // Choose one when
instance is destroyed optional default is
page 3 // e.g., a.b.MyClass
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
32
Scope of a Bean in a JSP
  • page - new object created and destroyed for
    every page view.
  • request - the newly created object created and
    bound to the request object.
  • session - the newly created object bound to the
    session object. -- every visitor coming to the
    site will have a separate session for it, so you
    will not have to create a new object every time
    for it -- can retrieve that object later again
    from the session object when wanted
  • application - object will stay as long as the
    application remains loaded. E.g., you want to
    count page views or daily sessions for your site.

Source http//stardeveloper.com8080/articles/072
001-1.shtml
33
Setting and Getting a Bean Property in a
JSPIntroduction
ltjspsetProperty nameaccount17"
propertybal" value3211 /gt ltjspgetProper
ty nameaccount17" propertybal" /gt
34
Summary of This Chapter
  • A Java Bean is a compiled collection of Java
    classes and required files
  • JARd to reduce to a single file
  • Beans are used at various phases, often in a Bean
    container
  • Creating from scratch
  • Creating instances of
  • Connecting
  • Deploying as part of an application

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
35
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
Write a Comment
User Comments (0)
About PowerShow.com