import bench.*;
import org.omg.CosNaming.*;

public class BenchServeur
{
  //
  // Fonction principale implantant un processeur serveur CORBA
  //
  public static void main(String args[])
  {
    try {
      	//
      	// Initialisation du bus CORBA pour un processus serveur.
      	//
      	// Fixer les propriétés pour utiliser ORBacus.
      	//
/* ALL */
      	java.util.Properties props = System.getProperties();
	
/* ORBACUS */
		props.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
props.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton");
      	System.setProperties(props);	  


    	// Création des objets ORB. 
	// idem a Orbacus et JacORB
    	//
/* ALL */
      	org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props);

      	//
      	// Obtenir le BOA
      	//
/* JavaORB */
		org.omg.CORBA.BOA boa = org.omg.CORBA.BOA.init(orb, args);

/* ORBACUS */
org.omg.CORBA.BOA boa = ((com.ooc.CORBA.ORB)orb).BOA_init (args, props);

/* VBROKER */
   	org.omg.CORBA.BOA boa = ((com.visigenic.vbroker.orb.ORB)orb).BOA_init();

		// POA
		//
		// Resolve the RootPOA reference
/* JacORB & (JavaORB) */
		org.omg.CORBA.Object objRef = null;
		org.omg.PortableServer.POA poa = null;

		objRef = orb.resolve_initial_references("RootPOA");
		poa = org.omg.PortableServer.POAHelper.narrow(objRef);

		//
      	// Création de l'objet d'implantation de l'interface IDL Bench.
      	//
/* JacORB & (JavaORB) */
      	org.omg.CORBA.Object bench = poa.servant_to_reference(new BenchImpl());

/* ORBACUS & VBROKER & JavaORB */
      	BenchImpl bench = new BenchImpl();

		//
		// Obtenir la Reference du NameService
/* VBROKER */
      	NamingContext nc =		com.inprise.vbroker.services.CosNaming.NamingContextHelper.bind(orb,"NameService/1");

/* JacORB & Orbacus & JavaORB */
		org.omg.CORBA.Object obj = null;
		org.omg.CosNaming.NamingContextExt nc = null;
		obj = orb.resolve_initial_references("NameService");
		nc = org.omg.CosNaming.NamingContextExtHelper.narrow(obj);
/* Seulement pour JavaORB */
		boa.connect(bench);
		
		//
		// Enregistrement de l'objet aupres du service de nommage
		//
		//
/* ALL */
		NameComponent [] name = new NameComponent[1];
		name[0] = new NameComponent( "bench","");

/* ORBACUS et VBROKER */
	nc.rebind(name, bench);

/* JacORB et JAvaORB n'accepte pas la fonction rebind immediatement */
		nc.bind(name, bench);

		//
		// Le serveur attend la connexion des clients
/* VBROKER & JavaORB */
		boa.obj_is_ready(bench) ;
		boa.impl_is_ready();
/* JacORB */
		orb.run() ;

/* ORBACUS */
		boa.impl_is_ready(null);

    	//
// en cas de problème lié à l'utilisation de CORBA.
   	//
    } catch(org.omg.CORBA.SystemException ex) {
      System.err.println(ex.getMessage());
      ex.printStackTrace();
      System.exit(1);
    } catch (Exception e ) {
	    e.printStackTrace();
    }
  }
}
