HOME  |    TRAINING  |   FREE TUTORIALS   |   JOBS
Find out more about our new RSS feed.
FREE Tutorial
JAVABEANS

CATEGORY
SEARCH OUR OTHER TUTORIALS

DESCRIPTION

This tutorial is taken from our JavaBeans course and describes the properties and methods of introspection.
Click here to be kept informed of our new Tutorials.


TUTORIAL TAKEN FROM COURSE : INTRODUCTION TO JAVABEANS

FULL COURSE DETAILS

To go from the fundamentals of JavaBeans programming to the threshold of Advanced level. Gaining in depth programming and developer skills. A range of lab exercises reinforces the featured JavaBeans Technology aspects.

TO ACCESS THE FULL COURSE AND HUNDREDS OF OTHERS, CLICK HERE.


Introspection

Introspection is the ability to obtain information about the properties, events and methods of a Bean. Builder tools use this feature. It provides the data that is needed so developers who are using Beans can configure and connect components. It is also possible to explicitly designate which properties, events and methods are displayed to a user by a builder tool. This is very important and necessary for building productive quality Beans.

Classes and Interfaces

The Introspector class in the java.beans package provides static methods that allow the user to obtain information about the properties, events and methods of a Bean. One of the most commonly used methods of Introspector is getBeanInfo().

It has two forms shown below:

  • Static BeanInfo getBeanInfo(Class beanCls)

    This form of method returns an object that implements the BeanInfo interface. That object describes the properties, events and methods of beanCIs and all of its superclass.
  • Static BeanInfo getBeanInfo(Class beancls,Class ignoreCls)

    This form returns an object that implements the Beanlnfo interface. That object describes the properties, events and methods of beanCls and its superclasses up to but not including ignoreCls. There are additional details that determine where the introspection mechanisms look for this data.
BeanInfo

The BeanInfo interface in the java.beans package defines a set of constants and methods that are central to the process of introspection. The int constants defined by BeanInfo are ICON_COLOR_6*16, ICON_COLOR_32*32, ICON_MONO_16*16, and ICON_MONO_32*32. These values are used to identify icons of different sizes that you can provide for a component. The builder tool can use these icons to provide a visual representation of a Bean.

SimpleBeanInfo

The SimpleBeanInfo class in the java.beans package provides a default implementation of the Beanlnfo interface. To provide information about a Bean, a developer extends this class and overrides the implementations of some of its methods.

BeanDescriptor

The BeanDescriptor class in the java.beans package associates a customizer with a Bean. A customizer provides a graphical user interface through which a user may modify the properties of a Bean. Its most commonly used constructor is

BeanDescriptor (Class beanCls, Class customizerCls)

The two methods provided by this class are shown here:

  • Class getBeanClass() The getBeanClassQ method returns the Class object for a Bean
  • Class getCustomizerClass() The getCustomizerClass() method returns the Class object for a Bean customizer.
EventSetDescriptor

The EventSetDescriptor class in the java.beans package describes a set of events generated by a Bean. These are one or more events that are processed by an EventListener interface. The class supports the constructors shown below:

  • EventSetDescriptor(Class src,String esName,Class listener, String listenerMethName)
  • EventSetDescriptor(Class src,String esName,Class listener,String[] ListenerMethNames,String addListenerMethName, String removeListenerMethName)
  • EventSetDescriptor(String esName,Class listener, Method[] listenerMeths,Method addListenerMeth,Method removeListenerMeth)
  • EventSetDescriptor(String esName,Class listener, MethodDescriptor[] listener MethDescs, Method addListenerMeth, Method removeListenerMeth)

The arguments to these constructors have the following meaning:

src   is the class of the Bean that generates the event set.
esName   is the name of the event set.
listener   is the class of the listener interface,
listenerMethName   is the name of the, listener method.
listenerMethNames   is the names of the listener methods.
addListenerMethName   is the name of the method used to register a listener.
removeListenerMethName   is the name of the method used to unregister a listener.
listenerMeths   is an array of method objects describing the listener methods.
listenerMethDescs   is an array of MethodDescriptor objects describing the methods in the listener interface.
addListenerMeth   is a method object describing the method used to register a listener,
removeListenerMeth   is a method object describing the method listed to register a listener.

Each of these constructors can generate an IntrospectionException.

MethodDescriptor

The MethodDescriptor class in the java.beans package describes a method of a Bean. The class supports the constructors shown next,

MethodDescriptor (Method meth)

MethodDescriptor

