16-01-2013, 12:08 PM
JavaBeans
JavaBean.ppt (Size: 160.5 KB / Downloads: 337)
What Is JavaBeans?
(One of) Sun Microsystems’s entry in the component sweepstakes
Currently realized in Beans Development Kit (BDK) 1.1 spec (1999)
Component model for Java
Platform-independent
Language-dependent
Implemented as language extensions
Additional classes and interfaces in the Java Class Library
Basically a design pattern
Based on standard naming conventions
The naming conventions allow beanboxes and other beans to dynamically discover a bean’s capabilities
But naming conventions have well-known problems
Three Levels of Use
Building applications from beans written by bean developers
Developing individual beans
Developing “beanboxes” and other tools for graphically manipulating beans
A more neutral term for such tools is “sandboxes”
What Is a Bean?
A bean is a Java object
Exports properties, events and methods
Interface conforms to certain naming rules
Conforms to certain packaging rules
Usually (but not always) has a visual form for manipulation in beanboxes
Supported by package java.beans
Any Java class can be a bean
No predefined Bean class
Many AWT components are beans
Elements of JavaBeans (I)
Events signal a bean’s response to changes in its properties and other phenomena
Properties represent attributes of a bean
BeanInfo customizes the information about a bean that is made available within a beanbox
Review:Implicit Invocation
Advantages
Allows for decoupling and autonomy of components
Java events require tight coupling
Enhances reuse and evolution
Easy to introduce new components without affecting existing ones
Disadvantages
Components announcing events have no guarantee of getting a response
Components announcing events have no control over the order of responses
Event abstraction does not cleanly lend itself to data exchange
Difficult to reason about the behavior of an announcing component independently of the components that register for its events
Predefined Events in Java
ActionEvent: high-level user event
AdjustmentEvent: event from an Adjustable object (such as a scrollbar)
ComponentEvent: event from a GUI Component object
Container, Focus, Input (Key or Mouse), Paint, Window
ItemEvent: event from an ItemSelectable object
TextEvent: event from the editing of a TextComponent
Many of these have associated Adapters and/or Listeners