Revision: 1788
Author: [email protected]
Date: Thu Dec 17 13:42:01 2009
Log: If there is a problem connecting to the Wookie server return a null  
set of widgets and report issue accordingly
http://code.google.com/p/simal/source/detail?r=1788

Modified:
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieServerConnection.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.java

=======================================
---  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieServerConnection.java
    
Sun Dec 13 15:18:48 2009
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieServerConnection.java
    
Thu Dec 17 13:42:01 2009
@@ -21,6 +21,7 @@
  import java.io.OutputStreamWriter;
  import java.io.Serializable;
  import java.io.UnsupportedEncodingException;
+import java.net.ConnectException;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLConnection;
@@ -31,6 +32,8 @@
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;

+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
@@ -50,6 +53,8 @@
        private static final long serialVersionUID = 1L;
        private String wookieURL = "http://localhost:8888/wookie";;
        private HashMap<String, Widget> widgets = new HashMap<String, Widget>();
+       private static final Logger logger =  
LoggerFactory.getLogger(WookieServerConnection.class);
+

        /**
         * Get the URL of the wookie server.
@@ -144,7 +149,11 @@
        }

        /**
-        * Get a set of all the available widgets in the server.
+        * Get a set of all the available widgets in the server.
+        * If there is an error communicating with the server return an empty 
set,
+        * or the set received so far in order to allow
+        * the application to proceed. The application should display an  
appropriate message
+        * in this case.
         *
         * @return
         * @throws SimalException
@@ -187,7 +196,11 @@
                } catch (MalformedURLException e) {
                      throw new SimalException("URL for Wookie is malformed", 
e);
                } catch (IOException e) {
-                     throw new SimalException("Problem communicating with the 
Wookie  
server", e);
+                       // return an empty set, or the set received so far in 
order to allow
+                       // the application to proceed. The application should 
display an
+                       // appropriate message in this case.
+                       logger.debug("Error communicating with the widget 
server.", e);
+                       return widgets;
                } catch (SAXException e) {
                      throw new SimalException("Unable to parse the response 
from  
Wookie", e);
                }
=======================================
---  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.java
  
Sun Dec 13 15:18:48 2009
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.java
  
Thu Dec 17 13:42:01 2009
@@ -19,7 +19,6 @@

  import java.util.HashMap;
  import java.util.Iterator;
-import java.util.Set;

  import org.apache.wicket.markup.ComponentTag;
  import org.apache.wicket.markup.html.WebComponent;
@@ -56,24 +55,33 @@

    /**
     * Populate the panel with data.
-   * @param hashMap
+   * @param widgets a hashmap of the widgets to display in this panel
     *
     */
-  private void populatePanel(HashMap<String, Widget> hashMap) {
+  private void populatePanel(HashMap<String, Widget> widgets) {
      RepeatingView repeating = new RepeatingView("gallery");
-    Iterator<Widget> itr = hashMap.values().iterator();
-    Widget widget;
-       while(itr.hasNext()) {
-         WebMarkupContainer item = new  
WebMarkupContainer(repeating.newChildId());
-         repeating.add(item);
-         widget = itr.next();
-
-         item.add(new StaticImage("icon", new  
Model(widget.getIcon().toExternalForm())));
-         item.add(new Label("name", widget.getTitle()));
-         item.add(new Label("description", widget.getDescription()));
-
-         item.add(InstantiateWidgetPage.getLink("instantiate", widget));
-       }
+    if (widgets.size() > 0) {
+           Iterator<Widget> itr = widgets.values().iterator();
+           Widget widget;
+               while(itr.hasNext()) {
+                 WebMarkupContainer item = new  
WebMarkupContainer(repeating.newChildId());
+                 repeating.add(item);
+                 widget = itr.next();
+
+                 item.add(new StaticImage("icon", new  
Model(widget.getIcon().toExternalForm())));
+                 item.add(new Label("name", widget.getTitle()));
+                 item.add(new Label("description", widget.getDescription()));
+
+                 item.add(InstantiateWidgetPage.getLink("instantiate", 
widget));
+               }
+    } else {
+       WebMarkupContainer item = new  
WebMarkupContainer(repeating.newChildId());
+               repeating.add(item);
+               item.add(new StaticImage("icon", new Model("")));
+               item.add(new Label("name", "Widget Server"));
+               item.add(new Label("description", "There was a problem 
communicting with  
the Widget server"));
+               item.add(new Label("instantiate", ""));
+    }
        add(repeating);
    }

--

You received this message because you are subscribed to the Google Groups 
"Simal Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.


Reply via email to