Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

JavaBeansTM Short Course
Help: Inspecting Beans with BeanInfo and Juan Valdez

By MageLang Institute

[Tutorial Contents]
[Behavior] [API Docs] [Exercise] [Solution]

Help is available for each task, or you can go straight to the solution source code.

Task 1

The Introspector is used to get the BeanInfo of a Bean. Since it works with an instance of Class, you need to get the Class of the bean passed to our inspect method.
Use the Object.getClass method.

Task 2

Now that you have a Class, use the Introspector to get at its BeanInfo.
Use the Introspector.getBeanInfo method and remember to catch the IntrospectionException exception.

Task 3

From the BeanInfo, get the list of properties for the Bean. You will end up with an array of PropertyDescriptors.
Use the BeanInfo.getPropertyDescriptors method.

Task 4

For each element of the PropertyDescriptor array, display the name, datatype, and current value.
  • PropertyDescriptor is a subclass of FeatureDescriptor. Use the FeatureDescriptor.getName method to find out each name.
  • PropertyDescriptor has a getPropertyType method to get the Class for each property.
  • PropertyDescriptor also has a getReadMethod method to get the read Method for the property. Use the Method.invokeMethod routine to invoke it. Since the read methods take no parameters, you can pass it null for the Object[] it is expecting for parameters.
    • If the property is read-only, getReadMethod returns null.
    • The Method.invoke method can throw three exceptions, IllegalArgumentException, IllegalAccessException, or InvocationTargetException.

Task 5

From the BeanInfo, get the list of event sets for the Bean. You will end up with an array of EventSetDescriptors.
Use the BeanInfo.getEventSetDescriptors method.

Task 6

For each element of the EventSetDescriptor array, display the name and listener type.
  • EventSetDescriptor is a subclass of FeatureDescriptor. Use the FeatureDescriptor.getName method to find out each name.
  • EventSetDescriptor has a getListenerType method to get the Class whose interface will be invoked when the event is fired.

Task 7

Use the Burro frame provided in Burro.java to test out the inspect method of Valdez. Burro creates a Frame with a bunch of AWT Beans on it. When you double-click on a List element, select a Checkbox, or press return in the TextField, Juan goes to work and inspects the Bean selected. The results of the inspection are shown in the TextArea in the middle.
Compile and run:
javac Burro.java
java Burro
Copyright © 1997 MageLang Institute. All Rights Reserved.

[ This page was updated: 29-Sep-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.