When Nucleus creates your component from a properties file, it first calls your class constructor with no arguments. It then binds the component into the namespace of the NameContext
that contains the component. For example, if your component was created with the name /services/servers/LatteServer
, the component is bound into the NameContext
at /services/servers
, using the name LatteServer
.
If your class implements the atg.naming.NameContextBindingListener
interface, the component is notified when it is bound into a NameContext
, and also receives notification when it is unbound from that NameContext
.
A typical implementation of NameContextBindingListener
looks like this:
import atg.naming.*; public YourClass implements NameContextBindingListener { String name; NameContext nameContext; public void nameContextElementBound (NameContextBindingEvent ev) { if (ev.getElement () == this) { nameContext = ev.getNameContext (); name = ev.getName (); } } public void nameContextElementUnbound (NameContextBindingEvent ev) { if (ev.getElement () == this) { nameContext = null; name = null; } } }
Both methods check to verify that the element
in the event really is the object. This is because the same methods are called if the object is registered as a listener for binding events on other NameContexts
. For the time being, just remember to include this check before setting the member variables.
Although you can generally assume that these notifications happen all the time, the notifications usually happen only if the NameContext
also implements NameContextBindingEventSource
. This is because the NameContext
is responsible for sending the events, so if a NameContext
has a less responsible implementation, it might not send the notifications.