BeanContext and BeanContextServices
So far we’ve
talked about some sophisticated
mechanisms for connecting Java Beans together at design time and
runtime. However, we haven’t talked at all about the environment in which
JavaBeans live. To build advanced, extensible applications we need a
way for Java Beans to find each other or “rendezvous” at
run time. The
java.beans.beancontext
package provides this kind of container
environment It also provides a generic “services” lookup
mechanism for Beans that wish to advertise their capabilities.
Beans that implement the BeanContextChild
interface (or a subinterface) are passed a reference to the
container’s BeanContext, which is the source
for all container-related information. The
BeanContext implements many useful interfaces that
describe the Bean environment. (To use it, cast it to the appropriate
interface.) The two interfaces that we will talk about here are
Collection
and
BeanContextServices.
A bean
collection
is an object that implements the
java.util.Collection interface. It can be used to
enumerate the Bean instances in the container. A corresponding
listener interface lets Beans find out when Beans are added or
removed. The BeanContextServices interface
provides a means for looking up Beans that provide services, either
by the Bean’s class type or through a list of the currently
available service Beans. There is a corresponding listener interface
for being informed of new services and revoked services.
Doing much with these classes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access