You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by rg...@apache.org on 2010/02/26 11:56:10 UTC

svn commit: r916644 - in /incubator/wookie/trunk: src-tests/org/apache/wookie/tests/connector/ src-tests/org/apache/wookie/tests/connector/framework/ src-tests/org/apache/wookie/tests/connector/framework/impl/ src/org/apache/wookie/connector/ src/org/a...

Author: rgardler
Date: Fri Feb 26 10:56:09 2010
New Revision: 916644

URL: http://svn.apache.org/viewvc?rev=916644&view=rev
Log:
Initial connector framework for Java. This is incomplete and not fully tested. I'm committing now in order to encourage feedback and contributions.


Added:
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/UserTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/WookieServerConnectionTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/MockWookieConnectorService.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstance.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstances.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorException.java
    incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieServerConnection.java

Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/UserTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/UserTest.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/UserTest.java (added)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/UserTest.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,62 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.tests.connector.framework;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.wookie.connector.framework.User;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class UserTest {
+  private static final String SCREEN_NAME = "screen name";
+  private static final String LOGIN_NAME = "login name";
+  static User user;
+  
+  @BeforeClass
+  public static void setUp() {
+    user = new User(LOGIN_NAME, SCREEN_NAME);
+  }
+  
+  @Test
+  public void testGetLoginName() {
+    assertEquals("Login name not correctly set", LOGIN_NAME, user.getLoginName());
+  }
+ 
+  @Test
+  public void testGetScreenName() {
+    assertEquals("Login name not correctly set", SCREEN_NAME, user.getScreenName());
+  }
+  
+  @Test
+  public void testSetLoginName() {
+    user.setLoginName("foo");
+    assertEquals("Login name not correctly set", "foo", user.getLoginName());
+
+    user.setLoginName(LOGIN_NAME);
+    assertEquals("Login name not correctly set", LOGIN_NAME, user.getLoginName());
+  }
+ 
+  @Test
+  public void testSetScreenName() {
+    user.setScreenName("foo");
+    assertEquals("Login name not correctly set", "foo", user.getScreenName());
+
+    user.setScreenName(SCREEN_NAME);
+    assertEquals("Login name not correctly set", SCREEN_NAME, user.getScreenName());
+  }
+  
+}

Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/WookieServerConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/WookieServerConnectionTest.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/WookieServerConnectionTest.java (added)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/WookieServerConnectionTest.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,48 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.tests.connector.framework;
+
+import org.apache.wookie.connector.framework.WookieConnectorException;
+import org.apache.wookie.connector.framework.WookieServerConnection;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class WookieServerConnectionTest {
+  private static final String TEST_URL = "http://localhost:8888/wookie";
+  private static final String TEST_API_KEY = "TEST";
+  private static final String TEST_SHARED_DATA_KEY = "myshareddata";
+  static WookieServerConnection conn;
+  
+  @BeforeClass
+  public static void setup() throws WookieConnectorException {
+    conn = new WookieServerConnection(TEST_URL, TEST_API_KEY, TEST_SHARED_DATA_KEY);  
+    assertNotNull("Connection object has not been set up correctly", conn);
+  }
+  
+  @Test
+  public void testGetURL() throws WookieConnectorException {
+    assertEquals("URL not set correctly", TEST_URL, conn.getURL());
+  }
+  
+  @Test
+  public void testSetURL() throws WookieConnectorException {
+    conn.setURL("foo");
+    assertEquals("URL not set correctly", "foo", conn.getURL());
+    conn.setURL(TEST_URL);
+    assertEquals("URL not set correctly", TEST_URL, conn.getURL());
+  }
+}

Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/MockWookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/MockWookieConnectorService.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/MockWookieConnectorService.java (added)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/MockWookieConnectorService.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,56 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.tests.connector.framework.impl;
+
+import org.apache.wookie.connector.framework.AbstractWookieConnectorService;
+import org.apache.wookie.connector.framework.User;
+import org.apache.wookie.connector.framework.WookieConnectorException;
+import org.apache.wookie.connector.framework.WookieServerConnection;
+/**
+ * A mock class for testing purposes.
+ * 
+ * @FIXME this is not really a mock class it connects, via the network to a live
+ * instance of Wookie. This is clearly bad for testing, we need to make this a real
+ * Mock class or at least run a local version of Wookie to test against.
+ */
+public class MockWookieConnectorService extends AbstractWookieConnectorService {
+
+  private static MockWookieConnectorService instance;
+  User testUser = new User("test", "test_user");
+  
+  public MockWookieConnectorService(String url, String apiKey,
+      String sharedDataKey) throws WookieConnectorException {
+    super(url, apiKey, sharedDataKey);
+  }
+
+  public User getCurrentUser() {
+    return testUser;
+  }
+
+  public User getUser(String login) {
+    if (login.equals(testUser.getLoginName())) {
+      return testUser;
+    }
+    return null;
+  }
+  
+  public static MockWookieConnectorService getInstance() throws WookieConnectorException {
+    if (instance == null) {
+      instance = new MockWookieConnectorService("http://bombax.oucs.ox.ac.uk:8888/wookie", "TEST", "myshareddata");
+      
+    }
+    return instance;
+  }
+
+}

