// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package corbatest.server;

import java.util.Properties;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

import corbatest.common.TestHelper;

public class Server2 {
    private static final String NAMESERVER = "localhost";
    private static final String NAMESERVER_PORT = "1050";
    private static final String NAME = "TestJ2";
    public static void main(String[] args) throws Exception {
        Properties p = new Properties();
        p.put("org.omg.CORBA.ORBClass", "com.sun.corba.se.impl.orb.ORBImpl");
        p.put("org.omg.CORBA.ORBInitialHost", NAMESERVER);
        p.put("org.omg.CORBA.ORBInitialPort", NAMESERVER_PORT);
        ORB orb = ORB.init(args, p);
        POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        poa.the_POAManager().activate();
        TestImpl srv = new TestImpl();
        NamingContextExt nc = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
        nc.rebind(nc.to_name(NAME), TestHelper.narrow(poa.servant_to_reference(srv)));
        orb.run();
        //System.out.print("Press enter to exit");
        //System.in.read();
        //nc.unbind(nc.to_name(NAME));
        //orb.shutdown(false);
    }
}
