import helloWorld.*;

import java.io.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;

public class Server 
{
    public static void main(String[] args) 
    {
        if( args.length != 1 ) 
	{
            System.out.println(
                "Usage: java com.wiley.compbooks.brose.chapter4.extended.helloWorld.Server <location>");
            System.exit( 1 );
        }

        try {
            //init orb
            ORB orb = ORB.init( args, null );

            // init POA
            POA poa = POAHelper.narrow( orb.resolve_initial_references("RootPOA"));
	    poa.the_POAManager().activate();

            // create a GoodDay object
            GoodDayImpl goodDayImpl = new GoodDayImpl( args[0] );
    
            // create the object reference
            org.omg.CORBA.Object obj = poa.servant_to_reference( goodDayImpl );

            // export the object reference
            FileWriter out = new FileWriter("ior");
            out.write( orb.object_to_string( obj ) );
            out.close();
    
            // wait for requests
	    orb.run();
        }   
	// POA exceptions WrongPolicy and ServantNotActiv
        catch( UserException e ) {
            System.err.println(e);
        }
        catch( SystemException e ) {
            System.err.println(e);
        }
        catch( IOException e ) {
            System.err.println(e);
        }
    }
}
