
import tauzaman.*;
import java.net.URL;

/**
* This is an example program, which focuses on configuration
* and usage of remote or local TauZamanServices.
*/

public class TauZamanClient{

  /* note that main method throws any exception */
  public static void main(String args[]) throws Exception{

      /***************BEGINNING OF INITIALIZATION AND CONFIGURATION PHASE***************/

      /* Create a TauZamanServiceManager. TauZamanServiceManager is an interface,
         implemented by the TauZamanServiceManagerImpl. It must be an interface to
         use RMI */
      TauZamanServiceManager tzsm = TauZamanServiceManagerImpl.getTauZamanSystem();
      
      /* Decleration of URLs */
      URL urlOfServer, urlOfDefaultProperties, urlOfAmericanCalendricSystem;

      /* Form URLs that we are interested */
      try{
          urlOfServer = new URL("http://www.eecs.wsu.edu/~burgun");
          urlOfDefaultProperties = new URL("http://www.eecs.wsu.edu/~burgun/files/defaultProperties.xml");
          urlOfAmericanCalendricSystem = new URL("http://www.eecs.wsu.edu/~burgun/files/americanv1.xml");
      }
      catch(MalformedURLException mue){
          // take corresponding action
          System.exit(1);
      }


      /* When we create a service, the speficied Calendric System will be 
         set as the active Calendric System. The just created service will
         also be set as the currently active service. Both can be changed 
         later. */

      /* initialize remote service from server */
      TauZamanService remoteService = tzsm.getService(UrlOfServerA, urlOfAmericanCalendricSystem, urlOfDefaultProperties);


      /* initialize local service from local server */
      TauZamanService localService = tzsm.getService(urlOfAmericanCalendricSystem, urlOfDefaultProperties));

      /***************END OF INITIALIZATION AND CONFIGURATION PHASE***************/

      /* set remote service as active */
      tzsm.setActiveService(remoteService);

      /* Create a local Instant object, but the date is parsed by the
         remote server because the remote service is the active service */
      Instant i = new Instant("September, 17, 2003");

      /* set local service as active */
      tzsm.setActiveService(localService);

      /* Create a local Instant object, but the date is parsed locally
         because the local service is the active service */
      Instant j = new Instant("September, 17, 2003");
      

  }

}

