You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by ra...@apache.org on 2010/06/15 16:41:01 UTC
svn commit: r954915 [2/2] - in /incubator/wookie/trunk/connector/flash_flex:
./ com/ com/google/ com/google/code/ com/google/code/flexiframe/
com/google/code/flexiframe/assets/ org/ org/apache/ org/apache/wookie/
org/apache/wookie/connector/ org/apache...
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddConnectionFormTitleWindow.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddConnectionFormTitleWindow.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddConnectionFormTitleWindow.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddConnectionFormTitleWindow.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="300" height="200">
+
+ <mx:Script>
+ <![CDATA[
+ import mx.controls.Alert;
+ import mx.managers.PopUpManager;
+
+ public var sourceConnectionManager:WookieServerConnectionManager = null;
+
+ private function cancelAddConnectionForm():void {
+ PopUpManager.removePopUp(this);
+ }
+
+ private function submitAddConnectionForm():void {
+ if (isAddConnectionFormValid()) {
+ var new_connection:Object = {
+ url:addConnectionFormURL.text,
+ api_key:addConnectionFormAPIKey.text,
+ shared_key:addConnectionFormSharedKey.text
+ };
+ if(null != sourceConnectionManager) {
+ sourceConnectionManager.connections.addItem(new_connection);
+ }
+ PopUpManager.removePopUp(this);
+ } else {
+ Alert.show("Please fill all fields. They are all requiered.\nPlease write valid URL including protocol in field URL.", "Instructions to create a connection", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+
+ private function isAddConnectionFormValid():Boolean {
+ return isURLValid() && isAPIKeyValid() && isSharedKeyValid();
+ }
+
+ private function isURLValid():Boolean {
+ var url_regexp:RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
+ return url_regexp.test(addConnectionFormURL.text);
+ }
+
+ private function isAPIKeyValid():Boolean {
+ return 0 < addConnectionFormAPIKey.text.length;
+ }
+
+ private function isSharedKeyValid():Boolean {
+ return 0 < addConnectionFormSharedKey.text.length;
+ }
+ ]]>
+ </mx:Script>
+ <mx:Form id="addConnectionForm" defaultButton="{addConnectionFormCancel}">
+ <mx:FormItem label="URL" required="true">
+ <mx:TextInput id="addConnectionFormURL"/>
+ </mx:FormItem>
+ <mx:FormItem label="API Key" required="true">
+ <mx:TextInput id="addConnectionFormAPIKey"/>
+ </mx:FormItem>
+ <mx:FormItem label="SharedKey" required="true">
+ <mx:TextInput id="addConnectionFormSharedKey"/>
+ </mx:FormItem>
+ <mx:HBox>
+ <mx:FormItem>
+ <mx:Button id="addConnectionFormCancel" label="Cancel" click="cancelAddConnectionForm()"/>
+ </mx:FormItem>
+ <mx:FormItem>
+ <mx:Button id="addConnectionFormSubmit" label="Submit" click="submitAddConnectionForm()"/>
+ </mx:FormItem>
+ </mx:HBox>
+ </mx:Form>
+</mx:TitleWindow>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddUserFormTitleWindow.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddUserFormTitleWindow.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddUserFormTitleWindow.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/AddUserFormTitleWindow.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="300" height="200">
+
+ <mx:Script>
+ <![CDATA[
+ import mx.controls.Alert;
+ import mx.managers.PopUpManager;
+
+ public var sourceUserManager:UserManager = null;
+
+ private function cancelAddUserForm():void {
+ PopUpManager.removePopUp(this);
+ }
+
+ private function submitAddUserForm():void {
+ if (isAddUserFormValid()) {
+ var new_user:Object = {
+ login:addUserFormLogin.text,
+ name:addUserFormName.text,
+ thumbnail:addUserFormThumbnail.text
+ };
+ if(null != sourceUserManager) {
+ sourceUserManager.users.addItem(new_user);
+ }
+ PopUpManager.removePopUp(this);
+ } else {
+ Alert.show("Please fill requiered fields Name and Login.\nPlease write valid URL including protocol in field Thumbnail.", "Instructions to create an user", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+
+ private function isAddUserFormValid():Boolean {
+ return isNameValid() && isLoginValid() && isThumbnailValid();
+ }
+
+ private function isNameValid():Boolean {
+ return 0 < addUserFormName.text.length;
+ }
+
+ private function isLoginValid():Boolean {
+ return 0 < addUserFormLogin.text.length;
+ }
+
+ private function isThumbnailValid():Boolean {
+ // if not valid
+ // event.preventDefault();
+ var thumbnail_url:String = addUserFormThumbnail.text;
+ if(0 < thumbnail_url.length) {
+ var url_regexp:RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
+ return url_regexp.test(thumbnail_url);
+ } else {
+ // no value is requiered
+ return true;
+ }
+ }
+ ]]>
+ </mx:Script>
+
+
+ <mx:Form id="addUserForm" defaultButton="{addUserFormCancel}">
+ <mx:FormItem label="Name" required="true">
+ <mx:TextInput id="addUserFormName"/>
+ </mx:FormItem>
+ <mx:FormItem label="Login" required="true">
+ <mx:TextInput id="addUserFormLogin"/>
+ </mx:FormItem>
+ <mx:FormItem label="Thumbnail">
+ <mx:TextInput id="addUserFormThumbnail"/>
+ </mx:FormItem>
+ <mx:HBox>
+ <mx:FormItem>
+ <mx:Button id="addUserFormCancel" label="Cancel" click="cancelAddUserForm()"/>
+ </mx:FormItem>
+ <mx:FormItem>
+ <mx:Button id="addUserFormSubmit" label="Submit" click="submitAddUserForm()"/>
+ </mx:FormItem>
+ </mx:HBox>
+ </mx:Form>
+</mx:TitleWindow>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalUserManager.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalUserManager.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalUserManager.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalUserManager.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--- Component managing users of wookie server widgets -->
+<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="320" height="360">
+ <mx:Script>
+ <![CDATA[
+ import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
+ import org.apache.wookie.connector.framework.User;
+
+ /**
+ * Collection of user as Object objects.
+ */
+ [Bindable]
+ public var users:ArrayCollection = new ArrayCollection([
+ {login:"bob", name:"Bobby", thumbnail:""}
+ ]);
+
+ /**
+ * Utility fonction to manage User objects as standard objects.
+ */
+ public function fromUserToObject (u:User):Object {
+ return {login: u.getLoginName(), name: u.getScreenName(), thumbnail:u.getThumbnailUrl()};
+ }
+
+ /**
+ * Utility fonction to retrieve an User objects as standard object.
+ */
+ public function fromObjectToUser (o:Object):User {
+ return new User(o.login, o.name, o.thumbnail);
+ }
+
+ private function showAddUserForm():void {
+ addUserFormBox.visible = true;
+ }
+
+ private function submitAddUserForm():void {
+ if (isAddUserFormValid()) {
+ var new_user:Object = {
+ login:addUserFormLogin.text,
+ name:addUserFormName.text,
+ thumbnail:addUserFormThumbnail.text
+ }
+ users.addItem(new_user);
+ addUserFormName.text = "";
+ addUserFormLogin.text = "";
+ addUserFormThumbnail.text = "";
+ addUserFormBox.visible = false;
+ } else {
+ Alert.show("Please fill requiered fields Name and Login.\nPlease write valid URL including protocol in field Thumbnail.", "Instructions to create an user", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+
+ private function isAddUserFormValid():Boolean {
+ return isNameValid() && isLoginValid() && isThumbnailValid();
+ }
+
+ private function isNameValid():Boolean {
+ return 0 < addUserFormName.text.length;
+ }
+
+ private function OriginalUserManager():Boolean {
+ return 0 < addUserFormLogin.text.length;
+ }
+
+ private function isThumbnailValid():Boolean {
+ // if not valid
+ // event.preventDefault();
+ var thumbnail_url:String = addUserFormThumbnail.text;
+ if(0 < thumbnail_url.length) {
+ var url_regexp:RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
+ return url_regexp.test(thumbnail_url);
+ } else {
+ // no value is requiered
+ return true;
+ }
+ }
+
+ private function deleteAvailableUser():void {
+ if(0 <= availableUsers.selectedIndex && availableUsers.selectedIndex < availableUsers.dataProvider.source.length) {
+ availableUsers.dataProvider.removeItemAt(availableUsers.selectedIndex);
+ } else {
+ Alert.show("Please select a row to delete its corresponding user.", "Instructions to delete an user", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+ ]]>
+ </mx:Script>
+ <mx:HBox>
+ <mx:Button id="addUser" label="New user" click="showAddUserForm()"/>
+ <mx:Button id="deleteUser" label="Delete user" click="deleteAvailableUser()"/>
+ </mx:HBox>
+
+ <mx:VBox id="addUserFormBox" visible="false">
+ <mx:Form id="addUserForm" defaultButton="{addUserFormCancel}">
+ <mx:FormItem label="Name" required="true">
+ <mx:TextInput id="addUserFormName"/>
+ </mx:FormItem>
+ <mx:FormItem label="Login" required="true">
+ <mx:TextInput id="addUserFormLogin"/>
+ </mx:FormItem>
+ <mx:FormItem label="Thumbnail">
+ <mx:TextInput id="addUserFormThumbnail"/>
+ </mx:FormItem>
+ <mx:HBox>
+ <mx:FormItem>
+ <mx:Button id="addUserFormCancel" label="Cancel" click="{addUserFormBox.visible = false;}"/>
+ </mx:FormItem>
+ <mx:FormItem>
+ <mx:Button id="addUserFormSubmit" label="Submit" click="submitAddUserForm()"/>
+ </mx:FormItem>
+ </mx:HBox>
+ </mx:Form>
+ </mx:VBox>
+
+ <mx:HBox id="availableUsersBox">
+ <mx:DataGrid id="availableUsers" dataProvider="{users}" rowHeight="30" verticalAlign="middle" height="155">
+ <mx:columns>
+ <mx:DataGridColumn headerText="Name" dataField="name"/>
+ <mx:DataGridColumn headerText="Login" dataField="login"/>
+ <mx:DataGridColumn headerText="Thumbnail" dataField="thumbnail" itemRenderer="mx.controls.Image"/>
+ </mx:columns>
+ </mx:DataGrid>
+ </mx:HBox>
+</mx:VBox>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalWookieServerConnectionManager.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalWookieServerConnectionManager.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalWookieServerConnectionManager.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/OriginalWookieServerConnectionManager.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--- Component managing data to connect to wookie server(s) -->
+<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="320" height="360">
+ <mx:Script>
+ <![CDATA[
+ import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
+ import org.apache.wookie.connector.framework.WookieServerConnection;
+
+ /**
+ * Collection of data to connect to wookie server as Object objects.
+ */
+ [Bindable]
+ public var connections:ArrayCollection = new ArrayCollection([
+ {url:"http://localhost:8080/wookie/", api_key:"TEST", shared_key:"mysharedkey"}
+ ]);
+
+ /**
+ * Utility fonction to manage WookieServerConnection objects as standard objects.
+ */
+ public function fromConnectionToObject(c:WookieServerConnection):Object {
+ return {url: c.getURL(), api_key: c.getApiKey(), shared_key: c.getSharedDataKey()};
+ }
+
+ /**
+ * Utility fonction to retrieve a WookieServerConnection object from a standard object.
+ */
+ public function fromObjectToConnection(o:Object):WookieServerConnection {
+ return new WookieServerConnection(o.url, o.api_key, o.shared_key);
+ }
+
+ private function showAddConnectionForm():void {
+ addConnectionFormBox.visible = true;
+ }
+
+ private function submitAddConnectionForm():void {
+ if (isAddConnectionFormValid()) {
+ var new_connection:Object = {
+ url:addConnectionFormURL.text,
+ api_key:addConnectionFormAPIKey.text,
+ shared_key:addConnectionFormSharedKey.text
+ }
+ connections.addItem(new_connection);
+ addConnectionFormURL.text = "";
+ addConnectionFormAPIKey.text = "";
+ addConnectionFormSharedKey.text = "";
+ addConnectionFormBox.visible = false;
+ } else {
+ Alert.show("Please fill all fields. They are all requiered.\nPlease write valid URL including protocol in field URL.", "Instructions to create a connection", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+
+ private function isAddConnectionFormValid():Boolean {
+ return isURLValid() && isAPIKeyValid() && isSharedKeyValid();
+ }
+
+ private function isURLValid():Boolean {
+ var url_regexp:RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
+ return url_regexp.test(addConnectionFormURL.text);
+ }
+
+ private function isAPIKeyValid():Boolean {
+ return 0 < addConnectionFormAPIKey.text.length;
+ }
+
+ private function isSharedKeyValid():Boolean {
+ return 0 < addConnectionFormSharedKey.text.length;
+ }
+
+ private function deleteAvailableConnection():void {
+ if(0 <= availableConnections.selectedIndex && availableConnections.selectedIndex < availableConnections.dataProvider.source.length) {
+ availableConnections.dataProvider.removeItemAt(availableConnections.selectedIndex);
+ } else {
+ Alert.show("Please select a row to delete its corresponding connection.", "Instructions to delete a connection", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:HBox id="connectionFunctionalities">
+ <mx:Button id="addConnection" label="New connection" click="showAddConnectionForm()"/>
+ <mx:Button id="deleteConnection" label="Delete connection" click="deleteAvailableConnection()"/>
+ </mx:HBox>
+
+ <mx:VBox id="addConnectionFormBox" visible="false">
+ <mx:Form id="addConnectionForm" defaultButton="{addConnectionFormCancel}">
+ <mx:FormItem label="URL" required="true">
+ <mx:TextInput id="addConnectionFormURL"/>
+ </mx:FormItem>
+ <mx:FormItem label="API Key" required="true">
+ <mx:TextInput id="addConnectionFormAPIKey"/>
+ </mx:FormItem>
+ <mx:FormItem label="SharedKey" required="true">
+ <mx:TextInput id="addConnectionFormSharedKey"/>
+ </mx:FormItem>
+ <mx:HBox>
+ <mx:FormItem>
+ <mx:Button id="addConnectionFormCancel" label="Cancel" click="{addConnectionFormBox.visible = false;}"/>
+ </mx:FormItem>
+ <mx:FormItem>
+ <mx:Button id="addConnectionFormSubmit" label="Submit" click="submitAddConnectionForm()"/>
+ </mx:FormItem>
+ </mx:HBox>
+ </mx:Form>
+ </mx:VBox>
+
+ <mx:HBox id="availableConnectionsBox">
+ <mx:DataGrid id="availableConnections" dataProvider="{connections}">
+ <mx:columns>
+ <mx:DataGridColumn headerText="URL" dataField="url"/>
+ <mx:DataGridColumn headerText="API Key" dataField="api_key"/>
+ <mx:DataGridColumn headerText="Shared Key" dataField="shared_key"/>
+ </mx:columns>
+ </mx:DataGrid>
+ </mx:HBox>
+</mx:VBox>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/UserManager.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/UserManager.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/UserManager.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/UserManager.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--- Component managing users of wookie server widgets -->
+<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
+ width="320" height="220"
+ horizontalAlign="center" verticalAlign="middle">
+ <mx:Script>
+ <![CDATA[
+ import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
+ import mx.core.IFlexDisplayObject;
+ import mx.managers.PopUpManager;
+ import org.apache.wookie.connector.framework.User;
+
+ /**
+ * Collection of user as Object objects.
+ */
+ [Bindable]
+ public var users:ArrayCollection = new ArrayCollection([
+ {login:"bob", name:"Bobby", thumbnail:""}
+ ]);
+
+ /**
+ * Utility fonction to manage User objects as standard objects.
+ */
+ public function fromUserToObject (u:User):Object {
+ return {login: u.getLoginName(), name: u.getScreenName(), thumbnail:u.getThumbnailUrl()};
+ }
+
+ /**
+ * Utility fonction to retrieve an User objects as standard object.
+ */
+ public function fromObjectToUser (o:Object):User {
+ return new User(o.login, o.name, o.thumbnail);
+ }
+
+ private function showAddUserForm():void {
+ var addUserForm:AddUserFormTitleWindow = AddUserFormTitleWindow(
+ PopUpManager.createPopUp(this, AddUserFormTitleWindow, false));
+ addUserForm.sourceUserManager = this;
+ addUserForm.showCloseButton=true;
+ PopUpManager.centerPopUp(addUserForm);
+ }
+
+ private function deleteAvailableUser():void {
+ if(0 <= availableUsers.selectedIndex && availableUsers.selectedIndex < availableUsers.dataProvider.source.length) {
+ availableUsers.dataProvider.removeItemAt(availableUsers.selectedIndex);
+ } else {
+ Alert.show("Please select a row to delete its corresponding user.", "Instructions to delete an user", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+ ]]>
+ </mx:Script>
+ <mx:HBox>
+ <mx:Button id="addUser" label="New user" click="showAddUserForm()"/>
+ <mx:Button id="deleteUser" label="Delete user" click="deleteAvailableUser()"/>
+ </mx:HBox>
+
+ <mx:VBox id="addUserFormBox" visible="false">
+ </mx:VBox>
+
+ <mx:HBox id="availableUsersBox">
+ <mx:DataGrid id="availableUsers" dataProvider="{users}" rowHeight="30" verticalAlign="middle" height="155">
+ <mx:columns>
+ <mx:DataGridColumn headerText="Name" dataField="name"/>
+ <mx:DataGridColumn headerText="Login" dataField="login"/>
+ <mx:DataGridColumn headerText="Thumbnail" dataField="thumbnail" itemRenderer="mx.controls.Image"/>
+ </mx:columns>
+ </mx:DataGrid>
+ </mx:HBox>
+</mx:VBox>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceContainer.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceContainer.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceContainer.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceContainer.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.example
+{
+ import mx.containers.VBox;
+
+ import org.apache.wookie.connector.framework.User;
+ import org.apache.wookie.connector.framework.WookieServerConnection;
+
+ /**
+ * Base class of user interfaces for Wookie service(s).
+ */
+ public class WookieConnectorServiceContainer extends VBox {
+ private var _users:Array;
+ private var _current_user:User;
+ private var _connection:WookieServerConnection;
+
+ public function WookieConnectorServiceContainer(connection:WookieServerConnection=null) {
+ super();
+ this._users = [];
+ this._connection = connection;
+ }
+
+ public function get users ():Array {
+ return this._users;
+ }
+
+ public function set users (new_users:Array):void {
+ this._users = new_users;
+ }
+
+ public function get current_user ():User {
+ return this._current_user;
+ }
+
+ public function set current_user (new_current_user:User):void {
+ this._current_user = new_current_user;
+ }
+
+ public function get connection ():WookieServerConnection {
+ return this._connection;
+ }
+
+ public function set connection (new_connection:WookieServerConnection):void {
+ this._connection = new_connection;
+ }
+ }
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceView.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceView.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceView.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieConnectorServiceView.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--- Interface for Wookie service and manager of widgets -->
+<wookie:WookieConnectorServiceContainer xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns:wookie="org.apache.wookie.connector.example.*"
+ xmlns:flexiframe="com.google.code.flexiframe.*"
+ width="640"
+ horizontalAlign="center">
+ <mx:Script>
+ <![CDATA[
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.net.URLLoader;
+ import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
+ import org.apache.wookie.connector.framework.WookieConnectorService;
+ import org.apache.wookie.connector.framework.User;
+ import org.apache.wookie.connector.framework.Widget;
+ import org.apache.wookie.connector.framework.WidgetInstance;
+ import org.apache.wookie.connector.framework.WidgetInstanceLoader;
+ import org.apache.wookie.connector.framework.WookieConnectorService;
+ import org.apache.wookie.connector.framework.WookieServerConnection;
+
+ /**
+ * Collection of widgets gathered after a click on createConnectorBtn.
+ */
+ [Bindable]
+ public var widgets:ArrayCollection = new ArrayCollection();
+
+ private var connector:WookieConnectorService = null;
+
+ private function setConnector(new_connector:WookieConnectorService):void {
+ connector = new_connector;
+ }
+
+ private function createConnector():WookieConnectorService {
+ if(null == connection) {
+ Alert.show("Please select a connection to create a connector.", "Instructions to create a connector", Alert.OK, null, null, null, Alert.OK);
+ return connector;
+ }
+ if(null == current_user) {
+ Alert.show("Please select an user to create a connector.", "Instructions to create a connector", Alert.OK, null, null, null, Alert.OK);
+ return connector;
+ }
+ var wookie_connector:WookieConnectorService = new WookieConnectorService()
+ wookie_connector.setConnection(connection);
+ wookie_connector.setUsers(users);
+ wookie_connector.setCurrentUser(current_user);
+ return wookie_connector;
+ }
+
+ private function getAllWidgets():void {
+ if (null == connector) {
+ Alert.show("Create a connector to get its widgets.", "Instructions to get widgets", Alert.OK, null, null, null, Alert.OK);
+ return;
+ }
+ var async_widgets:URLLoader = connector.getAvailableWidgets();
+ async_widgets.addEventListener(Event.COMPLETE, getAllWidgetsComplete);
+ }
+
+ private function getAllWidgetsComplete(event:Event):void {
+ var allWidgets:ArrayCollection = new ArrayCollection();
+ var async_widgets:URLLoader = URLLoader(event.target);
+ for each(var asw:Widget in async_widgets.data) {
+ var asw_obj:Object = { id:asw.getIdentifier(), title:asw.getTitle(), desc:asw.getDescription(), icon:asw.getIconUrl() };
+ allWidgets.addItem( asw_obj );
+ }
+ widgets = allWidgets;
+ }
+
+ private function getWidgetInstance():void {
+ if (!(0 <= availableWidgets.selectedIndex && availableWidgets.selectedIndex < availableWidgets.dataProvider.source.length)) {
+ Alert.show("Please select a row corresponding to a widget to instanciate it.", "Instructions to instanciate a widget", Alert.OK, null, null, null, Alert.OK);
+ return;
+ }
+ if (null == connector) {
+ Alert.show("Create a connector to instanciate one of its widgets.", "Instructions to instanciate a widget", Alert.OK, null, null, null, Alert.OK);
+ return;
+ }
+ var widget_obj:Object = availableWidgets.dataProvider.getItemAt(availableWidgets.selectedIndex);
+ var async_widget_inst:WidgetInstanceLoader = connector.getOrCreateInstanceWithId(widget_obj.id);
+ async_widget_inst.addEventListener(Event.COMPLETE, getWidgetInstanceComplete);
+ async_widget_inst.addEventListener(IOErrorEvent.IO_ERROR, getWidgetInstanceError);
+ }
+
+ private function getWidgetInstanceComplete(event:Event):void {
+ var async_widget_inst:WidgetInstance = WidgetInstance(event.target.data);
+
+ trace(async_widget_inst.getId() + " " +
+ async_widget_inst.getTitle() + " " +
+ async_widget_inst.getUrl() + " " +
+ async_widget_inst.getWidth() + "x" +
+ async_widget_inst.getHeight() + "(WxH)");
+
+ widgetInstanceIFr.label = async_widget_inst.getTitle();
+ widgetInstanceIFr.source = async_widget_inst.getUrl();
+ widgetInstanceIFr.width = Number(async_widget_inst.getWidth());
+ widgetInstanceIFr.height = Number(async_widget_inst.getHeight());
+ }
+
+ private function getWidgetInstanceError(event:IOErrorEvent):void {
+ Alert.show(event.text, "Input/Output Error", Alert.OK, null, null, null, Alert.OK);
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:HBox>
+ <mx:Button id="createConnectorBtn" label="New connector" click="setConnector(createConnector())"/>
+ <mx:Button id="getAllWidgetsBtn" label="Get widgets" click="getAllWidgets()"/>
+ <mx:Button id="getInstanceBtn" label="Get an instance" click="getWidgetInstance()"/>
+ </mx:HBox>
+ <mx:DataGrid id="availableWidgets" dataProvider="{widgets}" width="620" rowHeight="30" verticalAlign="middle">
+ <mx:columns>
+ <mx:DataGridColumn headerText="Id" dataField="id"/>
+ <mx:DataGridColumn headerText="Title" dataField="title"/>
+ <mx:DataGridColumn headerText="Description" dataField="desc"/>
+ <mx:DataGridColumn headerText="Icon" dataField="icon" itemRenderer="mx.controls.Image"/>
+ </mx:columns>
+ </mx:DataGrid>
+ <mx:Panel>
+ <flexiframe:IFrame id="widgetInstanceIFr" source="http://www.google.com"/>
+ </mx:Panel>
+</wookie:WookieConnectorServiceContainer>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieServerConnectionManager.mxml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieServerConnectionManager.mxml?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieServerConnectionManager.mxml (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/example/WookieServerConnectionManager.mxml Tue Jun 15 14:41:00 2010
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--- Component managing data to connect to wookie server(s) -->
+<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
+ width="320" height="220"
+ horizontalAlign="center" verticalAlign="middle">
+ <mx:Script>
+ <![CDATA[
+ import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
+ import mx.managers.PopUpManager;
+
+ import org.apache.wookie.connector.framework.WookieServerConnection;
+
+ /**
+ * Collection of data to connect to wookie server as Object objects.
+ */
+ [Bindable]
+ public var connections:ArrayCollection = new ArrayCollection([
+ {url:"http://localhost:8080/wookie/", api_key:"TEST", shared_key:"mysharedkey"}
+ ]);
+
+ /**
+ * Utility fonction to manage WookieServerConnection objects as standard objects.
+ */
+ public function fromConnectionToObject(c:WookieServerConnection):Object {
+ return {url: c.getURL(), api_key: c.getApiKey(), shared_key: c.getSharedDataKey()};
+ }
+
+ /**
+ * Utility fonction to retrieve a WookieServerConnection object from a standard object.
+ */
+ public function fromObjectToConnection(o:Object):WookieServerConnection {
+ return new WookieServerConnection(o.url, o.api_key, o.shared_key);
+ }
+
+ private function showAddConnectionForm():void {
+ var addConnectionForm:AddConnectionFormTitleWindow = AddConnectionFormTitleWindow(
+ PopUpManager.createPopUp(this, AddConnectionFormTitleWindow, false));
+ addConnectionForm.sourceConnectionManager = this;
+ addConnectionForm.showCloseButton = true;
+ PopUpManager.centerPopUp(addConnectionForm);
+ }
+
+ private function deleteAvailableConnection():void {
+ if(0 <= availableConnections.selectedIndex && availableConnections.selectedIndex < availableConnections.dataProvider.source.length) {
+ availableConnections.dataProvider.removeItemAt(availableConnections.selectedIndex);
+ } else {
+ Alert.show("Please select a row to delete its corresponding connection.", "Instructions to delete a connection", Alert.OK, null, null, null, Alert.OK);
+ }
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:HBox id="connectionFunctionalities">
+ <mx:Button id="addConnection" label="New connection" click="showAddConnectionForm()"/>
+ <mx:Button id="deleteConnection" label="Delete connection" click="deleteAvailableConnection()"/>
+ </mx:HBox>
+
+ <mx:HBox id="availableConnectionsBox">
+ <mx:DataGrid id="availableConnections" dataProvider="{connections}">
+ <mx:columns>
+ <mx:DataGridColumn headerText="URL" dataField="url"/>
+ <mx:DataGridColumn headerText="API Key" dataField="api_key"/>
+ <mx:DataGridColumn headerText="Shared Key" dataField="shared_key"/>
+ </mx:columns>
+ </mx:DataGrid>
+ </mx:HBox>
+</mx:VBox>
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/IWookieConnectorService.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/IWookieConnectorService.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/IWookieConnectorService.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/IWookieConnectorService.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,127 @@
+/*
+ * 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 flash.net.URLLoader;
+
+ /**
+ * 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.
+ * @throws WookieConnectorException if there is a problem setting up the connection
+ */
+ function setConnection(conn:WookieServerConnection):void;
+
+ /**
+ * Get the currently active connection to the Wookie server.
+ *
+ * @return WookieServerConnection Current connection to the server.
+ */
+ function getConnection():WookieServerConnection;
+
+ /**
+ * Retrieve the details of a specific user, identified with their user_id.
+ * Return null if no user is identified with user_id.
+ *
+ * @return Data of the user identified with user_id or null.
+ */
+ function getUser(user_id:String):User;
+
+ /**
+ * Retrieve the details of the current user.
+ *
+ * @return Data of the current user.
+ */
+ function getCurrentUser():User;
+
+ /**
+ * Set the current user with the user passed as parameter.
+ *
+ * @param user The next current user.
+ */
+ function setCurrentUser(user:User):void;
+
+ /**
+ * Retrieve the user identified with the parameter user_id
+ * and set it as the current user.
+ *
+ * @param user_id Id of the next current user. Usually this would be the login
+ * name of the user, but it need not be, it simply needs to be a unique identifier
+ * among all users.
+ * @throws WookieConnectorException if no user is identified with user_id.
+ */
+ function setCurrentUserWithId(user_id:String):void;
+
+ /**
+ * Get or create an instance of a widget. The current user will be added as a participant.
+ *
+ * @param widget
+ * @return the widget instance
+ * @throws IOError
+ * @throws SimalRepositoryException
+ */
+ function getOrCreateInstance(widget:Widget):WidgetInstanceLoader;
+
+ /**
+ * 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 loader that allows to get the widget instance in an asynchronous manner.
+ * @throws IOError
+ * @throws SimalRepositoryException
+ * @throws WookieConnectorexception if no widget is identified with guid.
+ */
+ function getOrCreateInstanceWithId(guid:String):WidgetInstanceLoader;
+
+ /**
+ * Add a participant to a widget.
+ *
+ * @param instance the Widget Instance to add the participant to
+ * @param user the user to add as a participant
+ * @return The loader used to add a participant, which allows to know if operation succeed or failed.
+ * @throws WookieConnectorexception
+ */
+ function addParticipant(widget:WidgetInstance, user:User):URLLoader;
+
+ /**
+ * 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 The loader having requested the listing of widgets.
+ * This allows to get result in an asynchronous manner.
+ * @throws SimalException
+ */
+ function getAvailableWidgets():URLLoader;
+
+ /**
+ * Get all the instances of widgets that are currently managed by this service.
+ *
+ * @return Instance of widgets managed by this service.
+ */
+ function getInstances():WidgetInstances;
+
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/User.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/User.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/User.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/User.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,108 @@
+/*
+ * 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 {
+ /**
+ * Login name.
+ */
+ private var _login_name:String;
+ /**
+ * Full name.
+ */
+ private var _screen_name:String;
+ /**
+ * URL pointing to a thumbnail.
+ */
+ private var _thumbnail_url:String;
+
+ /**
+ * Create a new user.
+ * No check are done on URL validity.
+ *
+ * @param loginName Login name of user is mandatory.
+ * @param screenName Full name of user is optional.
+ * @param thumbnailUrl URL pointing to a thumbnail of user is optional.
+ */
+ public function User(login_name:String, screen_name:String="", thumbnail_url:String="") {
+ setLoginName(login_name);
+ setScreenName(screen_name);
+ setThumbnailUrl(thumbnail_url);
+ }
+
+ /**
+ * Get the login name for this user.
+ *
+ * @return Login name of this user.
+ */
+ public function getLoginName():String {
+ return _login_name;
+ }
+
+ /**
+ * 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 new_login_name Login name to assign to this user.
+ */
+ public function setLoginName(new_login_name:String):void {
+ this._login_name = new_login_name;
+ }
+
+ /**
+ * 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.
+ *
+ * @return Full name of this user.
+ */
+ public function getScreenName():String {
+ return _screen_name;
+ }
+
+ /**
+ * 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 new_screen_name Full name to assign to this user.
+ */
+ public function setScreenName(new_screen_name:String):void {
+ this._screen_name = new_screen_name;
+ }
+
+ /**
+ * Get the URL for a thumbnail representing this user.
+ *
+ * @return User thumbnail icon url.
+ */
+ public function getThumbnailUrl():String {
+ return _thumbnail_url;
+ }
+
+ /**
+ * Set the URL for a thumbnail representing this user.
+ * No check are done on URL validity.
+ *
+ * @param new_thumbnail_url URL pointing to a thumbnail to assign to this user.
+ */
+ public function setThumbnailUrl(new_thumbnail_url:String):void {
+ this._thumbnail_url = new_thumbnail_url;
+ }
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/Widget.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/Widget.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/Widget.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/Widget.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,92 @@
+/*
+ * 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 client side representation of a widget.
+ *
+ * @refactor this duplicates data stored in the Widget bean on the server side.
+ */
+ public class Widget {
+ /**
+ * Unique identifier for this widget.
+ */
+ private var _identifier:String;
+ /**
+ * Title for this widget.
+ */
+ private var _title:String;
+ /**
+ * Description for this widget.
+ */
+ private var _description:String;
+ /**
+ * URL pointing to an icon for this widget.
+ */
+ private var _icon_url:String;
+
+ /**
+ * Create a new client side representation of a widget.
+ *
+ * @param identifier Identifier is mandatory.
+ * @param title Title is mandatory.
+ * @param description Description is mandatory.
+ * @param icon_url URL to an icon is optional.
+ */
+ public function Widget(identifier:String, title:String, description:String, icon_url:String="") {
+ this._identifier = identifier;
+ this._title = title;
+ this._description = description;
+ this._icon_url = icon_url;
+ }
+
+ /**
+ * Get a unique identifier for this widget type.
+ *
+ * @return Identifier of this widget.
+ */
+ public function getIdentifier():String {
+ return this._identifier;
+ }
+
+ /**
+ * Get the human readable title of this widget.
+ *
+ * @return Title of this widget.
+ */
+ public function getTitle():String {
+ return this._title;
+ }
+
+ /**
+ * Get the description of the widget.
+ *
+ * @return Description of this widget.
+ */
+ public function getDescription():String {
+ return this._description;
+ }
+
+ /**
+ * Get the location of a logo for this widget.
+ *
+ * @return URL pointing to a picture for this widget.
+ */
+ public function getIconUrl():String {
+ return this._icon_url;
+ }
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstance.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstance.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstance.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstance.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,152 @@
+/*
+ * 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 instance of a widget for use on the client.
+ *
+ * @refactor this class duplicates code in the widget bean on the server side
+ */
+ public class WidgetInstance {
+ /**
+ * URL pointing to the widget instance on the server side for this widget instance.
+ */
+ private var _url:String;
+ /**
+ * The unique identifier of the widget instance on the server side.
+ */
+ private var _id:String;
+ /**
+ * Title of the widget instance on the server side.
+ */
+ private var _title:String;
+ /**
+ * Height of the widget instance on the server side.
+ */
+ private var _height:String;
+ /**
+ * Width of the widget instance on the server side.
+ */
+ private var _width:String;
+
+ /**
+ * Create a new client representation of a widget instance.
+ *
+ * @param url URL pointing to the widget instance on the server side.
+ * @param id The unique identifier of the widget instance on the server side.
+ * @param title Title of the widget instance on the server side.
+ * @param height Height of the widget instance on the server side.
+ * @param width Width of the widget instance on the server side.
+ */
+ public function WidgetInstance(url:String, id:String, title:String, height:String, width:String) {
+ setId(id);
+ setUrl(url);
+ setTitle(title);
+ setHeight(height);
+ setWidth(width);
+ }
+
+ /**
+ * Get URL of this widget instance.
+ *
+ * @return URL of this widget instance.
+ */
+ public function getUrl():String {
+ return this._url;
+ }
+
+ /**
+ * Set a new URL for this widget instance.
+ *
+ * @param new_url URL pointing to a widget instance to assign to this widget instance.
+ */
+ public function setUrl(new_url:String):void {
+ this._url = new_url;
+ }
+
+ /**
+ * Get the unique identifier of this widget instance.
+ *
+ * @return The unique identifier of this widget instance.
+ */
+ public function getId():String {
+ return this._id;
+ }
+
+ /**
+ * Set a new identifier for this widget instance.
+ *
+ * @param new_id Identifier to assign to this widget instance.
+ */
+ public function setId(new_id:String):void {
+ this._id = new_id;
+ }
+
+ /**
+ * Get title of this widget instance.
+ *
+ * @return Title of this widget instance.
+ */
+ public function getTitle():String {
+ return this._title;
+ }
+
+ /**
+ * Set a new title for this widget instance.
+ *
+ * @param new_title Title to assign to this widget instance.
+ */
+ public function setTitle(new_title:String):void {
+ this._title = new_title;
+ }
+
+ /**
+ * Get height of this widget instance.
+ *
+ * @return Height of this widget instance.
+ */
+ public function getHeight():String {
+ return this._height;
+ }
+
+ /**
+ * Set a new height for this widget instance.
+ *
+ * @param new_height Height to assign to this widget instance.
+ */
+ public function setHeight(new_height:String):void {
+ this._height = new_height;
+ }
+
+ /**
+ * Get width of this widget instance.
+ *
+ * @return Width of this widget instance.
+ */
+ public function getWidth():String {
+ return this._width;
+ }
+
+ /**
+ * Set a new width for this widget instance.
+ *
+ * @param new_width Width to assign to this widget instance.
+ */
+ public function setWidth(new_width:String):void {
+ this._width = new_width;
+ }
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstanceLoader.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstanceLoader.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstanceLoader.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstanceLoader.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,98 @@
+/*
+ * 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 flash.events.ErrorEvent;
+ import flash.events.Event;
+ import flash.net.URLLoader;
+ import flash.net.URLRequest;
+
+ /**
+ * Load a widget instance given an url request and a widget identifier.
+ * This works like URLLoader excepting that it provides a WidgetInstance
+ * object in the field data or assign it null and dispatch an ErrorEvent.
+ */
+ public class WidgetInstanceLoader extends URLLoader {
+ /**
+ * Identifier of the widget that will be loaded.
+ */
+ private var _widget_id:String;
+
+ /**
+ * Create a WidgetInstance object from the received XML data and
+ * the widget identifier store in this widget instance loader.
+ * Dispatch an ErrorEvent of type ErrorEvent.ERROR, if it can't
+ * retrieve data from the XML.
+ *
+ * @param event Event containing XML data describing a widget instance.
+ */
+ private function _buildWidgetInstanceHandler(event:Event):void {
+ var widgetInstancesLoader:URLLoader = URLLoader(event.target);
+ if (event.target == this) {
+ try {
+ var xmlWidgetInstance:XML = XML(widgetInstancesLoader.data.toString());
+ var wdgtInstUrl:String = xmlWidgetInstance.url;
+ var wdgtInstTitle:String = xmlWidgetInstance.title;
+ var wdgtInstHeight:String = xmlWidgetInstance.height;
+ var wdgtInstWidth:String = xmlWidgetInstance.width;
+ var widgetInstance:WidgetInstance = new WidgetInstance(wdgtInstUrl, this._widget_id, wdgtInstTitle, wdgtInstHeight, wdgtInstWidth);
+ this.data = widgetInstance;
+ } catch(err:Error) {
+ this.data = null;
+ event.preventDefault();
+ event.stopPropagation();
+ this.dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, true, true, "Unable to create a WidgetInstanec object from XML."));
+ }
+ }
+ }
+
+ /**
+ * Create a new loader to download a client representation of a widget instance.
+ *
+ * @param widget_id Identifier of the widget to load.
+ * @param request URL request returning a widget instance under a XML format.
+ */
+ public function WidgetInstanceLoader(widget_id:String = null, request:URLRequest = null) {
+ // initialise fields
+ super(null);
+ setWidgetId(widget_id);
+ // initialise event handler
+ super.addEventListener(Event.COMPLETE, _buildWidgetInstanceHandler, false, int.MAX_VALUE);
+ // maintain URLLoader constructor behavior
+ if (null != request) {
+ this.load(request);
+ }
+ }
+
+ /**
+ * Get the identifier of the widget to load.
+ *
+ * @return The identifier of the widget to load.
+ */
+ public function getWidgetId():String {
+ return this._widget_id;
+ }
+
+ /**
+ * Set a new identifier for the widget to load.
+ *
+ * @param new_widget_id The identifier to associated with the widget to load.
+ */
+ public function setWidgetId(new_widget_id:String):void {
+ this._widget_id = new_widget_id;
+ }
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstancePropertyType.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstancePropertyType.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstancePropertyType.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstancePropertyType.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,77 @@
+/*
+ * 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
+{
+ /**
+ * The WidgetInstanceproperty_type class provides values to specify
+ * access of a property associated to a WidgetInstance.
+ * These values are read-only.
+ */
+ public class WidgetInstancePropertyType {
+ /**
+ * String specifing a public property access.
+ */
+ private static var _PUBLIC:String = "setpublicproperty";
+ /**
+ * String specifing a private property access.
+ */
+ private static var _PRIVATE:String = "setprivateproperty";
+ /**
+ * String specifing a personal property access.
+ */
+ private static var _PERSONAL:String = "setpersonalproperty";
+
+ /**
+ * Specifies that the property will be public.
+ *
+ * @return String specifing a public property access.
+ */
+ public static function get PUBLIC():String {
+ return _PUBLIC;
+ }
+
+ /**
+ * Specifies that the property will be private.
+ *
+ * @return String specifing a private property access.
+ */
+ public static function get PRIVATE():String {
+ return _PRIVATE;
+ }
+
+ /**
+ * Specifies that the property will be personal.
+ *
+ * @return String specifing a personal property access.
+ */
+ public static function get PERSONAL():String {
+ return _PERSONAL;
+ }
+
+ /**
+ * Get an array of available property accesses.
+ *
+ * @return Array of available property accesses.
+ */
+ public static function get ALL():Array {
+ var allTypes:Array = new Array();
+ allTypes.push(_PUBLIC);
+ allTypes.push(_PRIVATE);
+ allTypes.push(_PERSONAL);
+ return allTypes;
+ }
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstances.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstances.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstances.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WidgetInstances.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,71 @@
+/*
+ * 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 mx.collections.ArrayCollection;
+
+ /**
+ * A collection of known widget instances.
+ */
+ public class WidgetInstances extends ArrayCollection {
+
+ /**
+ * Record an instance of the given widget instance.
+ *
+ * @param xml description of the instance as returned by the widget server when the widget was instantiated.
+ * @return the identifier for this instance
+ */
+ public function addInstance(instance:WidgetInstance):void {
+ super.addItem({id:instance.getId(), obj:instance});
+ }
+
+ /**
+ * Replace widgets instance sharing the same identifier
+ * or add an instance, if none has been found.
+ *
+ * @param instance The widget instance to put in this container.
+ */
+ public function replaceOrAddInstance(instance:WidgetInstance):void {
+ var has_been_changed:Boolean = false;
+ for (var avl_wdgt_idx:Object in super.source) {
+ if (super.source[avl_wdgt_idx].id == instance.getId()) {
+ super.source[avl_wdgt_idx].obj = instance;
+ has_been_changed = true;
+ }
+ }
+ if(!has_been_changed) {
+ super.addItem({id:instance.getId(), obj:instance});
+ }
+ }
+
+ /**
+ * Get an instance according to its identifier or null.
+ *
+ * @param id Identifier of the widget instance to return.
+ * @return First widget instance identified with id or null,
+ * if nothing has been found.
+ */
+ public function getInstance(id:String):WidgetInstance {
+ for (var avl_wdgt:Object in super.source) {
+ if (avl_wdgt.id == id) {
+ return avl_wdgt.obj;
+ }
+ }
+ return null;
+ }
+
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorException.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorException.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorException.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorException.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,35 @@
+/*
+ * 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 Error {
+
+ /**
+ * Create a new WookieConnectorException object.
+ *
+ * @param message String associated with the Error object; this parameter is optional.
+ * @param id Reference number to associate with the specific error message.
+ */
+ public function WookieConnectorException(message:* = "", id:* = 0) {
+ super(message, id);
+ }
+
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorService.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorService.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorService.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieConnectorService.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,370 @@
+/*
+ * 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 flash.events.Event;
+ import flash.net.URLLoader;
+ import flash.net.URLLoaderDataFormat;
+ import flash.net.URLRequest;
+ import flash.net.URLRequestMethod;
+ import flash.net.URLVariables;
+ import flash.utils.Dictionary;
+
+ import mx.collections.ArrayCollection;
+
+ /**
+ * Implementation of the interface IWookieConnectorService.
+ */
+ public class WookieConnectorService implements IWookieConnectorService {
+ private var conn:WookieServerConnection;
+ private var instances:WidgetInstances;
+
+ /**
+ * Create a new WookieConnectorService object.
+ *
+ * @param conn Connection data to a wookie server are otional.
+ */
+ public function WookieConnectorService(conn:WookieServerConnection=null) {
+ setConnection(conn);
+ this.instances = new WidgetInstances();
+ }
+
+ /**
+ * Setup the connection to the Wookie service. This must be called before any
+ * other method.
+ *
+ * @param conn A connection to the Wookie server
+ * @throws WookieConnectorException
+ * if there is a problem setting up the connection
+ */
+ public function setConnection(conn:WookieServerConnection):void {
+ this.conn = conn;
+ }
+
+ /**
+ * Get the currently active connection to the Wookie server.
+ *
+ * @return WookieServerConnection
+ */
+ public function getConnection():WookieServerConnection {
+ return conn;
+ }
+
+ /**
+ * Set a property for a widget instance provided in parameters.
+ *
+ * @param instance Widget instance receiving a property.
+ * @param f_name Name of the property to assign to the widget instance.
+ * @param f_value Value of the property to assign to the widget instance.
+ * @param property_type Type of the property to assign to the widget instance.
+ * This parameter is optional. It accepts values available in WidgetInstancePropertyType.
+ * @return The loader that set a new property. This allows to check operation results by listening to its events.
+ * @throws WookieConnectorException
+ */
+ public function setPropertyForInstance(instance:WidgetInstance, f_name:String, f_value:String, property_type:String = null):URLLoader {
+ // set a default parameter value for property_type, if there is not already one.
+ // this workaround has been requiered, as WidgetInstancePropertyType.PUBLIC is a get function
+ // and functions are not allowed as default parameter value
+ if (null == property_type) {
+ property_type = WidgetInstancePropertyType.PUBLIC;
+ }
+
+ // check value of the property_type parameter
+ var is_valid_property_type:Boolean = false;
+ for each(var valid_property_type:String in WidgetInstancePropertyType.ALL) {
+ if (valid_property_type == property_type) {
+ is_valid_property_type = true;
+ }
+ }
+ if (false == is_valid_property_type) {
+ throw new Error() // TODO complete and enhance
+ }
+
+ // compute the request and its parameters
+ var query_string:URLVariables = new URLVariables();
+ query_string.requestid = property_type;
+ query_string.api_key = getConnection().getApiKey();
+ query_string.shareddatakey = getConnection().getSharedDataKey();
+ query_string.userid = getCurrentUser().getLoginName();
+ query_string.widgetid = instance.getId();
+ query_string.propertyname = f_name;
+ query_string.propertyvalue = f_value;
+
+ var widget_service_servlet_url:String = conn.getURL().concat("/WidgetServiceServlet");
+ var widget_service_servlet_request:URLRequest = new URLRequest(widget_service_servlet_url);
+
+ widget_service_servlet_request.method = URLRequestMethod.GET;
+ widget_service_servlet_request.data = query_string;
+
+ // get the response corresponding to the computed request
+ var widget_service_servlet_loader:URLLoader = new URLLoader();
+ try {
+ widget_service_servlet_loader.load(widget_service_servlet_request);
+ } catch(error:Error) {
+ throw new WookieConnectorException(); // TODO complete
+ }
+
+ // return the loader so that user can catch events
+ return widget_service_servlet_loader;
+ }
+
+ /**
+ * Get or create an instance of a widget. The current user will be added as a participant.
+ *
+ * @param widget Data for widget to be instanciated. Only the id is useful.
+ * @return The widget instance corresponding to the parameter widget.
+ * @throws IOError
+ * @throws SimalRepositoryException
+ * @throws WookieConnectorException
+ */
+ public function getOrCreateInstance(widget:Widget):WidgetInstanceLoader {
+ return this.getOrCreateInstanceWithId(widget.getIdentifier());
+ }
+
+ /**
+ * Get or create an instance of a widget. The current user will be added as a participant.
+ *
+ * @param guid Global unique identifier for widget to be instantiated
+ * @return The widget instance corresponding to the parameter guid.
+ * @throws IOError
+ * @throws SimalRepositoryException
+ * @throws WookieConnectorException
+ */
+ public function getOrCreateInstanceWithId(guid:String):WidgetInstanceLoader {
+ // compute the request and its parameters
+ var postData:URLVariables = new URLVariables();
+ // TODO check if escape is requiered or implicite
+ postData.api_key = getConnection().getApiKey();
+ postData.shareddatakey = getConnection().getSharedDataKey();
+ postData.userid = getCurrentUser().getLoginName();
+ postData.widgetid = guid;
+
+ var widgetInstancesUrl:String = conn.getURL().concat("/widgetinstances");
+ var widgetInstancesRequest:URLRequest = new URLRequest(widgetInstancesUrl);
+
+ widgetInstancesRequest.method = URLRequestMethod.POST;
+ widgetInstancesRequest.data = postData;
+
+ // initialise the loader to process the response and load the computed request
+ var widgetInstancesLoader:WidgetInstanceLoader = new WidgetInstanceLoader(guid);
+ widgetInstancesLoader.addEventListener(Event.COMPLETE, _getOrCreateWidgetInstanceHandler, false, int.MAX_VALUE);
+ widgetInstancesLoader.dataFormat = URLLoaderDataFormat.TEXT;
+ try {
+ widgetInstancesLoader.load(widgetInstancesRequest);
+ } catch (err:Error) {
+ throw new WookieConnectorException(); // TODO complete
+ }
+
+ // return the loader so that user can catch events
+ return widgetInstancesLoader;
+ }
+
+ /**
+ * Add the current user as participant to a new created widget instance
+ * after having saved this instance.
+ *
+ * @param event Event containing the new widget instance.
+ */
+ private function _getOrCreateWidgetInstanceHandler(event:Event):void {
+ var widgetInstancesLoader:WidgetInstanceLoader = WidgetInstanceLoader(event.target);
+ var widgetInstance:WidgetInstance = WidgetInstance(widgetInstancesLoader.data);
+ this.instances.replaceOrAddInstance(widgetInstance);
+ this.addParticipant(widgetInstance, this.getCurrentUser());
+ }
+
+ /**
+ * Add a participant to a widget.
+ *
+ * @param instance The WidgetInstance to add the participant to.
+ * @param user The user to add as a participant.
+ *
+ * @throws WookieConnectorexception
+ */
+ public function addParticipant(widget:WidgetInstance, user:User):URLLoader {
+ // compute the request and its parameters
+ var postData:URLVariables = new URLVariables();
+ // TODO check if escape is requiered or implicite
+ postData.api_key = getConnection().getApiKey();
+ postData.shareddatakey = getConnection().getSharedDataKey();
+ postData.userid = getCurrentUser().getLoginName();
+ postData.widgetid = widget.getId();
+ postData.participant_id = user.getLoginName();
+ postData.participant_display_name = user.getScreenName();
+ postData.participant_thumbnail_url = user.getThumbnailUrl();
+
+ var participantsUrl:String = conn.getURL().concat("/participants");
+ var participantsRequest:URLRequest = new URLRequest(participantsUrl);
+
+ // TODO participantsRequest.method = URLRequestMethod.POST;
+ participantsRequest.method = URLRequestMethod.GET;
+ participantsRequest.data = postData;
+
+ // get the response corresponding to the computed request
+ var participantsLoader:URLLoader = new URLLoader();
+ try {
+ participantsLoader.load(participantsRequest);
+ // TODO what do we have to do if it returns a wrong http status ?
+ } catch (err:Error) {
+ throw new WookieConnectorException(); // TODO complete
+ }
+
+ // return the loader so that user can catch events
+ return participantsLoader;
+ }
+
+ /**
+ * 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 The loader that requested available widgets. This allows to
+ * gather available widgets in an asynchronous manner.
+ * @throws SimalException
+ * @throws WookieConnectorException
+ */
+ public function getAvailableWidgets():URLLoader {
+ // compute the request and its parameters
+ var availableWidgetsUrl:String = conn.getURL().concat("/widgets?all=true");
+ var availableWidgetsRequest:URLRequest = new URLRequest(availableWidgetsUrl);
+
+ // initialise the loader to process the response and load the computed request
+ var availableWidgetsLoader:URLLoader = new URLLoader();
+ availableWidgetsLoader.addEventListener(Event.COMPLETE, _getAvailableWidgetsHandler, false, int.MAX_VALUE);
+ try {
+ availableWidgetsLoader.load(availableWidgetsRequest);
+ } catch (err:Error) {
+ throw new WookieConnectorException(); // TODO complete
+ }
+
+ // return the loader so that user can catch events
+ return availableWidgetsLoader;
+ }
+
+ /**
+ * Extract data about available widgets as Widget objects.
+ *
+ * @param event Listing of available widgets as an XML file.
+ * @throws WookieConnectorException if there is a syntax error in the XML content.
+ */
+ private function _getAvailableWidgetsHandler(event:Event):void {
+ try {
+ var avlWidgets:Dictionary = new Dictionary();
+
+ var availableWidgetsLoader:URLLoader = URLLoader(event.target);
+ var xmlAvailableWidgets:XML = XML(availableWidgetsLoader.data);
+ for each(var avlWidgetEl:XML in xmlAvailableWidgets.widget) {
+ var avlWidgetId:String = avlWidgetEl.@identifier;
+ if (null == avlWidgets[avlWidgetId]) {
+ var avlWidgetTitle:String = avlWidgetEl.title;
+ var avlWidgetDesc:String = avlWidgetEl.description;
+ var avlWidgetIco:String = avlWidgetEl.icon;
+ var avlWidget:Widget = new Widget(avlWidgetId, avlWidgetTitle, avlWidgetDesc, avlWidgetIco);
+ avlWidgets[avlWidgetId] = avlWidget;
+ }
+ }
+ availableWidgetsLoader.data = avlWidgets;
+ } catch(err:Error) {
+ throw new WookieConnectorException(); // TODO complete and enhance
+ }
+ }
+
+ /**
+ * Get all the instances of widgets that are currently managed by this service.
+ *
+ * @return Instances of widgets managed by this service.
+ */
+ public function getInstances():WidgetInstances {
+ return this.instances;
+ }
+
+ /***************************************************************************************************/
+ /* user management functions */
+ /* this part should be enhanced */
+ /***************************************************************************************************/
+ private var users:Array;
+ private var currentUser:User;
+ private var userLogin:String;
+
+ /**
+ * Retrieve the details of a specific user, identified with their user_id.
+ * Return null if no user is identified with user_id.
+ *
+ * @return Data of the user identified with user_id or null.
+ */
+ public function getUser(user_id:String):User {
+ for each(var user:User in users) {
+ if (user.getLoginName() == user_id) {
+ return user;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * [Deprecated]
+ * @deprecated
+ */
+ public function setUsers(new_users:Array):void {
+ users = new_users;
+ }
+
+ /**
+ * [Deprecated]
+ * @deprecated
+ */
+ public function getUsers():Array {
+ return users;
+ }
+
+ /**
+ * Retrieve the details of the current user.
+ *
+ * @return Data of the current user.
+ */
+ public function getCurrentUser():User {
+ return this.currentUser;
+ }
+
+ /**
+ * Set the current user with the user passed as parameter.
+ *
+ * @param user The next current user.
+ */
+ public function setCurrentUser(user:User):void {
+ this.currentUser = user;
+ }
+
+ /**
+ * Retrieve the user identified with the parameter user_id
+ * and set it as the current user.
+ *
+ * @param user_id Id of the next current user. Usually this would be the login
+ * name of the user, but it need not be, it simply needs to be a unique identifier
+ * among all users.
+ * @throws WookieConnectorException if no user is identified with user_id.
+ */
+ public function setCurrentUserWithId(userId:String):void {
+ var user:User = this.getUser(userId);
+ if(null != user) {
+ setCurrentUser(user);
+ } else {
+ throw new WookieConnectorException() // TODO complete enhance
+ }
+ }
+
+ }
+
+}
Added: incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieServerConnection.as
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieServerConnection.as?rev=954915&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieServerConnection.as (added)
+++ incubator/wookie/trunk/connector/flash_flex/org/apache/wookie/connector/framework/WookieServerConnection.as Tue Jun 15 14:41:00 2010
@@ -0,0 +1,127 @@
+/*
+ * 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 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 {
+ /**
+ * URL pointing to wookie server or servlet for this connection.
+ */
+ private var _url:String;
+ /**
+ * API Key of the wookie server or servlet for this connection.
+ */
+ private var _api_key:String;
+ /**
+ * Shared data key for this connection.
+ */
+ private var _shared_data_key:String;
+
+ /**
+ * Create a connection to a Wookie server at a given URL.
+ * Each parameter is mandatory.
+ *
+ * @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 function WookieServerConnection(url:String, api_key:String, shared_data_key:String) {
+ setURL(url);
+ setApiKey(api_key);
+ setSharedDataKey(shared_data_key);
+ }
+
+ /**
+ * Get the URL of the wookie server.
+ *
+ * @return URL of the wookie server.
+ */
+ public function getURL():String {
+ return this._url;
+ }
+
+ /**
+ * Set the URL of the wookie server.
+ * No check on URL validity and URL syntax.
+ *
+ * @param new_url URL to assign to this connection.
+ */
+ public function setURL(new_url:String):void {
+ var lastCharIdx:Number = new_url.length - 1;
+ // force the new url to end in "/"
+ if (0 < lastCharIdx) {
+ if ("/" == new_url.charAt(lastCharIdx)) {
+ new_url = new_url.slice(0, lastCharIdx);
+ }
+ }
+ this._url = new_url;
+ }
+
+ /**
+ * Get the API key for this server.
+ *
+ * @return API key for this server.
+ */
+ public function getApiKey():String {
+ return this._api_key;
+ }
+
+ /**
+ * Set the API key for this server.
+ *
+ * @param new_api_key API key to assign to this server.
+ */
+ public function setApiKey(new_api_key:String):void {
+ this._api_key = new_api_key;
+ }
+
+ /**
+ * Get the shared data key for this server.
+ *
+ * @return Shared data key for this server.
+ */
+ public function getSharedDataKey():String {
+ return this._shared_data_key;
+ }
+
+ /**
+ * Set the shared data key for this server.
+ *
+ * @param new_key Shared data key to assign to this server.
+ */
+ public function setSharedDataKey(new_key:String):void {
+ this._shared_data_key = new_key;
+ }
+
+ /**
+ * Get a string containing values of this connection.
+ *
+ * @return String containing values of this connection.
+ */
+ public function toString():String {
+ var toStringResult:String = new String("Wookie Server Connection - ");
+ toStringResult += "URL: " + this.getURL();
+ toStringResult += "API Key: " + this.getApiKey();
+ toStringResult += "Shared Data Key: " + this.getSharedDataKey();
+ return toStringResult;
+ }
+ }
+
+}