Import javax. Swing .*;
Import java. AWT .*;
Import java. AWT. event .*;
Import java. Beans .*;
Import java. Io .*;
Import java. Lang. Reflect. method;
Public class mybeanintrospector
{
Public mybeanintrospector ()
{
Try
{
// Instantiate a bean
Student beanobj = new student ();
// Generate a beaninfo Class Based on bean
Beaninfo binfoobject =
Introspector. getbeaninfo (beanobj. getclass (), beanobj. getclass (). getsuperclass ());
// Define a string for display
String output = "";
// Start Introspection
/*
* Beaninfo. getmethoddescriptors ()
* This interface is used to obtain all member methods allowed to be exposed in the bean and return results in the form of a methoddescriptor array.
*
* Methoddescriptor class
* Used to record all information about a member Method
* Methoddescriptor. getname ()
* Obtain the method name of the method.
* Methoddescriptor. getmethod ()
* Method object for obtaining the Method)
*
* Method class
* Records all information about a specific method.
* Method. getparametertypes ()
* Obtain all the parameters used by this method and return them in the form of a class array.
*
* Class .. getname ()
* Obtain the name of this type.
*/
Output = "Introspection member method:/N ";
Methoddescriptor [] mdescarray = binfoobject. getmethoddescriptors ();
For (INT I = 0; I <mdescarray. length; I ++)
{
// Obtain the name of the method represented by the member method descriptor.
String methodname = mdescarray [I]. getname ();
String methodparams = new string ();
// Obtain the method object
Method methodobj = mdescarray [I]. getmethod ();
// Obtain all the parameters of the method through the method object and return them in the form of a class array.
Class [] parameters = methodobj. getparametertypes ();
If (parameters. length> 0)
{
// Obtain the parameter type name
Methodparams = parameters [0]. getname ();
For (Int J = 1; j <parameters. length; j ++)
{
Methodparams = methodparams + "," + parameters [J]. getname ();
}
}
Output + = methodname + "(" + methodparams + ")/n ";
}
System. Out. println (output );
/*
* Beaninfo. getpropertydescriptors ()
* This interface is used to obtain all the attributes of members allowed to be disclosed in the bean and return the attributes in the form of a propertydescriptor array.
*
* Propertydescriptor class
* Describes a member attribute.
*
* Propertydescriptor. getname ()
* Get the name of this attribute
*
* Propertydescriptor. getpropertytype ()
* Obtain the data type of this attribute, which is given in the form of class
*
*/
Output = "province member attributes:/N ";
Propertydescriptor [] mpropertyarray = binfoobject. getpropertydescriptors ();
For (INT I = 0; I <mpropertyarray. length; I ++)
{
String propertyname = mpropertyarray [I]. getname ();
Class propertytype = mpropertyarray [I]. getpropertytype ();
Output + = propertyname + "(" + propertytype. getname () + ")/n ";
}
System. Out. println (output );
/*
* Beaninfo. geteventsetdescriptors ()
* This interface is used to obtain all the publicly allowed member events in the bean and return the events in the form of an eventsetdescriptor array.
*
* Eventsetdescriptor class
* Used to describe a member event
*
* Eventsetdescriptor. getname ()
* Obtain the event name.
*
* Eventsetdescriptor. getlistenertype ()
* Obtain the event listener that the event depends on and give it as a class.
*
*/
Output = "Introspection binding event:/N ";
Eventsetdescriptor [] meventarray = binfoobject. geteventsetdescriptors ();
For (INT I = 0; I <meventarray. length; I ++)
{
String eventname = meventarray [I]. getname ();
Class listenertype = meventarray [I]. getlistenertype ();
Output + = eventname + "(" + listenertype. getname () + ")/n ";
}
System. Out. println (output );
System. Out. println ("write by esonghui :)");
}
Catch (exception E)
{
System. Out. println ("exception:" + E );
}
}
Public static void main (string [] ARGs)
{
New mybeanintrospector ();
}
}