Lesson 8 | Explicitly providing Bean information |
Objective | Find out How Beans can Explicitly Provide Information about Themselves. |
How JavaBeans can Explicitly Provide Information about Themselves
Although the automatic approach to introspection afforded by applying design patterns is useful and powerful, there may be situations where you want to explicitly provide informationabout a Bean for introspection purposes.
Explicitly providing Bean information
The following paragraph describes how to make JavaBeans as explicit as you want.
When explicitly providing Bean information using a Bean information class, you have the freedom of explicitly providing as much or as little information as you want. For example, it is possible to explicitly provide information about a Bean's properties, yet allow the automatic introspection facility to determine the Bean's supported methods and events.
If you do provide explicit information about a certain part of a Bean, such as its exposed properties, the automatic introspection facility isn't employed for that part of the Bean. In this way, you can explicitly hide properties that would otherwise be exported through the automatic introspection facility.
JavaBeans supports the explicit inclusion of Bean information through Bean information classes.
A Bean information class is a special class that can contain the following information about a Bean:
- Description of a Bean
- Icons for visually representing the Bean in design tools, toolbars, etc.
- Properties of a Bean
- Events broadcast by a Bean
- Methods supported by a Bean
- Properties are the appearance and behavior characteristics of a bean that can be changed at design time
- Beans expose properties so they can be customized at design time
- Builder tools introspect on a bean to discover its properties and expose those properties for manipulation
- Customization is supported in two ways:
1) by using property editors, 2) by using more sophisticated bean customizers
Bean information classes must implement the BeanInfo interface, which defines methods used to determine information about a Bean.
A bean's information class must be named the same as the Bean class, with the words BeanInfo appended to the end.
So, if you have a Bean named Widget, then the Bean information class must be named WidgetBeanInfo.
Security
The high-level Introspection APIs only provide information on "public" methods of target beans. The normal JDK security manager will allow even untrusted applets to access public fields and methods using the java.lang.reflect APIs. However, while access to private methods and fields may be available to "trusted" application builders, this access will normally be denied to untrusted applets.
Developing Java Beans