Chapter 11JavaBeansProcess Phases Discussed in This ChapterLearning Goals for This ChapterJava Beans Design Goals 1Beans Design Goals 2Design Goal At Work: ? Reusability ?Output Of Chair Maker EstimatorBean PhasesKey Concept: ? Ways to use Beans ?Amenities Afforded by Bean EnvironmentsRequired Bean Rules 1 of 2Required Bean Rules 2 of 2JAR’ing a BeanBeanBox EnvironmentAdding a Bean to the BeanBoxBean1Setting ColorDesign Goal At Work: ? Reusability ?Initial Form of Properties PanelDesign Goal At Work: ? Reusability ?Beginning to Use ChairMakerSetting ChairMaker to Add a Chair LegAn Output Of ChairMaker BeanOutput Of ChairMaker Bean From Button ActionUsing a Bean in an Application: OutputDesign Goal At Work: ? Reusability ?Property Change Event DemonstrationProperty Change Event Demonstration #2Bound Property DemonstrationKey Concept: ? Bound Properties ?Embedding Beans in JSPScope of a Bean in a JSPSetting and Getting a Bean Property in a JSP:IntroductionSummary of This ChapterCOMP 7700 – JavaBeans 1Chapter 11JavaBeansCOMP 7700 – JavaBeans 2Process Phases Discussed in This ChapterRequirementsAnalysisDesignDetailed DesignFramework ArchitectureImplementationxKey: = secondary emphasisx = main emphasisAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 3Learning Goals for This Chapter … what JavaBeans (“Beans”) are … the life-cycle of a Bean … Bean containers … create JavaBeans … connect Beans in BeanBox … create applications that use BeansBe able to …Understand …Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 4Java 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 kindCOMP 7700 – JavaBeans 5Beans 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 & eventsAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 6Design 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.COMP 7700 – JavaBeans 7Output Of Chair Maker EstimatorAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 8Bean PhasesPhase 1. Create Bean ClassesSource subject to rulesDesign / implementation time.Phase 2. Create Bean from Multiple Bean ClassesCombine Bean classes to make new Beans; create manifest; compilePhase 3. Create Bean InstanceInstantiate object(s), usually in a Bean environment (container)Instance creation time.--------Phase 4a. Combine Beans in Bean Container to Make ApplicationCombine with other Beans to produce applicationAssembly time.-or -Phase 4b. Deploy Bean and Use in ApplicationsPlace application, Beans and required software on target platformDeployment time.COMP 7700 – JavaBeans 9Key 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.COMP 7700 – JavaBeans 10Amenities Afforded by Bean Environments Detection of the Bean’s propertiesRead only – or-Writeable Detection of listeners supportedSo events on the Bean can be handled Ability to easily create instancesand display an image if an awt or swing objectSet property values visually Ability to store instancesAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 11Required Bean Rules 1 of 2 Java source consists of Java classes -containing null constructor … MyClass() { … } - implementing Serializable interface - obeying standards shown below for …o … accessor methods o … Listener registration o … Event classes Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 12Required Bean Rules 2 of 2 To have property myProp, include methods:<type> getMyProp(){ … } // to access myPropvoid setMyProp( <type> 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.COMP 7700 – JavaBeans 13JAR’ing a Beanjar 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 fileList all .class files to be includedAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 14BeanBox EnvironmentCOMP 7700 – JavaBeans 15Adding a Bean to the BeanBoxCOMP 7700 – JavaBeans 16Bean1Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 17Setting ColorAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 18Design 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.COMP 7700 – JavaBeans 19Initial Form of Properties Panel(green in color)Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.COMP 7700 – JavaBeans 20Design Goal At Work: ÆReusability ÅUtilize Chairmaker with TicTock events. This avoids
View Full Document