Introspector
Introspector (빈 인트로스펙터)
도구가 대상 Java Bean이 지원하는 속성, 이벤트, 메서드를 배우는 표준 방법을 제공하는 클래스예요. 이 세 종류의 정보 각각에 대해 Introspector는 빈의 클래스와 슈퍼클래스를 별도로 분석해 명시적 또는 암시적 정보를 찾고, 이를 바탕으로 대상 빈을 포괄적으로 기술하는 BeanInfo 객체를 만듭니까.
본문
각 클래스 "Foo"에 대해, 대응하는 "FooBeanInfo" 클래스가 존재해 정보를 물었을 때 null이 아닌 값을 반환하면 명시적 정보가 있다고 간주해요. 먼저 대상 빈 클래스의 패키지 한정 전체 이름에 "BeanInfo"를 붙여 BeanInfo 클래스를 찾아요. 실패하면 이름의 마지막 클래스명 컴포넌트를 사용해 BeanInfo 패키지 검색 경로의 각 패키지에서 그 클래스를 찾아요. 예를 들어 sun.xyz.OurButton 클래스라면 sun.xyz.OurButtonBeanInfo를 먼저 찾고, 실패하면 검색 경로에서 OurButtonBeanInfo를 찾아요.
클래스가 자신에 대한 명시적 BeanInfo를 제공하면, 파생 클래스 분석에서 얻은 정보에 그 내용을 더하되 명시적 정보를 해당 클래스와 기본 클래스에 대해 결정적인 것으로 간주하고 슈퍼클래스 체인을 더 올라가지 않아요.
명시적 BeanInfo를 찾지 못하면, 저수준 리플렉션으로 클래스의 메서드를 연구해 표준 디자인 패턴을 적용해 속성 접근자, 이벤트 소스, 공개 메서드를 식별해요. 그런 다음 클래스의 슈퍼클래스를 분석해 그 정보를 추가해요.
주요 메서드는 다음과 같아요.
public static final int USE_ALL_BEANINFO
public static final int IGNORE_IMMEDIATE_BEANINFO
public static final int IGNORE_ALL_BEANINFO
public static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException
public static BeanInfo getBeanInfo(Class<?> beanClass, int flags) throws IntrospectionException
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass) throws IntrospectionException
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass, int flags) throws IntrospectionException
public static String decapitalize(String name)
getBeanInfo()— 대상 빈 클래스의BeanInfo를 반환해요. 플래그로 베이스 클래스 분석 방식을 제어하고,stopClass로 슈퍼클래스 분석 중단 지점을 지정할 수 있어요.decapitalize()— JavaBeans 명세에 따라 이름을 소문자로 시작하도록 바꿔요(예:FooBar→fooBar).