【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-AuditBeanInfo.java,希望本篇文章对您学习有所帮助。
package ejava.beansch7;
import java.beans.SimpleBeanInfo;
import java.beans.PropertyDescriptor;
import java.beans.MethodDescriptor;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.IntrospectionException;
import java.beans.BeanDescriptor;
/**
* This class implements the Bean info for our bean. SimpleBean is the
* basic implementation of the BeanInfo Interface
*/
public class AuditBeanInfo extends SimpleBeanInfo
{
public BeanDescriptor getBeanDescriptor()
{
BeanDescriptor beanDescriptor =
new BeanDescriptor(ejava.beansch7.AuditBean.class);
beanDescriptor.setDisplayName("AuditBean");
return beanDescriptor;
}
/**
* Get Property Description information
*/
public PropertyDescriptor[] getPropertyDescriptors ()
{
try {
// Create a descriptor for file property
PropertyDescriptor fileP =
new PropertyDescriptor("file", AuditBean.class,
"getFile", "setFile");
// Create a descriptor for FileName property
PropertyDescriptor fileNameP =
new PropertyDescriptor("fileName", AuditBean.class,
"getFileName", "setFileName");
fileNameP.setDisplayName("File Name");
fileNameP.setBound(true);
PropertyDescriptor[] descriptors =
new PropertyDescriptor[] { fileP, fileNameP };
return descriptors;
} catch (Exception ex) {
return null;
}
}
/**
* Get the medthods and its, descipritons
*/
public MethodDescriptor[] getMethodDescriptors ()
{
try {
MethodDescriptor[] descriptors = {
new MethodDescriptor (
AuditBean.class.getMethod ("auditMessage", new Class[0]))};
return descriptors;
} catch (Exception ex) {
return null;
}
}
/**
* Get the Event Descriptors for the beans
*/
public EventSetDescriptor[] getEventSetDescriptors ()
{
try {
EventSetDescriptor[] events = {
new EventSetDescriptor (AuditBean.class,
"audit", AuditListener.class,
"notifyAuditEvent")};
return events;
} catch (IntrospectionException ex) {
return null;
}
}
/**
* Additional Bean info is the super class information of the bean.
*
*/
public BeanInfo[] getAdditionalBeanInfo() {
Class superclass = AuditBean.class.getSuperclass();
try {
BeanInfo superBeanInfo =
Introspector.getBeanInfo(superclass);
return new BeanInfo[] { superBeanInfo };
} catch(IntrospectionException ex) {
ex.printStackTrace();
return null;
}
}
}