StockQuoteService.java
上传用户:shen332233
上传日期:2021-09-03
资源大小:7478k
文件大小:2k
源码类别:

Ajax

开发平台:

Java

  1. package ajaxdashboard.service;
  2. import ajaxdashboard.ws.stockquote.GetQuotes;
  3. import ajaxdashboard.ws.stockquote.GetQuotesResponse;
  4. import ajaxdashboard.ws.stockquote.Quote;
  5. import ajaxdashboard.ws.stockquote.StockQuotesLocator;
  6. import ajaxdashboard.ws.stockquote.StockQuotesSoap;
  7. import javax.xml.rpc.ServiceException;
  8. public class StockQuoteService {
  9.     public GetQuotesResponse getStockQuotesFor(String ticker) {
  10.         GetQuotes quotes = new GetQuotes(ticker);
  11.         GetQuotesResponse quotesResponse = null;
  12.         try {
  13.             quotesResponse = getStockQuotesSoap().getStockQuotes(quotes);
  14.         } catch(java.rmi.RemoteException ex) {
  15.             // TODO handle remote exception
  16.         }
  17.         
  18.         Quote[] quotesArray = quotesResponse.getGetQuotesResult().getQuote();
  19.         Quote quote = null;
  20.         for(int i = 0; i < quotesArray.length; i++) {
  21.             quote = quotesArray[i];
  22. //            System.out.println("Quote for: " + quote.getCompanyName()
  23. //                + " (" + quote.getStockTicker()+ ")"
  24. //                + "nQuote:" + quote.getStockQuote()
  25. //                + "nLastUpdate:" + quote.getLastUpdated()
  26. //                + "nChange:" + quote.getChange());
  27.         }
  28.         return quotesResponse;
  29.     }
  30.     private StockQuotesSoap getStockQuotesSoap() {
  31.         StockQuotesSoap stockQuotesSoap = null;
  32.         try {
  33.             stockQuotesSoap = new StockQuotesLocator().getStockQuotesSoap();
  34.         } catch (ServiceException ex) {
  35.             ex.printStackTrace();
  36.         }
  37.         return stockQuotesSoap;
  38.     }
  39. }