package WebFlow.ContextManager; 

import WebFlow.*; 
import WebFlow.event.*; 
import WebFlow.RemoteFile.*;
import WebFlow.hashtable.*;
import WebFlow.ContextManager.ContextManagerPackage.*;
import org.omg.CORBA.*; 

public class Client{

   public static void main(String args[])
   {
      try {
         //  Create ORB
         Properties props = System.getProperties();
         props.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
         props.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton");
         System.setProperties(props);
         ORB orb = ORB.init(args, props);
 
        //  Connect to the master server

         if(args.length !=1) {
           System.out.println("Usage:");
           System.out.println("   WebFlow.JobService.Client url");
           System.out.println("     url - url to the master's IOR");
           System.exit(1);
	     }    
         String masterURL = args[0] ; 
    
         String ref ; 
         org.omg.CORBA.Object obj = null ; 
         ref = getIORFromURL(masterURL); 
         obj = orb.string_to_object(ref); 


         if(obj == null)
              throw new RuntimeException(); 
         WebFlowContext ws =  WebFlowContextHelper.narrow(obj);
         System.out.println("Clinet: got master "+ws);
  
         if(ws == null) throw new RuntimeException(); 
         
         /* attach modules: SaveContext, RemoteFile, ContextManager
            and ContextData */    

         org.omg.CORBA.Object p1 = ws.addNewModule("SaveContext");  
         SaveContext saveContext  = SaveContextHelper.narrow(p2);
         org.omg.CORBA.Object p2 = ws.addNewModule("RemoteFile");  
         RemoteFile remotefile = RemoteFileHelper.narrow(p1);
         org.omg.CORBA.Object p3 = ws.addNewModule("ContextManager");
         ContextManager cm = ContextManagerHelper.narrow(p3);
         org.omg.CORBA.Object p4 = ws.addNewModule("ContextData");
         ContextData cd = ContextDataHelper.narrow(p4);
   
         /* initialize ContextManager 
            by providing handles to UserContext, SaveContext 
            and RemoteFile modules 
            To simplify the example, the master server is used
            as the UserContext here     
          */ 

         cm.init(ws,p1,p2);

         /* ContextManager ready to use */

         ...

      } catch(COMM_FAILURE ex) {
         System.out.println("Command_Error: "+ex); 
         System.exit(1); 
      }  
   } 
}