FileDocCategorySizeDatePackage
GetQuote.javaAPI DocApache Axis 1.43115Sat Apr 22 18:56:52 BST 2006samples.stock

GetQuote

public class GetQuote extends Object
author
Doug Davis (dug@us.ibm.com.com)

Fields Summary
public String
symbol
Constructors Summary
public GetQuote()

  
Methods Summary
public floatgetQuote(java.lang.String[] args)

      Options opts = new Options( args );

      args = opts.getRemainingArgs();

      if ( args == null ) {
        System.err.println( "Usage: GetQuote <symbol>" );
        System.exit(1);
      }

      symbol = args[0] ;

      // useful option for profiling - perhaps we should remove before
      // shipping?
      String countOption = opts.isValueSet('c");
      int count=1;
      if ( countOption != null) {
          count=Integer.valueOf(countOption).intValue();
          System.out.println("Iterating " + count + " times");
      }

      URL url = new URL(opts.getURL());
      String user = opts.getUser();
      String passwd = opts.getPassword();

      Service  service = new Service();

      Float res = new Float(0.0F);
      for (int i=0; i<count; i++) {
          Call     call    = (Call) service.createCall();

          call.setTargetEndpointAddress( url );
          call.setOperationName( new QName("urn:xmltoday-delayed-quotes", "getQuote") );
          call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN );
          call.setReturnType( XMLType.XSD_FLOAT );

          // TESTING HACK BY ROBJ
          if (symbol.equals("XXX_noaction")) {
              symbol = "XXX";
          }

          call.setUsername( user );
          call.setPassword( passwd );

          Object ret = call.invoke( new Object[] {symbol} );
          if (ret instanceof String) {
              System.out.println("Received problem response from server: "+ret);
              throw new AxisFault("", (String)ret, null, null);
          }
        res = (Float) ret;
      }

        return res.floatValue();
    
public static voidmain(java.lang.String[] args)

    try {
        GetQuote gq = new GetQuote();
        float val = gq.getQuote(args);
        // args array gets side-effected
        System.out.println(gq.symbol + ": " + val);
    }
    catch( Exception e ) {
       e.printStackTrace();
    }