JavaBeans Jar Utility - Exercise Result
Using the JAR utility to look inside JAR files
You Said:
Results: The content listing for the buttons.jar file are as follows:
C:\BDK\jars>jar ft buttons.jar
META-INF/MANIFEST.MF
sunw/demo/buttons/BlueButtonWriter.class
sunw/demo/buttons/ExplicitButton.class
sunw/demo/buttons/ExplicitButtonBeanInfo.class
sunw/demo/buttons/ExternalizableButton.class
sunw/demo/buttons/OrangeButtonWriter.class
sunw/demo/buttons/OurButton.class
sunw/demo/buttons/OurButtonCustomizer.class
sunw/demo/buttons/ExplicitButtonIcon16.gif
sunw/demo/buttons/ExplicitButtonIcon32.gif
sunw/demo/buttons/BlueButton.ser
sunw/demo/buttons/OrangeButton.ser
Notice how the classes and resources in the buttons.jar JAR file are organized in a directory structure within the JAR file.
This directory structure exactly matches the package structure of the classes, which is an organizational requirement of JAR files.
Using the BeanInfo Interface
As the preceding discussion shows, design patterns implicitly determine what information is available to the user of a Bean. The BeanInfo interface enables you to explicitly control what information is available. The BeanInfo interface defines several methods, including these:
PropertyDescriptor[ ] getPropertyDescriptors( )
EventSetDescriptor[ ] getEventSetDescriptors( )
MethodDescriptor[ ] getMethodDescriptors( )
The getter methods listed above return arrays of objects that provide information about the properties, events, and methods of a Bean.
The classes
- PropertyDescriptor,
- EventSetDescriptor, and
- MethodDescriptor
are defined within the java.beans package, and they describe the indicated elements.
By implementing these methods, a developer can designate exactly what is presented to a user, bypassing introspection based on design patterns. When creating a class that implements BeanInfo, you must call that class bnameBeanInfo, where bname is the name of the Bean.
For example, if the Bean is called MyBean, then the information class must be called MyBeanBeanInfo.
To simplify the use of
BeanInfo
, JavaBeans supplies the SimpleBeanInfo class. It provides default implementations of the BeanInfo interface, including the three methods just shown. You can extend this class and override one or more of the methods to explicitly control what aspects of a Bean are exposed. If you do not override a method, then design-pattern introspection will be used.
For example, if you do not override
getPropertyDescriptors( )
, then design patterns are used to discover a Bean's properties.
You will see SimpleBeanInfo in action later in this module.