Java Beans - CSCE | College of Engineering | University of

Download Report

Transcript Java Beans - CSCE | College of Engineering | University of

Java Beans
• Component Technology
• Integrated, Visual Development
Environments
• Reusable
• Platform-Independent
• Modular
Java Bean Concepts
• Visual Composition or Programming
• Components expose their features (public
methods and events) to builder tools
• Features adhere to specific design patterns
• Forte or NetBeans for IDE
Component Model
• Building Block Approach to Software
Development
• Components are self-contained elements of
software
• Dynamic Control
• Assembled to form Applications
• Interact according to rules and guidelines
Component Characteristics
•
•
•
•
•
Containment
Discovery and Registration
Events
Persistance
Visual Presentation
Containment
• Implicit in Model is concept of container in
which components interact
• Containers can be components
Discovery and Registration
• Java has built in mechanisms for class and
interface discovery
• Used to locate a component at runtime
• Used to determine supported interface for
use by other components
• Reflection API
Advantages
• Late binding allows components and
applications to be developed independently
• Interface define contract between
component and application
• Application does not include component in
order to use it at runtime.
• Just has to know what it is capable of doing
Feature Discovery
• Discovery of Features (properties, methods,
events) through INTROSPECTION
• Design Patterns when naming features.
Reflection API (Introspector class)
• Feature information in a Bean Information
class
Java Runtime
•
•
•
•
•
•
JRE - Java Runtime Environment
Runtime portion of development kit
Contains core API
Maintains Class object for each class
Represents or Reflects class
Reflection API invokes methods on Class
object
Reflection API
• Classes, Interfaces, and Objects in current
JVM
• Discovery at runtime
• Determine Class of an Object
• Get Information about Class (modifiers,
fields, methods, constructors, superclass)
• Constants and method declarations in
interface
• Create an instance of a class whose name is
not known at runtime
• Get and set value of objects field, even if
unknown at runtime
• Invoke method on an object, even if
unknown at runtime
• Create new array, whose size and
components are not known at runtime
Events
• Event occurs at specific point in time
• Events generated by actors (User, other
systems, components)
• Components notify other Components when
events take place
• Communication mechanism with welldefined interface
Events
• Events used to communicate with other
Beans
• A bean that wants to receive notification of
an event (a listener Bean) registers its
interest with Bean that fires the event (a
source Bean).
Persistence
• Beans are able to save and store state, then,
restore it
• Object Serialization is key technology
Persistence
• State of the Component
• Persistence: Store and Restore State
• Components participate in containers
persistence mechanism
• Uniform Persistance Mechanism
Visual Presentation
•
•
•
•
Component itself may or may not be visual
Related to container object
Support Visual Programming
Proceed by altering properties, managing
events
Properties
• Properties are Bean’s behavior and
appearance attributes that can be changed at
design time.
• Properties exposed for customization
• Customization by Property Editors or more
custom classes
Bean Development Kit
•
•
•
•
BDK separate for JDK
BEANBOX
Documentation
Examples
Introduction to BeanBox
•
•
•
•
See tutorial
Located in bdk\beanbox directory
Shell scripts to start run.bat or run.sh
Or use make facility (Unix gmake,
Windows nmake)
BeanBox
•
•
•
•
Three Windows
Toolbox: available beans
Beanbox: wire beans
Properites Sheet: Properties of currently
selected beans