BeanContextServiceProvider
BeanContextServiceProvider (서비스 제공자)
BeanContext의 주요 기능 중 하나는 JavaBeans와 BeanContextServiceProvider 사이의 중개자 역할을 하는 것이에요. BeanContext 안에 중첩된 JavaBean은 특정 서비스 클래스를 나타내는 Class 객체를 기준으로 해당 서비스의 인스턴스를 요청할 수 있어요.
본문
BeanContextServiceProvider는 BeanContext에 일반적인 "서비스"를 제공하는 인터페이스예요. BeanContextChild 객체가 서비스를 요청하면, BeanContext는 등록된 서비스 제공자에게 해당 서비스의 인스턴스를 제공하도록 요청해요.
서비스 요청이 발생하면 서비스 클래스를 등록한 BeanContextServiceProvider에게 서비스 인스턴스를 요청해요. 컨텍스트가 요청을 처리하지 못해 상위 컨텍스트에 위임하는 경우에는 상위 컨텍스트에 등록된 서비스 제공자에게 요청할 수도 있어요.
서비스 제공자는 항상 동일한 인스턴스를 반환할 수도 있고, 요청마다 새로운 인스턴스를 생성할 수도 있어요. 구현 방식에 따라 달라져요.
주요 메서드는 다음과 같아요.
Object getService(BeanContextServices bcs, Object requestor, Class<?> serviceClass, Object serviceSelector)
void releaseService(BeanContextServices bcs, Object requestor, Object service)
Iterator<?> getCurrentServiceSelectors(BeanContextServices bcs, Class<?> serviceClass)
getService()— 요청자(requestor)를 위해 서비스 클래스의 인스턴스를 제공해요.releaseService()— 더 이상 필요하지 않은 서비스 인스턴스를 해제해요.getCurrentServiceSelectors()— 현재 사용 가능한 서비스 선택자 목록을 반환해요.
대표적인 구현으로는 BeanContextServicesSupport.BCSSProxyServiceProvider가 있어요.