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

Ajax

开发平台:

Java

  1. package ajaxdashboard.service;
  2. import ajaxdashboard.ws.weatherforecast.WeatherData;
  3. import ajaxdashboard.ws.weatherforecast.WeatherForecast;
  4. import ajaxdashboard.ws.weatherforecast.WeatherForecastLocator;
  5. import ajaxdashboard.ws.weatherforecast.WeatherForecastSoap;
  6. import ajaxdashboard.ws.weatherforecast.WeatherForecasts;
  7. import java.text.SimpleDateFormat;
  8. import javax.xml.rpc.ServiceException;
  9. public class WeatherForecastService {
  10.     public WeatherForecasts getForecastFor(String zipCode) {
  11.         WeatherForecasts forecasts = null;
  12.         try {
  13.             forecasts = getWeatherForecastSoap().getWeatherByZipCode(zipCode);
  14.             WeatherData[] dataArray = forecasts.getDetails().getWeatherData();
  15.             
  16.             WeatherData data = null;
  17.             SimpleDateFormat parser = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
  18.             SimpleDateFormat formatter = new SimpleDateFormat("EEE. MM/dd");
  19.             for(int i = 0; i < dataArray.length; i++) {
  20.                 data = dataArray[i];
  21.                 try {
  22.                     data.setDay(formatter.format(parser.parse(data.getDay())));
  23.                 }
  24.                 catch(Exception e) {
  25.                     System.out.println("nnnParsing Exception: " + e);
  26.                 }
  27.             }
  28.         } 
  29.         catch(java.rmi.RemoteException ex) {
  30.             // TODO handle remote exception
  31.         }
  32.         return forecasts;
  33.     }
  34.     private WeatherForecastSoap getWeatherForecastSoap() {
  35.         WeatherForecastSoap weatherForecastSoap = null;
  36.         try {
  37.             weatherForecastSoap = new WeatherForecastLocator().getWeatherForecastSoap();
  38.         } 
  39.         catch (ServiceException ex) {
  40.             ex.printStackTrace();
  41.         }
  42.         
  43.         return weatherForecastSoap;
  44.     }
  45. }