Added: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java (added)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,61 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.tests.connector.framework.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.wookie.connector.framework.Widget;
+import org.apache.wookie.connector.framework.WidgetInstance;
+import org.apache.wookie.connector.framework.WookieConnectorException;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class WookieConnectorService {
+
+  private static MockWookieConnectorService service;
+
+  @BeforeClass
+  public static void setup() throws WookieConnectorException {
+    service = MockWookieConnectorService.getInstance();
+  }
+  
+  @Test
+  public void getCurrentUser() {
+    assertNotNull("Current user is null", service.getCurrentUser());
+  }
+  
+  @Test
+  public void getUser() {
+    assertNotNull("Test user is null", service.getUser("test"));
+  }
+  
+  @Test
+  public void getAvailableWidgets() throws WookieConnectorException {
+    HashMap<String, Widget> widgets = service.getAvailableWidgets();
+    assertTrue("Not retrieved enough widgets", 10 < widgets.size());
+    assertNotNull("Widget value is null", widgets.values().toArray()[0]);
+  }
+  
+  @Test
+  public void getOrCreateInstance() throws WookieConnectorException, IOException {
+    HashMap<String, Widget> widgets = service.getAvailableWidgets();
+    WidgetInstance instance = service.getOrCreateInstance((Widget)widgets.values().toArray()[0]);
+    assertNotNull("Retrieved widget instance is null", instance);
+  }
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,154 @@
+package org.apache.wookie.connector.framework;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public abstract class AbstractWookieConnectorService implements
+    IWookieConnectorService {
+  WookieServerConnection conn;
+  WidgetInstances instances = new WidgetInstances();
+  
+  public AbstractWookieConnectorService(String url, String apiKey, String sharedDataKey) throws WookieConnectorException {
+    setConnection(new WookieServerConnection(url, apiKey, sharedDataKey));
+  }
+  
+  /**
+   * Creates a WookieConnectorService that has not yet been initialised to connect
+   * to a specific server.
+   */
+  protected AbstractWookieConnectorService() {
+    super();
+  }
+  
+  public void setConnection(WookieServerConnection newConn) {
+    this.conn = newConn;
+  }
+  
+  public WookieServerConnection getConnection() {
+    return this.conn;
+  }
+  
+  /**
+   * Get or create an instance of a widget.
+   * 
+   * @param widget
+   * @return the ID of the widget instance
+   * @throws IOException
+   * @throws SimalRepositoryException
+   */
+  public WidgetInstance getOrCreateInstance(Widget widget) throws IOException,
+      WookieConnectorException {
+    URL url;
+    WidgetInstance instance;
+    try {
+      StringBuilder postdata = new StringBuilder("api_key=");
+      postdata.append(URLEncoder.encode(getConnection().getApiKey(), "UTF-8"));
+      postdata.append("&shareddatakey=");
+      postdata.append(URLEncoder.encode(getConnection().getSharedDataKey(), "UTF-8"));
+      postdata.append("&userid=");
+      postdata.append(URLEncoder.encode(getCurrentUser().getLoginName(), "UTF-8"));
+      postdata.append("&widgetid=");
+      postdata.append(URLEncoder.encode(widget.getIdentifier(), "UTF-8"));
+      
+      url = new URL(conn.getURL() + "/widgetinstances");
+      URLConnection conn = url.openConnection();
+      conn.setDoOutput(true);
+      OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+      wr.write(postdata.toString());
+      wr.flush();
+
+      InputStream is = conn.getInputStream();
+
+      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+      DocumentBuilder db = dbf.newDocumentBuilder();
+      instance = widget.addInstance(db.parse(is));
+      
+      instances.put(instance);
+
+      wr.close();
+      is.close();
+    } catch (MalformedURLException e) {
+      throw new RuntimeException("URL for supplied Wookie Server is malformed",
+          e);
+    } catch (ParserConfigurationException e) {
+      throw new RuntimeException("Unable to configure XML parser", e);
+    } catch (SAXException e) {
+      throw new RuntimeException("Problem parsing XML from Wookie Server", e);
+    }
+
+    return instance;
+  }
+
+  /**
+   * 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
+   */
+  public HashMap<String, Widget> getAvailableWidgets()
+      throws WookieConnectorException {
+    HashMap<String, Widget> widgets = new HashMap<String, Widget>();
+    try {
+      InputStream is = new URL(conn.getURL() + "/widgets?all=true").openStream();
+      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+      DocumentBuilder db = dbf.newDocumentBuilder();
+      Document widgetsDoc = db.parse(is);
+
+      Element root = widgetsDoc.getDocumentElement();
+      NodeList widgetList = root.getElementsByTagName("widget");
+      for (int idx = 0; idx < widgetList.getLength(); idx = idx + 1) {
+        Element widgetEl = (Element) widgetList.item(idx);
+        String id = widgetEl.getAttribute("identifier");
+        if (widgets.containsKey(id)) {
+          break;
+        }
+        String title = widgetEl.getElementsByTagName("title").item(0).getTextContent();
+        String description = widgetEl.getElementsByTagName("description").item(0).getTextContent();
+        Node iconEl = widgetEl.getElementsByTagName("icon").item(0);
+        URL iconURL;
+        if (iconEl != null) {
+          iconURL = new URL(iconEl.getTextContent());
+        } else {
+          iconURL = new URL("http://www.oss-watch.ac.uk/images/logo2.gif");
+        }
+        Widget widget = new Widget(id, title, description, iconURL);
+        widgets.put(id, widget);
+      }
+    } catch (ParserConfigurationException e) {
+      throw new WookieConnectorException("Unable to create XML parser", e);
+    } catch (MalformedURLException e) {
+      throw new WookieConnectorException("URL for Wookie is malformed", e);
+    } catch (IOException 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.
+      return widgets;
+    } catch (SAXException e) {
+      throw new WookieConnectorException(
+          "Unable to parse the response from Wookie", e);
+    }
+    return widgets;
+  }
+
+  
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,81 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.connector.framework;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+
+/**
+ * This service needs to be implemented on each platform. It provides methods
+ * for interfacing with the host environment. In order to use the connection
+ * service the Wookie Connection must have been initialised by calling
+ * connect(...), usually from within the constructor.
+ */
+public interface IWookieConnectorService {
+  
+  /**
+   * Setup the connection to the Wookie service. This must be called before any
+   * other method.
+   * 
+   * @param conn
+   *          - a connection to the Wookie server
+   * @return true if the connection has been correctly configured.
+   * @throws WookieConnectorException
+   *           if there is a problem setting up the connection
+   */
+  public void setConnection(WookieServerConnection conn)
+      throws WookieConnectorException;
+  
+  /**
+   * Get the currently active connection to the Wookie server.
+   * 
+   * @return
+   */
+  public WookieServerConnection getConnection();
+
+  /**
+   * Retrieve the details of the current user.
+   */
+  public User getCurrentUser();
+
+  /**
+   * Retrieve the details of a specific user, identified by their login name.
+   */
+  public User getUser(String login);
+
+  /**
+   * Get or create an instance of a widget.
+   * 
+   * @param widget
+   * @return the ID of the widget instance
+   * @throws IOException
+   * @throws SimalRepositoryException
+   */
+  public WidgetInstance getOrCreateInstance(Widget widget) throws IOException,
+      WookieConnectorException;
+  
+  /**
+   * 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
+   */
+  public HashMap<String, Widget> getAvailableWidgets()
+      throws WookieConnectorException;
+
+}
\ No newline at end of file

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,69 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.connector.framework;
+
+/**
+ * A user represents a possible user of a widget. This class provides a standard way
+ * of representing users in plugins for host environments.
+ */ 
+public class User {
+  private String loginName = "UNKNOWN";
+  private String screenName = "UNKNOWN";
+  
+  /**
+   * Create a new user.
+   * 
+   * @param loginName
+   * @param screenName
+   */
+  public User(String loginName, String screenName) {
+    setLoginName(loginName);
+    setScreenName(screenName);
+  }
+
+  /**
+   * Get the login name for this user.
+   */
+  public String getLoginName() {
+    return loginName;
+  }
+
+  /**
+   * Get the screen name for this user. This is the name that is intended to be displayed on
+   * screen. In many cases it will be the same as the login name.
+   */
+  public String getScreenName() {
+    return screenName;
+  }
+
+  /**
+   * Set the login name for this user. This is the value that is used by the user to register on the
+   * system, it is guaranteed to be unique.
+   * 
+   * @param loginName
+   */
+  public void setLoginName(String loginName) {
+    this.loginName = loginName;
+  }
+
+  /**
+   * Set the screen name for this user. this is the value that should be displayed on screen.
+   * In many cases it will be the same as the login name.
+   * 
+   * @param screenName
+   */
+  public void setScreenName(String screenName) {
+    this.screenName = screenName;
+  } 
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,106 @@
+package org.apache.wookie.connector.framework;
+
+/*
+ * Copyright 2008 University of Oxford
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");   *
+ * you may not use this file except in compliance with the License.  *
+ * You may obtain a copy of the License at                           *
+ *                                                                   *
+ *   http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                   *
+ * Unless required by applicable law or agreed to in writing,        *
+ * software distributed under the License is distributed on an       *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY            *
+ * KIND, either express or implied.  See the License for the         *
+ * specific language governing permissions and limitations           *
+ * under the License.                                                *
+ */
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * A client side representation of a widget. 
+ * 
+ * @refactor this duplicates data stored in the Widget bean on the server side.
+ */
+public class Widget { 
+  String identifier;
+  String title;
+  String description;
+  URL icon;
+  HashMap<String, WidgetInstance> instances = new HashMap<String, WidgetInstance>();
+
+  public Widget(String identifier, String title, String description, URL icon) {
+    this.identifier = identifier;
+    this.title = title;
+    this.description = description;
+    this.icon = icon;
+  }
+  
+  /**
+   * Get a unique identifier for this widget type.
+   * 
+   * @return
+   */
+  public String getIdentifier() {
+    return identifier;
+  }
+
+  /**
+   * Get the human readable title of this widget.
+   * @return
+   */
+  public String getTitle() {
+    return title;
+  }
+
+  /**
+   * Get the location of a logo for this widget.
+   * @return
+   */
+  public URL getIcon() {
+    return icon;
+  }
+  
+  /**
+   * Get the description of the widget.
+   * 
+   * @return
+   */
+  public String getDescription() {
+    return description;
+  }
+
+  /**
+   * Record an instance of the given widget.
+   * 
+   * @param xml description of the instance as returned by the widget server when the widget was instantiated.
+   * @return the identifier for this instance
+   */
+  public WidgetInstance addInstance(Document xml) {
+    Element rootEl = xml.getDocumentElement();
+    String url = rootEl.getElementsByTagName("url").item(0).getTextContent();
+    String id = rootEl.getElementsByTagName("identifier").item(0).getTextContent();
+    String title = rootEl.getElementsByTagName("title").item(0).getTextContent();
+    String height = rootEl.getElementsByTagName("height").item(0).getTextContent();
+    String width = rootEl.getElementsByTagName("width").item(0).getTextContent();
+    String maximize = rootEl.getElementsByTagName("maximize").item(0).getTextContent();
+    WidgetInstance instance = new WidgetInstance(url, id, title, height, width, maximize);
+    instances.put(id, instance);
+    
+    return instance;
+  }
+
+  /**
+   * Get all instances of a widget available in this server.
+   * @return
+   */
+  public Collection<WidgetInstance> getInstances() {
+    return instances.values();
+  }
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstance.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstance.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstance.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstance.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,75 @@
+package org.apache.wookie.connector.framework;
+
+/**
+ * An instance of a widget for use on the client.
+ * 
+ * @refactor this class duplicates code in the widget bean o nthe server side
+ *
+ */
+public class WidgetInstance {
+  String url;
+
+  String id;
+  String title;
+  String height;
+  String width;
+  String maximize;
+
+  public WidgetInstance(String url, String id, String title, String height,
+      String width, String maximize) {
+    setId(id);
+    setUrl(url);
+    setTitle(title);
+    setHeight(height);
+    setWidth(width);
+    setMaximize(maximize);
+  }
+  
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getHeight() {
+    return height;
+  }
+
+  public void setHeight(String height) {
+    this.height = height;
+  }
+
+  public String getWidth() {
+    return width;
+  }
+
+  public void setWidth(String width) {
+    this.width = width;
+  }
+
+  public String getMaximize() {
+    return maximize;
+  }
+
+  public void setMaximize(String maximize) {
+    this.maximize = maximize;
+  }
+}
\ No newline at end of file

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstances.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstances.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstances.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WidgetInstances.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,33 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.connector.framework;
+
+import java.util.HashMap;
+
+/**
+ * A collection of known widget instances available to a host.
+ */
+public class WidgetInstances extends HashMap<String, WidgetInstance> {
+  private static final long serialVersionUID = 1L;
+  
+  /**
+   * Record an instance of the given widget.
+   * 
+   * @param xml description of the instance as returned by the widget server when the widget was instantiated.
+   * @return the identifier for this instance
+   */
+  public void put(WidgetInstance instance) {
+    put(instance.getId(), instance);
+  }
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorException.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorException.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorException.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorException.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,29 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.connector.framework;
+
+/**
+ * And exception that represents a problem connecting with or communicating with
+ * a Wookie server or the host environment for plugins.
+ */
+public class WookieConnectorException extends Exception {
+  private static final long serialVersionUID = 1L;
+  
+  public WookieConnectorException(String message, Exception cause) {
+    super(message, cause);
+  }
+
+  
+
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieServerConnection.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieServerConnection.java?rev=916644&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieServerConnection.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieServerConnection.java Fri Feb 26 10:56:09 2010
@@ -0,0 +1,100 @@
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.connector.framework;
+
+import java.io.Serializable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A connection to a Wookie server. This maintains the necessary data for
+ * connecting to the server and provides utility methods for making common calls
+ * via the Wookie REST API.
+ * 
+ */
+public class WookieServerConnection implements Serializable {
+  private static final long serialVersionUID = 1L;
+  private static final Logger logger = LoggerFactory
+      .getLogger(WookieServerConnection.class);
+  private String url;
+  private String apiKey = "TEST";
+  private String sharedDataKey = "mysharedkey";
+
+  /**
+   * Create a connection to a Wookie server at a given URL.
+   * @param url the URL of the wookie server
+   * @param apiKey the API key for the server
+   * @param sharedDataKey the sharedDataKey for the server connection 
+   * 
+   * @throws WookieConnectorException if there is a problem setting up this connection.
+   */
+  public WookieServerConnection(String url, String apiKey, String sharedDataKey) throws WookieConnectorException {
+    setURL(url);
+    setApiKey(apiKey);
+    setSharedDataKey(sharedDataKey);
+  }
+
+  /**
+   * Get the URL of the wookie server.
+   * 
+   * @return
+   * @throws WookieConnectionException
+   */
+  public String getURL() throws WookieConnectorException {
+    return url;
+  }
+  
+  /**
+   * Set the URL of the wookie server.
+   * 
+   * @throws WookieConnectionException
+   */
+  public void setURL(String newUrl) throws WookieConnectorException {
+    this.url = newUrl;
+  }
+  
+  /**
+   * Get the API key for this server.
+   * 
+   * @return
+   */
+  public String getApiKey() {
+    return apiKey;
+  }
+
+  /**
+   * Set the API key for this server.
+   * 
+   */
+  public void setApiKey(String newApiKey) {
+    apiKey = newApiKey;
+  }
+
+  /**
+   * Get the shared data key for this server.
+   * 
+   * @return
+   */
+  public String getSharedDataKey() {
+    return sharedDataKey;
+  }
+
+  /**
+   * Set the shared data key for this server.
+   *
+   */
+  public void setSharedDataKey(String newKey) {
+    sharedDataKey = newKey;
+  }}