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: Server <location (any string)>");
            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 );

            // print stringified object reference
            FileWriter out = new FileWriter("ior");
            out.write( orb.object_to_string( obj ) );
            out.close();
    
            // wait for requests
	    System.out.println("Server started with IOR: " 
		+ orb.object_to_string(obj));
	    orb.run();
        }
        catch( SystemException e ) 
        {
            e.printStackTrace();
        }
        catch( java.lang.Exception ie) {
            System.err.println(ie);
        }
    }
}
