package uk.ac.roe.wfau;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.rpc.ParameterMode;


/**
 * Titre : Sesame
 * Description : Resolves names in Simbad and VizieR
 * Copyright : Copyright (c) 2002-2003
 * Société : Centre de Données Astronomique de Strasbourg
 * @author André Schaaff
 * @version 1.0
 */
public class Sesame {

  /**
   * A local method which contains all the code to access the remote resolving method
   * @param name a name to resolve
   * @return a result which has to be parsed to extract informations
   */
  public String getNameResolved(String name) {

    String ret = null;
    try {
      // URL corresponding to the Web Service which will be called
      String endpoint = "http://cdsws.u-strasbg.fr/axis/services/Sesame";

      // Name of the method which will be invoked
      String method = "Sesame";

      // Creates a Service object
      Service  service = new Service();

      // Creates a Call object
      Call call = (Call) service.createCall();

      // Initialization of the call with the parameters
      call.setTargetEndpointAddress( new java.net.URL(endpoint) );
      call.setOperationName( method );
      call.addParameter( "op1", XMLType.XSD_STRING, ParameterMode.IN );
      call.setReturnType( XMLType.XSD_STRING );

      // Invokes the remote method and gets a result
      ret = (String)call.invoke( new Object [] { name });
    }
    catch (Exception e ) {System.out.println("getNameResolved : " + e);}
    return ret;
  }

  public static void main(String [] args) throws Exception {

    // Sesame object
    Sesame sesame = new Sesame();

    // Calls the the resolving method with the command line argument
    String result = sesame.getNameResolved(args[0]);
    if (result != null)
      System.out.println("The result is : " + result);
    else
      System.out.println("Sorry but no result found ");
  }
}
