Java Reference
In-Depth Information
city:root.channel.location.@city,
region:root.channel.location.@region,
country:root.channel.location.@country,
condition:root.channel.item.condition.@text,
temp:root.channel.item.condition.@temp,
chill:root.channel.wind.@chill,
humidity:root.channel.atmosphere.@humidity
)
}
}
Given a WOEID, the service builds the URL and accesses the web service, parses the res-
ulting RSS, and returns an instance of the Weather class with all the relevant fields pop-
ulated.
To complete the program I need a driver, which I can write as a Groovy script. That's a
one-liner, unless I want to allow the client to specify a WOEID on the command line:
def woeid = args.size() ? args[0] : '2367105'
println new YahooParser().getWeather(woeid)
ThedefaultWOEIDinthescriptisforBoston,MA,andit'sstoredin RunDemo.groovy .
In order to demonstrate the differences when both Java and Groovy sources are present to-
gether, I also added a Java class to access the web service in the file RunInJava.java:
public class RunInJava {
public static void main(String[] args) {
String woeid = "2367105";
if (args.length > 0) woeid = args[0];
YahooParser yp = new YahooParser();
System. out .println(yp.getWeather(woeid));
}
}
Now comes the interesting part: how do I get Maven to handle all the Groovy code? The
Groovy-Eclipse plugin requires two additions to the POM file. First I need to add Groovy
as a dependency:
<dependencies>
...
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.5</version>
Search WWH ::




Custom Search