Zembly, Sang Shin, and Swing

I took the first half of Sang Shin's Zembly Basics course today. It was the first time that I'd ever used Zembly. I didn't even really know what it was, before taking Sang's course.

It seems pretty cool. Zembly is an on-line platform for creating 'things', which are 'services', 'widgets', and 'applications'. First you create services (such as a weather service) and then you create widgets that provide a presentation layer on top of the services (such as a widget where the user needs to type in a zip code for the area of interest for the weather service). Then you make the widgets available to others, by embedding them in your website, or something similar. (You can also create applications, but that's the second part of the course, which I haven't done yet.) You can very easily reuse other people's services and widgets too. Hard to visualize all this without doing it yourself, though.

So then I created a service following Sang's instructions and then thought: "Why would I create an on-line widget when I could just as easily create a widget in Swing?" So I created a small NetBeans module that calls my service from a menu item:

public final class GreetMeAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        int ageValue = 34;
        String nameValue = "Tom";
        try {
            URL zemblyServiceURL = new URL("http://zembly.com/things/099efc10ebed4e4899decd62d7aad4ba;exec?name=" + nameValue + "&age=" + ageValue);
            URLDisplayer.getDefault().showURL(zemblyServiceURL);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    
}

Then the browser opens, displaying this result:

Hi Tom! Your age is 34

So, the menu item is the widget for my Zembly service. It would be even better to be able to receive the results within Swing, rather than needing to open the browser to see them. Not sure how that would be done, though. But, imagine creating a weather service in Zembly. Then you'd (under the hood of your module) call that service and then do something with the results, within the module itself. But how could one get access to the results?

Comments:

There are various ways to read the content of a URL (Jakarta Commons HTTP Client is best for complex cases), but you can read the content by calling the URL's openStream() method.

Posted by Tom Wheeler on November 14, 2008 at 04:17 AM PST #

Perfect, thanks. Seems to me there's a big opportunity for JavaFX in the context of Zembly, both of which are important to Sun. Here's now the Swing version:

public final class GreetMeAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
int ageValue = 34;
String nameValue = "Tom";
try {
URL zemblyServiceURL = new URL("http://zembly.com/things/099efc10ebed4e4899decd62d7aad4ba;exec?name=" + nameValue + "&age=" + ageValue);
BufferedReader in = new BufferedReader(
new InputStreamReader(
zemblyServiceURL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
JOptionPane.showMessageDialog(null, inputLine);
}
in.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}

}

Posted by Geertjan on November 14, 2008 at 04:32 AM PST #

I guess this is where the Semantic Web would come in handy. Imagine if your Zembly service provided weather forecasts when given a city. You would want to get the output back, and ask for just the "TommorowWeather" tag, or something similar.

This Zembly stuff is cool, thank you for sharing!

Posted by David Koelle on November 20, 2008 at 04:58 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« May 2015
SunMonTueWedThuFriSat
     
2
3
8
9
10
19
22
23
24
25
26
27
28
29
30
31
      
Today