com.oopitis.weather.owm
Class OwmData<T>

java.lang.Object
  extended by com.oopitis.weather.URLDataSource<T>
      extended by com.oopitis.weather.owm.OwmData<T>

public abstract class OwmData<T>
extends URLDataSource<T>

Helper class to retrieve data from openweathermap.org. This class is kept abstract to allow the use of a different parser.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.oopitis.weather.URLDataSource
URLDataSource.FetchException
 
Field Summary
 
Fields inherited from class com.oopitis.weather.URLDataSource
licenseKey
 
Constructor Summary
protected OwmData(java.lang.String apiKey, java.net.Proxy proxy)
          Constructs a data source with an API key and a network proxy.
 
Method Summary
 WeatherPropertySet getApplicableProperties(Feature f)
          Returns the applicable properties associated with a feature.
protected  java.lang.String getBaseUrl()
          Gets the base URL; for example, "http://api.openweathermap.org/data/2.5/".
protected abstract  WeatherReport getCurrentConditions(GeoLocation loc, OwmQueryHint.Language lang)
          Gets the current weather conditions for a location.
protected abstract  java.util.List<WeatherReport> getDailyConditions(GeoLocation loc, OwmQueryHint.Language lang, java.lang.Integer numOfDays)
          Gets daily weather conditions for a location.
protected abstract  java.util.List<WeatherReport> getHourlyConditions(GeoLocation loc, OwmQueryHint.Language lang)
          Gets hourly weather conditions for a location.
protected abstract  java.util.List<WeatherReport> getMultiLocationConditions(GeoLocation loc, OwmQueryHint.Language lang)
          Gets weather conditions for multiple locations.
protected  java.lang.String getUrlCurrent(GeoLocation loc, OwmQueryHint.Language lang)
          Constructs a URL for retrieving the current weather data.
protected  java.lang.String getUrlDaily(GeoLocation loc, OwmQueryHint.Language lang, java.lang.Integer numOfDays)
          Constructs a URL for retrieving daily weather data up to 14 days.
protected  java.lang.String getUrlHourly(GeoLocation loc, OwmQueryHint.Language lang)
          Constructs a URL for retrieving hourly (actually every 3 hours) weather data.
protected  java.lang.String getUrlMultiLocation(GeoLocation loc, OwmQueryHint.Language lang)
          Constructs a URL for retrieving weather data from multiple locations.
protected  OwmLocation newOwmLocation(java.lang.Long id, java.lang.String city, java.lang.String countryCodeOrName, GeoLocation.Coordinates coordinates)
          Creates a location object to be used in a report.
protected abstract  boolean xmlMode()
          Returns true if the data requested from openwewathermap.org should be in XML; otherwise the data will be in JSON format.
 
Methods inherited from class com.oopitis.weather.URLDataSource
fetch, parse, setProxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OwmData

protected OwmData(java.lang.String apiKey,
                  java.net.Proxy proxy)
Constructs a data source with an API key and a network proxy.

Parameters:
apiKey - the API key
proxy - the network proxy
Method Detail

getBaseUrl

protected java.lang.String getBaseUrl()
Gets the base URL; for example, "http://api.openweathermap.org/data/2.5/".

Returns:
the base URL

getUrlCurrent

protected java.lang.String getUrlCurrent(GeoLocation loc,
                                         OwmQueryHint.Language lang)
Constructs a URL for retrieving the current weather data.

Parameters:
loc - the location
lang - the language; null to use the default
Returns:
the URL for retrieving the current weather data

getUrlHourly

protected java.lang.String getUrlHourly(GeoLocation loc,
                                        OwmQueryHint.Language lang)
Constructs a URL for retrieving hourly (actually every 3 hours) weather data.

Parameters:
loc - the location
lang - the language; null to use the default
Returns:
the URL for retrieving the hourly weather data

getUrlDaily

protected java.lang.String getUrlDaily(GeoLocation loc,
                                       OwmQueryHint.Language lang,
                                       java.lang.Integer numOfDays)
Constructs a URL for retrieving daily weather data up to 14 days.

Parameters:
loc - the location
lang - the language; null to use the default
numOfDays - the number of days ranging from 1 to 14; null to use the default
Returns:
the URL for retrieving daily weather data
Throws:
java.lang.IllegalArgumentException - if the number of days is out of range

getUrlMultiLocation

protected java.lang.String getUrlMultiLocation(GeoLocation loc,
                                               OwmQueryHint.Language lang)
Constructs a URL for retrieving weather data from multiple locations.

Parameters:
loc - the common attributes of the locations
lang - the language; null to use the default
Returns:
the URL for retrieving weather data from multiple locations

newOwmLocation

protected OwmLocation newOwmLocation(java.lang.Long id,
                                     java.lang.String city,
                                     java.lang.String countryCodeOrName,
                                     GeoLocation.Coordinates coordinates)
Creates a location object to be used in a report. The reason of having this special factory method is that openweathermap.org sometimes returns the full name of a country instead of the country code. That creates a discrepancy between the location object used in a query and the location object used in a report, because one cannot query openweathermap.org by a full country name.

Parameters:
id - the city ID
city - the city name
countryCodeOrName - the two-letter country code or full country name
coordinates - the latitude and longitude
Returns:
the new location object

getApplicableProperties

public WeatherPropertySet getApplicableProperties(Feature f)
Returns the applicable properties associated with a feature.

Parameters:
f - the feature
Returns:
the applicable properties

xmlMode

protected abstract boolean xmlMode()
Returns true if the data requested from openwewathermap.org should be in XML; otherwise the data will be in JSON format. HTML format is not supported.

Returns:
true if the data requested from openweathermap.org should be in XML
See Also:
URLDataSource.parse(BufferedReader)

getCurrentConditions

protected abstract WeatherReport getCurrentConditions(GeoLocation loc,
                                                      OwmQueryHint.Language lang)
Gets the current weather conditions for a location.

Parameters:
loc - the location
lang - the language; null to use the default
Returns:
the current weather conditions

getHourlyConditions

protected abstract java.util.List<WeatherReport> getHourlyConditions(GeoLocation loc,
                                                                     OwmQueryHint.Language lang)
Gets hourly weather conditions for a location.

Parameters:
loc - the location
lang - the language; null to use the default
Returns:
the hourly weather conditions

getDailyConditions

protected abstract java.util.List<WeatherReport> getDailyConditions(GeoLocation loc,
                                                                    OwmQueryHint.Language lang,
                                                                    java.lang.Integer numOfDays)
Gets daily weather conditions for a location.

Parameters:
loc - the location
lang - the language; null to use the default
numOfDays - the number of days ranging from 1 to 14; null to use the default
Returns:
the daily weather conditions
Throws:
java.lang.IllegalArgumentException - if the number of days is out of range

getMultiLocationConditions

protected abstract java.util.List<WeatherReport> getMultiLocationConditions(GeoLocation loc,
                                                                            OwmQueryHint.Language lang)
Gets weather conditions for multiple locations.

Parameters:
loc - the common attributes of the locations
lang - the language; null to use the default
Returns:
the hourly weather conditions