Chapter 11 Java Beans Requirements Analysis Process Phases

Chapter 11 Java. Beans

Requirements Analysis Process Phases Discussed in This Chapter Design Framework. Architecture Detailed Design Key: x = main emphasis x = secondary emphasis Implementation Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Learning Goals for This Chapter Understand … q … what Java. Beans (“Beans”) are q… the life-cycle of a Bean q …… Bean containers Be able to q… create Java. Beans q… connect Beans in Bean. Box q… create applications that use Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Java Beans Design Goals 1 o Create a component technology within Java o capitalize on Java portability o Include GUI components o but not limited to GUI (e. g. server bean) o Compete with other visual programming and component systems o (which are often specific to an O. S. ) o usually Windows o require installation of some kind

Beans Design Goals 2 o o “Light weight” for Internet applications Secure o use Java security model o Easy & efficient to distribute o 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.

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.

Output Of Chair Maker Estimator Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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 Phase 3. Create Bean Instance creation time. Instantiate object(s), usually in a Bean environment (container) ---- Phase 4 a. Combine Beans in Bean Container to Make Application Assembly time. Combine with other Beans to produce application - or Deployment time. Phase 4 b. Deploy Bean and Use in Applications Place application, Beans and required software on target Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. platform

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.

Amenities Afforded by Bean Environments q Detection of the Bean’s properties Read only – or. Writeable q Detection of listeners supported So events on the Bean can be handled q Ability to easily create instances and display an image if an awt or swing object Set property values visually q Ability to store instances Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Required Bean Rules 1 of 2 q Java source consists of Java classes q -containing null constructor … My. Class() { … } q - implementing Serializable interface q - obeying standards shown below for … o … accessor methods o … Listener registration Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

q To have property my. Prop, include methods: <type> get. My. Prop(){ … } my. Prop // to access Required void set. My. Prop( <type> p ) // to change Bean q For boolean property: Rules boolean is. My. Prop() 2 of 2 q Name for event classes to be XXXEvent o extends Event q Listeners must implement java. util. Event. Listener o Name must end in Listener as in XXXListener o added with public void add. XXXListener(. . . ) Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

JAR’ing a Bean jar cfm Bean 0. jar manifest. txt Bean 0. 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.

Bean. Box Environment

Adding a Bean to the Bean. Box Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Bean 1 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Setting Color Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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.

Initial Form of Properties Panel (green in color) Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Design Goal At Work: Reusability Utilize Chairmaker with Tic. Tock events. This avoids compromising either Bean. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Beginning to Use Chair. Maker Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Setting Chair. Maker to Add a Chair Leg Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

An Output Of Chair. Maker Bean Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Output Of Chair. Maker Bean From Button Action Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Using a Bean in an Application: Outpu Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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.

Property Change Event Demonstration Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Property Change Event Demonstration #2 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Bound Property Demonstration Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept: Bound Properties -- causes a Beans to react when a property in another Bean changes value.

Embedding Beans in JSP <jsp: use. Bean id="object name" 1 scope="page|request|session|applic ation" 2 class="fully qualified classname" 3 </ jsp: use. Bean > 1 Bean instance name as in My. Class my. Name = …. 2 // Choose one; when instance is destroyed; optional; default is page 3 // e. g. , a. b. My. Class Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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 Source: http: //stardeveloper. com: 8080/articles/072001 -1. shtml

<jsp: set. Property name=“account 17" property=“bal" value=“ 3211“ /> <jsp: get. Property name=“account 17" property=“bal" /> Setting and Getting a Bean Property in a JSP: Introduction

Summary of This Chapter 1. A Java Bean is a compiled collection of Java classes and required files 1. JAR’d to reduce to a single file 2. Beans are used at various phases, often in a Bean container 1. Creating from scratch 2. Creating instances of Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
- Slides: 35