
import tauzaman.*;
import java.net.URL;

/**
* This is an example program, which focuses on configuration
* and usage of remote or local TauZamanServices.
*/

public class LocalTauZamanClient{

  /* note that main method throws any exception */
  public static void main(String args[]) throws Exception{

      /***************BEGINNING OF INITIALIZATION AND CONFIGURATION PHASE***************/

      /* Create a TauZamanSystem. */
      TauZamanSystem tzs = TauZamanSystem.getTauZamanSystem();
      
      /* URL of remote service as string */
      String urlOfServer;

      /* Decleration of URLs */
      URL urlOfDefaultProperties, urlOfAmericanCalendricSystem;

      /* Form URLs that we are interested */
      try{
          urlOfServer = "dyreson2.eecs.wsu.edu";
          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 remote server */
      TauZamanRemoteService remoteService = tzs.getRemoteService(UrlOfServerA, urlOfAmericanCalendricSystem, urlOfDefaultProperties);


      /* initialize local service from local server */
      TauZamanLocalService localService = tzs.getLocalService(urlOfAmericanCalendricSystem, urlOfDefaultProperties));

      /***************END OF INITIALIZATION AND CONFIGURATION PHASE***************/

      /* set remote service as active */
      tzs.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 */
      tzs.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");
      

  }

}

