Java by API/java.beans/BeanInfo
BeanInfo: getEventSetDescriptors()
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class Main {
public static void main(String args[]) {
try {
Class c = Class.forName("Colors");
BeanInfo beanInfo = Introspector.getBeanInfo(c);
System.out.println("Properties:");
PropertyDescriptor propertyDescriptor[] = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptor.length; i++) {
System.out.println("\t" + propertyDescriptor[i].getName());
}
System.out.println("Events:");
EventSetDescriptor eventSetDescriptor[] = beanInfo.getEventSetDescriptors();
for (int i = 0; i < eventSetDescriptor.length; i++) {
System.out.println("\t" + eventSetDescriptor[i].getName());
}
} catch (Exception e) {
System.out.println("Exception caught. " + e);
}
}
}
BeanInfo: getPropertyDescriptors()
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class Main {
public static void main(String[] argv) throws Exception {
BeanInfo bi = Introspector.getBeanInfo(MyBean.class);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
String propName = pds[i].getDisplayName();
System.out.println(propName);
}
}
}
class MyBean {
public String getProp1() {
return null;
}
public void setProp1(String s) {
}
public int getProp2() {
return 0;
}
public void setProp2(int i) {
}
public byte[] getPROP3() {
return null;
}
public void setPROP3(byte[] bytes) {
}
}