// Sample5/App.java
//##########################################################
// App Implementation using an Aclass interface AvlassIf
//##########################################################
//
public class App
{
public App(boolean localFlag)
{
    String serverClassName   = "Aclass";
    String serverClassNameCI = "AclassCI";
    String address = "127.0.0.1";
    int    port    = 6789;

    Class  theClass  = null;
    Object theObject = null;
    if(localFlag) // local implemenation
    {
      try
      {
      theClass   = Class.forName(serverClassName);
      theObject  = theClass.newInstance();
      }
      catch(Exception ex)
      {System.out.println("Class Not Found : " + ex.getMessage());};
    }
    else // distributed implementation
    {
    try
    {
        theClass   = Class.forName(serverClassNameCI);
        theObject  = theClass.newInstance();
    }
    catch(Exception ex)
    {System.out.println("Class Not Found : " + ex.getMessage());};
    // request the remote instance
    try
    {
    //((cam.netapp.CIinterface)theObject).setVerboseFlag(true);
    ((cam.netapp.CIinterface)theObject).createServerInstance(address,port);
    }
    catch(Exception e){System.out.println(e);};
    }
//
//  Cast the object to type AclassIf
//
    A = (AclassIf)theObject;
}

public int doCalculation(int D)
{
    return A.addTwo(D); // Call an Aclass method
}

//#### DATA MEMBERS ####

     AclassIf A;

public static void main(String argv[])
{
    App S1 = new App(true);

    System.out.println(" Local Results ");
    int result = S1.doCalculation(5);
    System.out.println("The result of the calculation = "
    + result+ " (and should = 7)");

    System.out.println(" ");
    System.out.println(" Distributed Results ");
    App S2 = new App(false);
    
    result = S2.doCalculation(5);
    System.out.println("The result of the calculation = "
    + result+ " (and should = 7)");

}
}