import net.jini.core.entry.*;
import net.jini.core.lookup.*; 
import net.jini.core.discovery.*;    
import net.jini.lookup.entry.*; 
import com.sun.jini.lookup.*;
import java.rmi.*;                    // needed for the RMI SecurityManager

/***************************************************************************

    MyClient -- The Jini Client Class

 ***************************************************************************/

    class MyClient
      {
      public static void main (String[] args)
        {
        String s;
        Entry[] aeAttributes;
        LookupLocator lookup;  
        ServiceRegistrar registrar;
        ServiceTemplate template;
        MyServerProxyInterface myServerProxyInterface;

        try 
          {


/*        Set a looser security manager so when the MyServerProxy
          object is received from the lookup service, the class loader
          will be able to fetch the MyServerProxy class to deserialize
          the object.  The serialized object has a codebase URL at the
          beginning of the stream that identifies the webserver from
          which missing classes can be fetched.
          ============================================================  */

          System.setSecurityManager (new RMISecurityManager ());


/*        Find the Jini lookup service and fetch a service proxy by the
          name "MyServerProxy".
          =============================================================  */

          System.out.println ();
          System.out.println ("main: Finding lookup service...");
          lookup = new LookupLocator ("jini://localhost");
          registrar  = lookup.getRegistrar ();

          System.out.println ("main: Fetching MyServerProxy...");
          aeAttributes = new Entry[1];
          aeAttributes[0] = new Name ("MyServerProxy");
          template = new ServiceTemplate (null, null, aeAttributes);
          myServerProxyInterface 
            = (MyServerProxyInterface) registrar.lookup (template);


/*        If the proxy object implements the proxy interface, then
          make a call to the server through the proxy.
          ========================================================  */

          if (myServerProxyInterface instanceof MyServerProxyInterface)
            {
            System.out.println ("main: Using the proxy to call the "
              + "service...");
            s = myServerProxyInterface.getGreeting ();
            }
          } 

        catch (Exception e) 
          {
          System.out.println ("main: MyClient.main() exception: " + e);
          }
        }
      }

