Author: rgardler
Date: Sun Feb 28 23:13:22 2010
New Revision: 917317
URL: http://svn.apache.org/viewvc?rev=917317&view=rev
Log:
Implement a WookieConnectorService for use within Wookie itself.
This required some refactoring of the connector framework:
- Remove unused instance collection from Widget class
- move parsing of XML widget instance description to connector service
- allow retrieval/creation of a widget using GUID
Added:
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorService.java
Modified:
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/Widget.java
Modified:
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=917317&r1=917316&r2=917317&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
Sun Feb 28 23:13:22 2010
@@ -61,6 +61,11 @@
*/
public WidgetInstance getOrCreateInstance(Widget widget) throws IOException,
WookieConnectorException {
+ return getOrCreateInstance(widget.identifier);
+ }
+
+ public WidgetInstance getOrCreateInstance(String guid) throws IOException,
+ WookieConnectorException {
URL url;
WidgetInstance instance;
try {
@@ -71,7 +76,7 @@
postdata.append("&userid=");
postdata.append(URLEncoder.encode(getCurrentUser().getLoginName(),
"UTF-8"));
postdata.append("&widgetid=");
- postdata.append(URLEncoder.encode(widget.getIdentifier(), "UTF-8"));
+ postdata.append(URLEncoder.encode(guid, "UTF-8"));
logger.debug("Makeing Wookie REST query using: " + postdata);
@@ -86,7 +91,7 @@
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
- instance = widget.addInstance(db.parse(is));
+ instance = parseInstance(guid, db.parse(is));
instances.put(instance);
@@ -106,6 +111,30 @@
return instance;
}
+ /**
+ * Parse an XML document returned from the Wookie server that describes a
widget instance.
+ *
+ * @param widgetId the identifier of the widget this document represents
+ * @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 parseInstance(String widgetId, Document xml) {
+ Element rootEl = xml.getDocumentElement();
+ String url = rootEl.getElementsByTagName("url").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, widgetId, title, height,
width, maximize);
+ return instance;
+ }
+
+ /**
+ * @refactor At time of writing the REST API for adding a participant is
broken so we are
+ * using the non-REST approach. The code for REST API is commented out and
should be used
+ * in the future.
+ */
public void addParticipant(WidgetInstance widget, User user) throws
WookieConnectorException {
StringBuilder postdata;
try {
Modified:
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=917317&r1=917316&r2=917317&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
Sun Feb 28 23:13:22 2010
@@ -59,12 +59,23 @@
* Get or create an instance of a widget. The current user will be added as
a participant.
*
* @param widget
- * @return the ID of the widget instance
+ * @return the widget instance
* @throws IOException
* @throws SimalRepositoryException
*/
public WidgetInstance getOrCreateInstance(Widget widget) throws IOException,
WookieConnectorException;
+
+ /**
+ * Get or create an instance of a widget. The current user will be added as
a participant.
+ *
+ * @param guid global identifier for widget to be instantiated
+ * @return the widget instance
+ * @throws IOException
+ * @throws SimalRepositoryException
+ */
+ public WidgetInstance getOrCreateInstance(String guid) throws IOException,
+ WookieConnectorException;
/**
* Add a participant to a widget.
Modified:
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=917317&r1=917316&r2=917317&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
Sun Feb 28 23:13:22 2010
@@ -17,11 +17,6 @@
* 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.
@@ -33,7 +28,6 @@
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;
@@ -75,32 +69,4 @@
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 = getIdentifier();
- 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/WookieConnectorService.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorService.java?rev=917317&view=auto
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorService.java
(added)
+++
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/WookieConnectorService.java
Sun Feb 28 23:13:22 2010
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * An implementation of the WookieConnectorService for use by Wookie itself.
+ *
+ */
+public class WookieConnectorService extends AbstractWookieConnectorService {
+ User currentUser;
+
+ public WookieConnectorService(String url, String apiKey, String
sharedDataKey) throws WookieConnectorException {
+ setConnection(new WookieServerConnection(url, apiKey, sharedDataKey));
+ }
+
+ public User getCurrentUser() {
+ if (currentUser == null) {
+ currentUser = getTestUser();
+ }
+ return currentUser;
+ }
+
+ private User getTestUser() {
+ return new User("testuser", "Test User");
+ }
+
+ public User getUser(String login) {
+ if (login.toLowerCase().equals("testuser")) {
+ return getCurrentUser();
+ }
+ return null;
+ }
+
+
+}