Ar re e w we e c cr re ea at ti in ng g A TM M o s T Ja av va aB Be ea an ns or r J Ja av va a c cl la as ss se es s? ?? ? J Le et t’ ’s s d de ef fi in ne e t th he e d di if ff fe er re en nc ce e! !! ! L Mani Jorda Garcia 28.3.2000 Page 1
WH HA AT T I IS S A A J JA AV VA AB BE EA AN N? ? W 1. . 1 � Reusable software components that can be visually manipulated in builder tools to create applications. � They can be simple components, like a button, or can be more complex software components like a calendar: Fig 1. J avaBeans examples Mani Jorda Garcia 28.3.2000 Page 2
WH HA AT T I IS S T TH HE E D DI IF FF FE ER RE EN NC CE E W 2. . 2 BE ET TW WE EE EN N B BE EA AN NS S A AN ND D C CL LA AS SS S B LI IB BR RA AR RI IE ES S? ? L The difference is INTROSPECTION . � - Introspection is what builder tools use to “look inside” a Bean and determine its properties and behavior . - Beans publish their attributes and methods through special method signature patterns that are recognized by beans- aware application construction tools. - BASICALLY, JAVABEANS ARE WHAT BUILDER TOOLS USE TO CREATE APPLICATIONS. Mani Jorda Garcia 28.3.2000 Page 3
WH HY Y D DO OE ES S T TH HE E T TO OO OL L N NE EE ED D W 3. . 3 “T TO O L LO OO OK K I IN NS SI ID DE E” ” T TH HE E B BE EA AN N? ? “ � To know which are the methods and the properties defined in the Bean and to create the respective editors to manage those methods and properties. Mani Jorda Garcia 28.3.2000 Page 4
CO OU UL LD D I I A AD DD D M MY Y J JA AV VA AC CL LA AS SS S C 4. . 4 TO O T TH HE E C CO OM MP PO ON NE EN NT T P PA AL LE ET TT TE E O OF F T TH HE E T TO OO OL L? ? T � It is true that a Javabean is defined following standard design patterns that the tool can recognize. � But it is also true that you CAN CREATE your Java classes, and ADD them to the tool, even if they are not designed following the design patterns. To do so, we need to create a complementary Java class extended from BeanInfo class, defining the methods and properties we have used in our class, and add it to the tool. Mani Jorda Garcia 28.3.2000 Page 5
CO ON NS SE EQ QU UE EN NC CE ES S C 5. . 5 � Two consequences are derived from the above definitions: 1. If we use a Builder tool, it is better to think of creating Beans rather than Java classes, to take advantage of the possibilities that tools provide: - Property editors automatically created. - Easy management of events and listeners. 2. If we don’t know if we are using a tool, we can define our elements as Java classes, in which case: - Properties are read from an external file. Later on, we could add them to the tool palette and specify the corresponding BeanInfo class. Mani Jorda Garcia 28.3.2000 Page 6
S T TM M A JA AV VA AB BE EA AN NS AD DD DI IT TI IO ON NA AL L J 6. . 6 IN NF FO OR RM MA AT TI IO ON N I 6. .1 1 6 JA AV VA AB BE EA AN NS S F FE EA AT TU UR RE ES S J 1. They can be instantiated . A Javaclass can be instantiated if it is neither an interface nor an abstract class. A class is an interface when it is defined like that, and it is abstract when contains any abstract method or variable. Mani Jorda Garcia 28.3.2000 Page 7
2. They contain a constructor method, even if it is an empty method. 3. They are persistent (must implement either a serializable or externalizable interfaz). 4. They follow a standard design pattern defined by five rules. 5. They use the event delegation model . Mani Jorda Garcia 28.3.2000 Page 8
6.2 B BE EA AN NS S A AR RC CH HI IT TE EC CT TU UR RE E Beans are composed of three elements: 1. Properties 2. Methods 3. Events � Properties define the attributes of the Bean. � Methods are used to set the Beans properties and to define and receive events. � Events are the vehicle between Beans, as well as between Beans and containers. Mani Jorda Garcia 28.3.2000 Page 9
6. .3 3 6 PR RO OP PE ER RT TI IE ES S P Property types � Simple (numbers, characters and strings) � Boolean � Array � Indexed � Bound � Constrained Mani Jorda Garcia 28.3.2000 Page 10
6. .3 3. .1 1 6 BO OU UN ND D A AN ND D B CO ON NS ST TR RA AI IN NE ED D P PR RO OP PE ER RT TI IE ES S C � A Bound property is a property that notifies any listeners of changes in the property’s value. The listener notifies other components of changes. The listening component then has the opportunity to respond to the change in the property’s value. � A Constrained property is a property in which a change to the property value can be vetoed by another component that is listening for changes in the property’s value. Mani Jorda Garcia 28.3.2000 Page 11
6. .3 3. .2 2 6 P PR RO OP PE ER RT TY Y E ED DI IT TO OR RS S A property editor is an editor for changing property values at design time. They vary from one IDE to another, but typically appear as a top-level dialog box. They can edit a single property at a time or the entire component at once (which is called component customizes). Component customizers present a dialog box or panel that lets the user set many properties at once. Mani Jorda Garcia 28.3.2000 Page 12
ME ET TH HO OD DS S M 4 6. .4 6 They are mainly used: - to read/write beans properties: - get ( ), set ( ), is( ) methods - to handle bean events: - Notifying the actionlistener that an event has ocurred - Implementing the action associated to that event. Notifying other beans. - - Mani Jorda Garcia 28.3.2000 Page 13
Recommend
More recommend