Method Descriptor
Method getAddListenerMethod() Returns a Method object for the registration method.
MethodDescriptor[] getListenerMethodDescriptors() Returns an array of MethodDescriptor objects for the methods in the listener interface.
Method[] getListenerMethods() Returns an array of Method objects for the methods in the listener interface
Class getListenerType() Returns a Class object for the listener interface.
Method getRemoveListenerMethod() Returns a Method object for the unregistration method.
boolean isInDefaultEventSet() Returns true if the event set is in the "default set". Otherwise returns false.
boolean isUnicast() Returns true if the event set is unicast. Otherwise returns false.
Void set!nDefaultEventSet(boolean flag) If the flag is true, the event set is part of the default set. Otherwise it is not.
void setUnicast(boolean flag) If the flag is true, the event set is unicast. Otherwise it is multicast.

MethodDescriptor (Method meth, ParameterDescriptor[] pds)

Here, meth is a method object for this method, and pds is an array of parameterDescriptor objects that describe the parameters to this method.

Method getMethod() ParameterDescriptor[] getParameterDescriptors() The getMethod() method returns a method object for the associated method

getParameterDescriptors() returns an array of ParameterDescriptor objects for the parameters of this method.

ParameterDescriptor

The ParameterDescriptor class in the java.beans package describes the parameters of a method. The class does not provide any additional fields or methods beyond those of its FeatureDescriptor superclass.

PropertyDescriptor

The PropertyDescriptor class in a java.beans package describes a property of a Bean. It supports the constructors as shown below,

Property Descriptor (String pname, Class cls)

Property Descriptor (String pname, Class cls, String getMethName, String setMethName)

Property Descriptor (String pname. Method getMeth, Method setMeth)

Here, pname is the name of the property, and els is the class of the Bean. The names of the access methods for this property are getMethName and setMethName. The argument getMeth, setMeth are method objects for these access methods.

These constructors can throw an IntrospectionException.

Method Descriptor
Class getPropertyEditorClass() Returns a class object for the associated property editor. If a property editor has not been defined for this property, null is returned. In this case, the PropertyEditorManager is used to obtain a property editor.
Class getPropertyType() Returns a class object for the property.
Method getReadMethod() Returns a method object for the reader.
Method getWriteMethod() Returns a method object for the writer.
Void setPropertyEditorClass(Class pEdCls) Set the property editor for this property to pEdCls

IndexedPropertyDescriptor

The IndexedPropertyDescriptor class in the java.beans package describes an indexed property of a Bean. It extends the PropertyDescriptor class and supports the constructors as shown below

1. IndexedPropertyDescriptor (String pname, Class cls)

2. IndexedPropertyDescriptor (String pname,Class cls, String getMethName,String setMethName,String GetIndexedMethName,String setIndexedMethName)

3. IndexedPropertyDescriptor(String pname,Method getMeth, Method getMeth,Method setMeth,Method getIndexedMeth, Method setIndexedMeth)

Here, pname is the name of the property, and cls is the class of the Bean. Access methods for this property are getMethName, setMethName, getIndexedMethName, and setIndexedMethName. The arguments are getMeth, setMeth, getIndexedMeth and setIndexecMeth are method objects for these access methods. These constructors can throw an IntrospectionException.

Some of the methods provided by IndexedPropertyDescriptor are shown here:

Class getIndexedProperty()

Method getIndexedReadMethod()

Method getIndexedWriteMethod()

The getIndexedPropertyType() method returns a class object for the indexed property.

The getIndexedReadMethod() and getIndexedWriteMethod() methods return the Method object for the indexed read and write methods respectively.




7 RELATED COURSES AVAILABLE
INTRODUCTION TO JAVA PROGRAMMING
The aims of this Java training courses is to understand the role that Java plays on the Internet; describe the be....
JAVA (V1.2): ADVANCED PROGRAMMING
This course teaches the reader to learn, understand and become familiar with the advanced features of Java progra....
INTRODUCTION TO JAVABEANS
To go from the fundamentals of JavaBeans programming to the threshold of Advanced level. Gaining in depth progr....
C++ PROGRAMMING
Object oriented programming is fast becoming the leading software design methodology, with C++ becoming ever more....
C PROGRAMMING
This course is design to provide non-C programmers with the essential skills and knowledge necessary to allow the....
 
1 RELATED JOBS AVAILABLE
JAVA DEVELOPER MANCHESTER
Computer Futures Solutions are seeking a Senior Java Developer for their Manchester based client. You will be joi....
CONTACT US
Thursday 24th July 2008  © COPYRIGHT 2008 - VISUALSOFT