package jacorb.orb.domain.test;
/**
 * ReferenceTester.java
 *
 *
 * Created: Mon Jan 17 20:16:10 2000
 *
 * @author Herbert Kiefer
 * @version
 */
import jacorb.orb.domain.*;
import org.omg.CosNaming.*;
import jacorb.util.Debug;
import java.io.*;
public class ReferenceTester  {
  
 public static void main( String[] args )

  {
    new ReferenceTester(args);
  }

  ReferenceTester(String[] args) {

    int n= 10;
    Domain dm[]= new Domain[n];
    TestPolicy pol[]= new TestPolicy[10];
    org.omg.CORBA.Policy policy=     null;
    TestPolicy           testPolicy= null;
    jacorb.orb.domain.Domain[] list;
    String [] lines={
      "get policy", 
      "get domain managers", 
      "-------------------", 
      "finish"};
    org.omg.CORBA.ORB orb= null;
    NamingContextExt nc= null;
    NameComponent [] name = new NameComponent[1];

    try
      { // get name service
	orb = org.omg.CORBA.ORB.init(args,null);
	nc = NamingContextExtHelper.narrow
	  (orb.resolve_initial_references("NameService"));

	// get test policies
	for (int i= 0; i < 10; i++) 
	  {
	    name[0] = new NameComponent("TestPolicy"+i, "whatever");
	    pol[i]= TestPolicyHelper.narrow(nc.resolve(name));
	  }

	} catch (Exception e) {
	  Debug.output(1,e);
	}

    // main loop
    boolean end= false;
    int j, answer;
  try {
    while (!end)
     
      {

	answer= Util.textmenu(lines);
	System.out.println("answer is " + answer);
	switch (answer) {

	case 1:
	  System.out.println("of which object ?: ");
	  int i= Util.readInt();
	  System.out.println
	    ("policy is :"+TestPolicyHelper.narrow
	     (pol[i]._get_policy(i))._toString() );
	  break;

	case 2:
	  System.out.println("of which object ?: ");
	  i= Util.readInt();

	  list= (Domain[]) pol[i]._get_domain_managers();
	  for (i= 0; i < list.length; i++) 
	    System.out.println(list[i].description());
	  break;

	case 3: 
	  end= true; 
	  break;
	}
      }
  } catch (Exception e) { Debug.output(1,e); }
  }

} // ReferenceTester
