summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-08 02:49:34 (EDT)
committerEike Stepper2007-10-08 02:49:34 (EDT)
commit7a2888fab87764de49535f07f13b00eb24a45829 (patch)
treed27643b40ffe86e51789b4de3b719d0f111aab1a
parentb9e31e4f77d5998be79fe0a775e6d928fca8b4c6 (diff)
downloadcdo-7a2888fab87764de49535f07f13b00eb24a45829.zip
cdo-7a2888fab87764de49535f07f13b00eb24a45829.tar.gz
cdo-7a2888fab87764de49535f07f13b00eb24a45829.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/LoadAccountIndication.java52
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java11
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java18
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/LoadAccountRequest.java53
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java24
5 files changed, 127 insertions, 31 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/LoadAccountIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/LoadAccountIndication.java
new file mode 100644
index 0000000..a9f7ed3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/LoadAccountIndication.java
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.server.protocol;
+
+import org.eclipse.net4j.buddies.protocol.AccountUtil;
+import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
+import org.eclipse.net4j.buddies.server.IBuddyAdmin;
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class LoadAccountIndication extends IndicationWithResponse
+{
+ private IBuddyAccount account;
+
+ public LoadAccountIndication()
+ {
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return BuddiesProtocolConstants.SIGNAL_LOAD_ACCOUNT;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ String userID = in.readString();
+ account = IBuddyAdmin.INSTANCE.getAccounts().get(userID);
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws IOException
+ {
+ AccountUtil.writeAccount(out, account);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
index 8f5d5e4..9b08043 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.server.bundle.OM;
+import org.eclipse.net4j.buddies.protocol.AccountUtil;
import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
@@ -21,7 +22,6 @@ import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import java.io.IOException;
-import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -71,9 +71,9 @@ public class OpenSessionIndication extends IndicationWithResponse
@Override
protected void responding(ExtendedDataOutputStream out) throws IOException
{
+ AccountUtil.writeAccount(out, account);
if (account != null)
{
- out.writeBoolean(true);
List<IChannel> channels = new ArrayList<IChannel>();
out.writeInt(buddies.length);
for (String buddy : buddies)
@@ -86,9 +86,6 @@ public class OpenSessionIndication extends IndicationWithResponse
}
}
- ObjectOutputStream oos = new ObjectOutputStream(out);
- oos.writeObject(account);
-
for (IChannel channel : channels)
{
try
@@ -101,9 +98,5 @@ public class OpenSessionIndication extends IndicationWithResponse
}
}
}
- else
- {
- out.writeBoolean(false);
- }
}
}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
index d666d26..855cdb8 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.buddies.internal.ui.views;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.ui.actions.LongRunningAction;
@@ -36,10 +37,23 @@ public class BuddiesItemProvider extends ContainerItemProvider<IContainer<Object
}
@Override
+ public String getText(Object obj)
+ {
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ return buddy.getUserID();
+ }
+
+ return super.getText(obj);
+ }
+
+ @Override
public Image getImage(Object obj)
{
- if (obj instanceof String)
+ if (obj instanceof IBuddy)
{
+ IBuddy buddy = (IBuddy)obj;
// return SharedIcons.getImage(SharedIcons.OBJ_ACCEPTOR);
}
@@ -52,7 +66,7 @@ public class BuddiesItemProvider extends ContainerItemProvider<IContainer<Object
if (selection.size() == 1)
{
Object obj = selection.getFirstElement();
- if (obj instanceof String)
+ if (obj instanceof IBuddy)
{
manager.add(new RemoveAction(obj));
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/LoadAccountRequest.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/LoadAccountRequest.java
new file mode 100644
index 0000000..8d00b13
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/LoadAccountRequest.java
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.buddies.protocol;
+
+import org.eclipse.net4j.IChannel;
+import org.eclipse.net4j.buddies.protocol.AccountUtil;
+import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class LoadAccountRequest extends RequestWithConfirmation<IBuddyAccount>
+{
+ private String userID;
+
+ public LoadAccountRequest(IChannel channel, String userID)
+ {
+ super(channel);
+ this.userID = userID;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return BuddiesProtocolConstants.SIGNAL_LOAD_ACCOUNT;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeString(userID);
+ }
+
+ @Override
+ protected IBuddyAccount confirming(ExtendedDataInputStream in) throws IOException
+ {
+ return AccountUtil.readAccount(in);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
index 980a102..8070b4b 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
@@ -12,17 +12,16 @@ package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.protocol.AccountUtil;
import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
import org.eclipse.net4j.internal.buddies.BuddySession;
import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import java.io.IOException;
-import java.io.ObjectInputStream;
/**
* @author Eike Stepper
@@ -56,14 +55,15 @@ public class OpenSessionRequest extends RequestWithConfirmation<IBuddySession>
@Override
protected IBuddySession confirming(ExtendedDataInputStream in) throws IOException
{
- boolean granted = in.readBoolean();
- if (!granted)
+ IBuddyAccount account = AccountUtil.readAccount(in);
+ if (account == null)
{
return null;
}
BuddySession session = new BuddySession(getProtocol().getChannel());
getProtocol().setInfraStructure(session);
+ session.setSelf(account);
int size = in.readInt();
for (int i = 0; i < size; i++)
@@ -71,22 +71,6 @@ public class OpenSessionRequest extends RequestWithConfirmation<IBuddySession>
session.addBuddy(in.readString());
}
- IBuddyAccount account;
- ObjectInputStream ois = new ObjectInputStream(in);
- try
- {
- account = (IBuddyAccount)ois.readObject();
- }
- catch (IOException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- session.setSelf(account);
LifecycleUtil.activate(session);
return session;
}