reflectionがクラスを対象にするのに対して、introspectionはBeansを対象にします。 そこで得られるのは、Beansの properties, events, methods に関する情報です。 JDK1.1では、あるBeanについての、これらの情報を一まとめにしたものを BeanInfoと呼んでいます。また、JDK1.1では、Beanからこれらの情報を引き出す、 Beanのintrospectionための特別のクラスが用意されています。これが、Introspector クラスです。
基本的な使い方は、Introspectorクラスのstaticなメソッド getBeanInfo()を使った、 次のようなものです。
BeanInfo info = Introspector.getBeanInfo( Class beanClass );
ここで、BeanInfoはクラスではなく、Interfaceであることに注意してください。 先の呼び出し一回で、Beanの基本的な情報は、すべて BeanInfo interfaceを備えた オブジェクト info (GenericBeanInfoクラスのインスタンス)に格納されます。 後は、このオブジェクト infoに対して、必要な情報を取りに行けばいいのです。
---< リスト 4 >---------------------------------------------------------------- public class Introspector { ....... private BeanInfo getBeanInfo() throws IntrospectionException { BeanDescriptor bd = getTargetBeanDescriptor(); EventSetDescriptor esds[] = getTargetEventInfo(); int defaultEvent = getTargetDefaultEventIndex(); PropertyDescriptor pds[] = getTargetPropertyInfo(); int defaultProperty = getTargetDefaultPropertyIndex(); MethodDescriptor mds[] = getTargetMethodInfo(); return new GenericBeanInfo(bd, esds, defaultEvent, pds, defaultProperty, mds, informant); } ....... ....... } class GenericBeanInfo extends SimpleBeanInfo { ....... public GenericBeanInfo(BeanDescriptor beanDescriptor, EventSetDescriptor[] events, int defaultEvent, PropertyDescriptor[] properties, int defaultProperty, MethodDescriptor[] methods, BeanInfo targetBeanInfo) { this.beanDescriptor = beanDescriptor; this.events = events; this.defaultEvent = defaultEvent; this.properties = properties; this.defaultProperty = defaultProperty; this.methods = methods; this.targetBeanInfo = targetBeanInfo; } ....... ....... } -------------------------------------------------------------------------------