import atg.nucleus.*;
import atg.naming.*;

public class Jerry implements NameContextBindingListener {
    NameContext nameContext;
    String name;
    Tom t;

    public Jerry() {
    }

    public String getSound(){
        if (t==null){
            t = (Tom) Nucleus.getGlobalNucleus().resolveName( "Tom", nameContext, true );
        }
        if (t!=null)
            return t.getSound();
        else
            return "Sorry";
    }

    //NameContextBindingListener Interface
    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;
        }
    }
}
1