Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j')
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IAccount.java31
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddy.java50
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyContainer.java20
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyProvider.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyStateEvent.java25
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaboration.java44
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationContainer.java20
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationProvider.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacility.java29
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacilityInstalledEvent.java25
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembership.java23
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipContainer.java20
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipKey.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipProvider.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessage.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessageEvent.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISession.java28
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISessionProvider.java23
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Account.java79
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Buddy.java220
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/BuddyContainer.java143
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Collaboration.java288
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/CollaborationContainer.java141
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Membership.java118
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipContainer.java121
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipKey.java72
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MessageEvent.java37
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/bundle/OM.java50
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateIndication.java43
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateNotification.java48
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftIndication.java75
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftNotification.java47
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageIndication.java63
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageNotification.java52
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolConstants.java55
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolUtil.java225
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ClientFacilityFactory.java26
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Facility.java66
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Message.java52
-rw-r--r--plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ServerFacilityFactory.java26
40 files changed, 2511 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IAccount.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IAccount.java
new file mode 100644
index 0000000000..c276a28041
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IAccount.java
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IAccount
+{
+ public String getUserID();
+
+ public void setPassword(String password);
+
+ public boolean authenticate(String password);
+
+ public Map<String, String> getProperties();
+
+ public void touch();
+
+ public long getTimeStamp();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddy.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddy.java
new file mode 100644
index 0000000000..63a29dcf68
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddy.java
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IBuddy extends IMembershipContainer, ICollaborationProvider, IAdaptable
+{
+ public String getUserID();
+
+ public State getState();
+
+ public IAccount getAccount();
+
+ public ISession getSession();
+
+ public Set<String> getFacilityTypes();
+
+ public IMembership initiate();
+
+ public IMembership initiate(IBuddy buddy);
+
+ public IMembership[] initiate(Collection<IBuddy> buddies);
+
+ public IMembership join(long collaborationID);
+
+ public IMembership join(Object invitationToken);
+
+ /**
+ * @author Eike Stepper
+ */
+ public enum State
+ {
+ AVAILABLE, LONESOME, AWAY, DO_NOT_DISTURB
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyContainer.java
new file mode 100644
index 0000000000..6a4a9210e7
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyContainer.java
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IBuddyContainer extends IBuddyProvider, IContainer<IBuddy>
+{
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyProvider.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyProvider.java
new file mode 100644
index 0000000000..44468151f8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyProvider.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IBuddyProvider
+{
+ public IBuddy[] getBuddies();
+
+ public IBuddy getBuddy(String userID);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyStateEvent.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyStateEvent.java
new file mode 100644
index 0000000000..684ffc8197
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IBuddyStateEvent.java
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IBuddyStateEvent extends IEvent
+{
+ public IBuddy getBuddy();
+
+ public IBuddy.State getOldState();
+
+ public IBuddy.State getNewState();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaboration.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaboration.java
new file mode 100644
index 0000000000..e545d74358
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaboration.java
@@ -0,0 +1,44 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ICollaboration extends IMembershipContainer, IBuddyProvider, IAdaptable
+{
+ public long getID();
+
+ public String getTitle();
+
+ public String getDescription();
+
+ public Visibility getVisibility();
+
+ public boolean isPublic();
+
+ public void setPublic(String title, String description);
+
+ public void setPrivate();
+
+ public String[] getFacilityTypes();
+
+ public IFacility[] getFacilities();
+
+ public IFacility getFacility(String type);
+
+ public enum Visibility
+ {
+ PRIVATE, PUBLIC
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationContainer.java
new file mode 100644
index 0000000000..f9056bf04d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationContainer.java
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ICollaborationContainer extends ICollaborationProvider, IContainer<ICollaboration>
+{
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationProvider.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationProvider.java
new file mode 100644
index 0000000000..897cddd7a7
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ICollaborationProvider.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ICollaborationProvider
+{
+ public ICollaboration[] getCollaborations();
+
+ public ICollaboration getCollaboration(long id);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacility.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacility.java
new file mode 100644
index 0000000000..7c5731d6ef
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacility.java
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.event.INotifier;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IFacility extends INotifier, IAdaptable
+{
+ public String getType();
+
+ public ICollaboration getCollaboration();
+
+ public void setCollaboration(ICollaboration collaboration);
+
+ public void sendMessage(IMessage message);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacilityInstalledEvent.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacilityInstalledEvent.java
new file mode 100644
index 0000000000..2ca2d3d16a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IFacilityInstalledEvent.java
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IFacilityInstalledEvent extends IEvent
+{
+ public ICollaboration getCollaboration();
+
+ public IFacility getFacility();
+
+ public boolean fromRemote();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembership.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembership.java
new file mode 100644
index 0000000000..c6748d5719
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembership.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMembership extends IMembershipKey, IContainer<Object>, IAdaptable
+{
+ public long getStartTime();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipContainer.java
new file mode 100644
index 0000000000..8a9ff1f581
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipContainer.java
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMembershipContainer extends IMembershipProvider, IContainer<IMembership>
+{
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipKey.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipKey.java
new file mode 100644
index 0000000000..c7da597065
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipKey.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMembershipKey
+{
+ public IBuddy getBuddy();
+
+ public ICollaboration getCollaboration();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipProvider.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipProvider.java
new file mode 100644
index 0000000000..3c20dcedc6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMembershipProvider.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMembershipProvider
+{
+ public IMembership[] getMemberships();
+
+ public IMembership getMembership(IBuddy buddy, ICollaboration collaboration);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessage.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessage.java
new file mode 100644
index 0000000000..7b45c06378
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessage.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMessage extends IAdaptable
+{
+ public String getSenderID();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessageEvent.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessageEvent.java
new file mode 100644
index 0000000000..d488bb5aa1
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/IMessageEvent.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IMessageEvent extends IEvent
+{
+ public IMessage getMessage();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISession.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISession.java
new file mode 100644
index 0000000000..05673f3a95
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISession.java
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.util.event.INotifier;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ISession extends INotifier, IAdaptable
+{
+ public IChannel getChannel();
+
+ public IBuddy getSelf();
+
+ public void close();
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISessionProvider.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISessionProvider.java
new file mode 100644
index 0000000000..310771465f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/common/ISessionProvider.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ISessionProvider
+{
+ public ISession[] getSessions();
+
+ public ISession getSession(String userID);
+
+ public ISession getSession(IBuddy buddy);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Account.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Account.java
new file mode 100644
index 0000000000..78588c9dee
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Account.java
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IAccount;
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class Account implements IAccount, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String userID;
+
+ private transient String password;
+
+ private Map<String, String> properties = new HashMap<String, String>();
+
+ private long timeStamp;
+
+ protected Account()
+ {
+ }
+
+ public Account(String userID, String password)
+ {
+ this.userID = userID;
+ this.password = password;
+ }
+
+ public String getUserID()
+ {
+ return userID;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public boolean authenticate(String password)
+ {
+ return ObjectUtil.equals(password, this.password);
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+ public void touch()
+ {
+ timeStamp = System.currentTimeMillis();
+ }
+
+ public long getTimeStamp()
+ {
+ return timeStamp;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Buddy.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Buddy.java
new file mode 100644
index 0000000000..95f6b09b5a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Buddy.java
@@ -0,0 +1,220 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.IBuddyStateEvent;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.common.ISession;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.event.IEvent;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Buddy extends MembershipContainer implements IBuddy
+{
+ private ISession session;
+
+ private State state = State.AVAILABLE;
+
+ private Set<String> facilityTypes;
+
+ public Buddy(ISession session, Set<String> facilityTypes)
+ {
+ this.session = session;
+ this.facilityTypes = facilityTypes == null ? null : Collections.unmodifiableSet(facilityTypes);
+ }
+
+ public ISession getSession()
+ {
+ return session;
+ }
+
+ public void setSession(ISession session)
+ {
+ this.session = session;
+ }
+
+ public State getState()
+ {
+ return state;
+ }
+
+ public void setState(State state)
+ {
+ if (this.state != state)
+ {
+ IEvent event = new BuddyStateEvent(this.state, state);
+ this.state = state;
+ fireEvent(event);
+ }
+ }
+
+ public Set<String> getFacilityTypes()
+ {
+ if (facilityTypes == null)
+ {
+ facilityTypes = Collections.unmodifiableSet(loadFacilityTypes());
+ }
+
+ return facilityTypes;
+ }
+
+ public IMembership getMembership(Collaboration collaboration)
+ {
+ return getMembership(this, collaboration);
+ }
+
+ public IMembership removeMembership(Collaboration collaboration)
+ {
+ return removeMembership(this, collaboration);
+ }
+
+ public ICollaboration getCollaboration(long collaborationID)
+ {
+ for (IMembership membership : getMemberships())
+ {
+ ICollaboration collaboration = membership.getCollaboration();
+ if (collaboration.getID() == collaborationID)
+ {
+ return collaboration;
+ }
+ }
+
+ return null;
+ }
+
+ public ICollaboration[] getCollaborations()
+ {
+ List<ICollaboration> collaborations = new ArrayList<ICollaboration>();
+ for (IMembership membership : getMemberships())
+ {
+ ICollaboration collaboration = membership.getCollaboration();
+ collaborations.add(collaboration);
+ }
+
+ return collaborations.toArray(new ICollaboration[collaborations.size()]);
+ }
+
+ public IMembership initiate()
+ {
+ return initiate((IBuddy)null);
+ }
+
+ public IMembership initiate(IBuddy buddy)
+ {
+ HashSet<IBuddy> buddies = new HashSet<IBuddy>();
+ if (buddy != null)
+ {
+ buddies.add(buddy);
+ }
+
+ IMembership[] memberships = initiate(buddies);
+ return memberships.length == 0 ? null : memberships[0];
+ }
+
+ /**
+ * @see PlatformObject#getAdapter(Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter)
+ {
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ return ObjectUtil.equals(getUserID(), buddy.getUserID());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(getUserID());
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}]", getClass().getSimpleName(), getUserID());
+ }
+
+ protected Set<String> loadFacilityTypes()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class BuddyStateEvent extends Event implements IBuddyStateEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private State oldState;
+
+ private State newState;
+
+ public BuddyStateEvent(State oldState, State newState)
+ {
+ super(Buddy.this);
+ this.oldState = oldState;
+ this.newState = newState;
+ }
+
+ public IBuddy getBuddy()
+ {
+ return Buddy.this;
+ }
+
+ public State getOldState()
+ {
+ return oldState;
+ }
+
+ public State getNewState()
+ {
+ return newState;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("BuddyStateEvent[source={0}, oldState={1}, newState={2}]", getSource(),
+ getOldState(), getNewState());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/BuddyContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/BuddyContainer.java
new file mode 100644
index 0000000000..9c550ba0f1
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/BuddyContainer.java
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.IBuddyContainer;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEvent;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddyContainer extends Lifecycle implements IBuddyContainer, IListener
+{
+ private Map<String, IBuddy> buddies = new HashMap<String, IBuddy>();
+
+ public BuddyContainer(Collection<IBuddy> buddies)
+ {
+ if (buddies != null)
+ {
+ for (IBuddy buddy : buddies)
+ {
+ this.buddies.put(buddy.getUserID(), buddy);
+ buddy.addListener(this);
+ }
+ }
+ }
+
+ public BuddyContainer()
+ {
+ }
+
+ public boolean addBuddy(IBuddy buddy)
+ {
+ String userID = buddy.getUserID();
+ synchronized (buddies)
+ {
+ if (!buddies.containsKey(userID))
+ {
+ buddies.put(userID, buddy);
+ fireEvent(new SingleDeltaContainerEvent<IBuddy>(this, buddy, IContainerDelta.Kind.ADDED));
+ buddy.addListener(this);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public IBuddy removeBuddy(String userID)
+ {
+ IBuddy buddy;
+ synchronized (buddies)
+ {
+ buddy = buddies.remove(userID);
+ }
+
+ if (buddy != null)
+ {
+ buddy.removeListener(this);
+ fireEvent(new SingleDeltaContainerEvent<IBuddy>(this, buddy, IContainerDelta.Kind.REMOVED));
+ }
+
+ return buddy;
+ }
+
+ public IBuddy[] getBuddies()
+ {
+ synchronized (buddies)
+ {
+ return buddies.values().toArray(new IBuddy[buddies.size()]);
+ }
+ }
+
+ public IBuddy getBuddy(String userID)
+ {
+ synchronized (buddies)
+ {
+ return buddies.get(userID);
+ }
+ }
+
+ public IBuddy[] getElements()
+ {
+ return getBuddies();
+ }
+
+ public boolean isEmpty()
+ {
+ synchronized (buddies)
+ {
+ return buddies.isEmpty();
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event.getSource() instanceof IBuddy)
+ {
+ notifyBuddyEvent(event);
+ if (event instanceof LifecycleEvent)
+ {
+ LifecycleEvent e = (LifecycleEvent)event;
+ if (e.getKind() == ILifecycleEvent.Kind.DEACTIVATED)
+ {
+ removeBuddy(((IBuddy)e.getSource()).getUserID());
+ }
+ }
+ }
+ }
+
+ protected void notifyBuddyEvent(IEvent event)
+ {
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (IBuddy buddy : getBuddies())
+ {
+ buddy.removeListener(this);
+ }
+
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Collaboration.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Collaboration.java
new file mode 100644
index 0000000000..4f53e4516e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Collaboration.java
@@ -0,0 +1,288 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IFacility;
+import org.eclipse.net4j.buddies.common.IFacilityInstalledEvent;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.buddies.internal.common.bundle.OM;
+import org.eclipse.net4j.buddies.internal.common.protocol.MessageNotification;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class Collaboration extends MembershipContainer implements ICollaboration
+{
+ private long id;
+
+ private String title;
+
+ private String description;
+
+ private Visibility visibility = Visibility.PRIVATE;
+
+ private ConcurrentMap<String, IFacility> facilities = new ConcurrentHashMap<String, IFacility>();
+
+ public Collaboration(long id)
+ {
+ this.id = id;
+ }
+
+ public long getID()
+ {
+ return id;
+ }
+
+ public String getTitle()
+ {
+ return title == null ? String.valueOf(id) : title;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public Visibility getVisibility()
+ {
+ return visibility;
+ }
+
+ public boolean isPublic()
+ {
+ return visibility == Visibility.PUBLIC;
+ }
+
+ public void setPublic(String title, String description)
+ {
+ visibility = Visibility.PUBLIC;
+ this.title = title;
+ this.description = description;
+ }
+
+ public void setPrivate()
+ {
+ visibility = Visibility.PRIVATE;
+ title = null;
+ description = null;
+ }
+
+ public IMembership getMembership(IBuddy buddy)
+ {
+ return getMembership(buddy, this);
+ }
+
+ public IMembership removeMembership(IBuddy buddy)
+ {
+ return removeMembership(buddy, this);
+ }
+
+ public IBuddy getBuddy(String userID)
+ {
+ for (IMembership membership : getMemberships())
+ {
+ IBuddy buddy = membership.getBuddy();
+ if (ObjectUtil.equals(buddy.getUserID(), userID))
+ {
+ return buddy;
+ }
+ }
+
+ return null;
+ }
+
+ public IBuddy[] getBuddies()
+ {
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ for (IMembership membership : getMemberships())
+ {
+ IBuddy buddy = membership.getBuddy();
+ buddies.add(buddy);
+ }
+
+ return buddies.toArray(new IBuddy[buddies.size()]);
+ }
+
+ public String[] getFacilityTypes()
+ {
+ return facilities.keySet().toArray(new String[facilities.size()]);
+ }
+
+ public IFacility[] getFacilities()
+ {
+ return facilities.values().toArray(new IFacility[facilities.size()]);
+ }
+
+ public IFacility getFacility(String type)
+ {
+ return facilities.get(type);
+ }
+
+ public boolean addFacility(IFacility facility, boolean remote)
+ {
+ String type = facility.getType();
+ if (!facilities.containsKey(type))
+ {
+ facilities.put(type, facility);
+ fireEvent(new FacilityInstalledEvent(facility, remote));
+ facility.addListener(this);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void sendMessage(long collaborationID, String facilityType, IMessage message)
+ {
+ IMembership[] elements = getElements();
+ for (IMembership membership : elements)
+ {
+ IBuddy receiver = membership.getBuddy();
+ if (!ObjectUtil.equals(receiver.getUserID(), message.getSenderID()))
+ {
+ try
+ {
+ new MessageNotification(receiver.getSession().getChannel(), collaborationID, facilityType, message).send();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ }
+
+ /**
+ * @see PlatformObject#getAdapter(Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter)
+ {
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof ICollaboration)
+ {
+ ICollaboration collaboration = (ICollaboration)obj;
+ return getID() == collaboration.getID();
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(id);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}]", getClass().getSimpleName(), getTitle());
+ }
+
+ @Override
+ public void notifyEvent(IEvent event)
+ {
+ super.notifyEvent(event);
+ if (event.getSource() instanceof IFacility)
+ {
+ notifyFacilityEvent(event);
+ }
+ }
+
+ protected void notifyFacilityEvent(IEvent event)
+ {
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (IFacility facility : getFacilities())
+ {
+ facility.removeListener(this);
+ LifecycleUtil.deactivate(facility);
+ }
+
+ for (IMembership membership : getMemberships())
+ {
+ LifecycleUtil.deactivate(membership);
+ }
+
+ super.doDeactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class FacilityInstalledEvent extends Event implements IFacilityInstalledEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private IFacility facility;
+
+ private boolean remote;
+
+ public FacilityInstalledEvent(IFacility facility, boolean remote)
+ {
+ super(Collaboration.this);
+ this.facility = facility;
+ this.remote = remote;
+ }
+
+ public ICollaboration getCollaboration()
+ {
+ return Collaboration.this;
+ }
+
+ public IFacility getFacility()
+ {
+ return facility;
+ }
+
+ public boolean fromRemote()
+ {
+ return remote;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("FacilityInstalledEvent[source={0}, facility={1}, remote={2}]", getSource(),
+ facility, remote);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/CollaborationContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/CollaborationContainer.java
new file mode 100644
index 0000000000..c78fe059da
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/CollaborationContainer.java
@@ -0,0 +1,141 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.ICollaborationContainer;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEvent;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationContainer extends Lifecycle implements ICollaborationContainer, IListener
+{
+ private Map<Long, ICollaboration> collaborations = new HashMap<Long, ICollaboration>();
+
+ public CollaborationContainer(Collection<ICollaboration> collaborations)
+ {
+ if (collaborations != null)
+ {
+ for (ICollaboration collaboration : collaborations)
+ {
+ this.collaborations.put(collaboration.getID(), collaboration);
+ collaboration.addListener(this);
+ }
+ }
+ }
+
+ public CollaborationContainer()
+ {
+ }
+
+ public void addCollaboration(ICollaboration collaboration)
+ {
+ long id = collaboration.getID();
+ synchronized (collaborations)
+ {
+ if (!collaborations.containsKey(id))
+ {
+ collaborations.put(id, collaboration);
+ }
+ }
+
+ fireEvent(new SingleDeltaContainerEvent<ICollaboration>(this, collaboration, IContainerDelta.Kind.ADDED));
+ collaboration.addListener(this);
+ }
+
+ public ICollaboration removeCollaboration(long id)
+ {
+ ICollaboration collaboration;
+ synchronized (collaborations)
+ {
+ collaboration = collaborations.remove(id);
+ }
+
+ if (collaboration != null)
+ {
+ collaboration.removeListener(this);
+ fireEvent(new SingleDeltaContainerEvent<ICollaboration>(this, collaboration, IContainerDelta.Kind.REMOVED));
+ }
+
+ return collaboration;
+ }
+
+ public ICollaboration[] getCollaborations()
+ {
+ synchronized (collaborations)
+ {
+ return collaborations.values().toArray(new ICollaboration[collaborations.size()]);
+ }
+ }
+
+ public ICollaboration getCollaboration(long id)
+ {
+ synchronized (collaborations)
+ {
+ return collaborations.get(id);
+ }
+ }
+
+ public ICollaboration[] getElements()
+ {
+ return getCollaborations();
+ }
+
+ public boolean isEmpty()
+ {
+ synchronized (collaborations)
+ {
+ return collaborations.isEmpty();
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event.getSource() instanceof ICollaboration)
+ {
+ notifyCollaborationEvent(event);
+ if (event instanceof LifecycleEvent)
+ {
+ LifecycleEvent e = (LifecycleEvent)event;
+ if (e.getKind() == ILifecycleEvent.Kind.DEACTIVATED)
+ {
+ removeCollaboration(((ICollaboration)e.getSource()).getID());
+ }
+ }
+ }
+ }
+
+ protected void notifyCollaborationEvent(IEvent event)
+ {
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (ICollaboration collaboration : getCollaborations())
+ {
+ collaboration.removeListener(this);
+ }
+
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Membership.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Membership.java
new file mode 100644
index 0000000000..6addbc2f4b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/Membership.java
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.common.IMembershipKey;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+
+/**
+ * @author Eike Stepper
+ */
+public class Membership extends Lifecycle implements IMembership
+{
+ private MembershipKey key;
+
+ private long startTime;
+
+ private transient Object[] elements;
+
+ private Membership(IBuddy buddy, ICollaboration collaboration)
+ {
+ key = new MembershipKey(buddy, collaboration);
+ elements = new Object[] { buddy, collaboration };
+ startTime = System.currentTimeMillis();
+ activate();
+ }
+
+ public IBuddy getBuddy()
+ {
+ return key.getBuddy();
+ }
+
+ public ICollaboration getCollaboration()
+ {
+ return key.getCollaboration();
+ }
+
+ public long getStartTime()
+ {
+ return startTime;
+ }
+
+ public Object[] getElements()
+ {
+ return elements;
+ }
+
+ public boolean isEmpty()
+ {
+ return false;
+ }
+
+ public MembershipKey getKey()
+ {
+ return key;
+ }
+
+ /**
+ * @see PlatformObject#getAdapter(Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter)
+ {
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof IMembershipKey)
+ {
+ IMembershipKey key = (IMembershipKey)obj;
+ return ObjectUtil.equals(getBuddy(), key.getBuddy())
+ && ObjectUtil.equals(getCollaboration(), key.getCollaboration());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return key.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return key.toString();
+ }
+
+ public static IMembership create(IBuddy buddy, ICollaboration collaboration)
+ {
+ Membership membership = new Membership(buddy, collaboration);
+ ((Buddy)buddy).addMembership(membership);
+ ((Collaboration)collaboration).addMembership(membership);
+ return membership;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipContainer.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipContainer.java
new file mode 100644
index 0000000000..88ce8da4c3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipContainer.java
@@ -0,0 +1,121 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.common.IMembershipContainer;
+import org.eclipse.net4j.buddies.common.IMembershipKey;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class MembershipContainer extends Lifecycle implements IMembershipContainer, IListener
+{
+ private ConcurrentMap<IMembershipKey, IMembership> memberships = new ConcurrentHashMap<IMembershipKey, IMembership>();
+
+ public MembershipContainer()
+ {
+ }
+
+ public void addMembership(IMembership membership)
+ {
+ if (memberships.putIfAbsent(membership, membership) == null)
+ {
+ fireEvent(new SingleDeltaContainerEvent<IMembership>(this, membership, IContainerDelta.Kind.ADDED));
+ membership.addListener(this);
+ }
+ }
+
+ public IMembership removeMembership(IBuddy buddy, ICollaboration collaboration)
+ {
+ return removeMembership(new MembershipKey(buddy, collaboration));
+ }
+
+ public IMembership removeMembership(IMembershipKey key)
+ {
+ // for (IMembership membership : memberships.values())
+ // {
+ //
+ // }
+ //
+ IMembership membership = memberships.remove(key);
+ if (membership != null)
+ {
+ membership.removeListener(this);
+ fireEvent(new SingleDeltaContainerEvent<IMembership>(this, membership, IContainerDelta.Kind.REMOVED));
+ }
+
+ return membership;
+ }
+
+ public IMembership[] getMemberships()
+ {
+ return memberships.values().toArray(new IMembership[memberships.size()]);
+ }
+
+ public IMembership getMembership(IBuddy buddy, ICollaboration collaboration)
+ {
+ return memberships.get(new MembershipKey(buddy, collaboration));
+ }
+
+ public IMembership[] getElements()
+ {
+ return getMemberships();
+ }
+
+ public boolean isEmpty()
+ {
+ return memberships.isEmpty();
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event.getSource() instanceof IMembership)
+ {
+ IMembership membership = (IMembership)event.getSource();
+ notifyMembershipEvent(event);
+ if (event instanceof ILifecycleEvent)
+ {
+ ILifecycleEvent e = (ILifecycleEvent)event;
+ if (e.getKind() == ILifecycleEvent.Kind.DEACTIVATED)
+ {
+ removeMembership(membership);
+ }
+ }
+ }
+ }
+
+ protected void notifyMembershipEvent(IEvent event)
+ {
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (IMembership membership : getMemberships())
+ {
+ membership.removeListener(this);
+ }
+
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipKey.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipKey.java
new file mode 100644
index 0000000000..ce228dc125
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MembershipKey.java
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IMembershipKey;
+import org.eclipse.net4j.util.ObjectUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class MembershipKey implements IMembershipKey
+{
+ private IBuddy buddy;
+
+ private ICollaboration collaboration;
+
+ public MembershipKey(IBuddy buddy, ICollaboration collaboration)
+ {
+ this.buddy = buddy;
+ this.collaboration = collaboration;
+ }
+
+ public IBuddy getBuddy()
+ {
+ return buddy;
+ }
+
+ public ICollaboration getCollaboration()
+ {
+ return collaboration;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof IMembershipKey)
+ {
+ IMembershipKey key = (IMembershipKey)obj;
+ return ObjectUtil.equals(getBuddy(), key.getBuddy())
+ && ObjectUtil.equals(getCollaboration(), key.getCollaboration());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(buddy) ^ ObjectUtil.hashCode(collaboration);
+ }
+
+ @Override
+ public String toString()
+ {
+ return buddy + "(" + collaboration + ")";
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MessageEvent.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MessageEvent.java
new file mode 100644
index 0000000000..f3aaa66aec
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/MessageEvent.java
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common;
+
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.buddies.common.IMessageEvent;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.event.INotifier;
+
+/**
+ * @author Eike Stepper
+ */
+public final class MessageEvent extends Event implements IMessageEvent
+{
+ private static final long serialVersionUID = 1L;
+
+ private IMessage message;
+
+ public MessageEvent(INotifier notifier, IMessage message)
+ {
+ super(notifier);
+ this.message = message;
+ }
+
+ public IMessage getMessage()
+ {
+ return message;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/bundle/OM.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/bundle/OM.java
new file mode 100644
index 0000000000..6b59c6c183
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/bundle/OM.java
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.net4j.buddies.common"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_MODEL = DEBUG.tracer("model"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_REVISION = DEBUG.tracer("revision"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateIndication.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateIndication.java
new file mode 100644
index 0000000000..30cf3eaf8f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateIndication.java
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.IBuddy.State;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class BuddyStateIndication extends Indication
+{
+ public BuddyStateIndication()
+ {
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_BUDDY_STATE;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ String userID = in.readString();
+ State state = ProtocolUtil.readState(in);
+ stateChanged(userID, state);
+ }
+
+ protected abstract void stateChanged(String userID, State state);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateNotification.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateNotification.java
new file mode 100644
index 0000000000..2d755ae66b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/BuddyStateNotification.java
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.IBuddy.State;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.signal.Request;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddyStateNotification extends Request
+{
+ private String userID;
+
+ private State state;
+
+ public BuddyStateNotification(IChannel channel, String userID, State state)
+ {
+ super(channel);
+ this.userID = userID;
+ this.state = state;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_BUDDY_STATE;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeString(userID);
+ ProtocolUtil.writeState(out, state);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftIndication.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftIndication.java
new file mode 100644
index 0000000000..36c22d707b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftIndication.java
@@ -0,0 +1,75 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.IBuddyProvider;
+import org.eclipse.net4j.buddies.common.ICollaborationProvider;
+import org.eclipse.net4j.buddies.internal.common.Buddy;
+import org.eclipse.net4j.buddies.internal.common.Collaboration;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationLeftIndication extends Indication
+{
+ private IBuddyProvider buddyProvider;
+
+ private ICollaborationProvider collaborationProvider;
+
+ public CollaborationLeftIndication(IBuddyProvider buddyProvider, ICollaborationProvider collaborationProvider)
+ {
+ this.buddyProvider = buddyProvider;
+ this.collaborationProvider = collaborationProvider;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_COLLABORATION_LEFT;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ long collaborationID = in.readLong();
+ String userID = in.readString();
+
+ Collaboration collaboration = getCollaboration(collaborationID);
+ if (collaboration != null)
+ {
+ Buddy buddy = getBuddy(userID);
+ if (buddy != null)
+ {
+ collaborationLeft(buddy, collaboration);
+ }
+ }
+ }
+
+ protected void collaborationLeft(Buddy buddy, Collaboration collaboration)
+ {
+ collaboration.removeMembership(buddy);
+ buddy.removeMembership(collaboration);
+ }
+
+ protected Collaboration getCollaboration(long collaborationID)
+ {
+ return (Collaboration)collaborationProvider.getCollaboration(collaborationID);
+ }
+
+ protected Buddy getBuddy(String userID)
+ {
+ return (Buddy)buddyProvider.getBuddy(userID);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftNotification.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftNotification.java
new file mode 100644
index 0000000000..5a70267057
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/CollaborationLeftNotification.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.signal.Request;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationLeftNotification extends Request
+{
+ private long collaborationID;
+
+ private String userID;
+
+ public CollaborationLeftNotification(IChannel channel, long collaborationID, String userID)
+ {
+ super(channel);
+ this.collaborationID = collaborationID;
+ this.userID = userID;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_COLLABORATION_LEFT;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeLong(collaborationID);
+ out.writeString(userID);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageIndication.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageIndication.java
new file mode 100644
index 0000000000..70cbb13ba1
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageIndication.java
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.ICollaborationProvider;
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.buddies.spi.common.Facility;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class MessageIndication extends Indication
+{
+ private ICollaborationProvider collaborationProvider;
+
+ public MessageIndication(ICollaborationProvider collaborationProvider)
+ {
+ this.collaborationProvider = collaborationProvider;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_MESSAGE;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ long collaborationID = in.readLong();
+ String facilityType = in.readString();
+ Facility facility = getFacility(collaborationID, facilityType);
+ if (facility != null)
+ {
+ IMessage message = ProtocolUtil.readMessage(in, facility.getClass().getClassLoader());
+ facility.handleMessage(message);
+ }
+ }
+
+ private Facility getFacility(long collaborationID, String facilityType)
+ {
+ ICollaboration collaboration = collaborationProvider.getCollaboration(collaborationID);
+ if (collaboration == null)
+ {
+ return null;
+ }
+
+ return (Facility)collaboration.getFacility(facilityType);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageNotification.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageNotification.java
new file mode 100644
index 0000000000..7de369b755
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/MessageNotification.java
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.signal.Request;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class MessageNotification extends Request
+{
+ private long collaborationID;
+
+ private String facilityType;
+
+ private IMessage message;
+
+ public MessageNotification(IChannel channel, long collaborationID, String facilityType, IMessage message)
+ {
+ super(channel);
+ this.collaborationID = collaborationID;
+ this.facilityType = facilityType;
+ this.message = message;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_MESSAGE;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeLong(collaborationID);
+ out.writeString(facilityType);
+ ProtocolUtil.writeMessage(out, message);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolConstants.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolConstants.java
new file mode 100644
index 0000000000..54bc1e835d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolConstants.java
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ProtocolConstants
+{
+ public static final String PROTOCOL_NAME = "buddies";
+
+ public static final short SIGNAL_OPEN_SESSION = 1;
+
+ public static final short SIGNAL_LOAD_ACCOUNT = 2;
+
+ public static final short SIGNAL_BUDDY_ADDED = 3;
+
+ public static final short SIGNAL_BUDDY_REMOVED = 4;
+
+ public static final short SIGNAL_BUDDY_STATE = 5;
+
+ public static final short SIGNAL_INITIATE_COLLABORATION = 6;
+
+ public static final short SIGNAL_COLLABORATION_INITIATED = 7;
+
+ public static final short SIGNAL_COLLABORATION_LEFT = 8;
+
+ public static final short SIGNAL_INVITE_BUDDIES = 9;
+
+ public static final short SIGNAL_BUDDIES_INVITED = 10;
+
+ public static final short SIGNAL_INSTALL_FACILITY = 11;
+
+ public static final short SIGNAL_FACILITY_INSTALLED = 12;
+
+ public static final short SIGNAL_MESSAGE = 13;
+
+ public static final long TIMEOUT = 5000L;
+
+ public static final byte STATE_AVAILABLE = 1;
+
+ public static final byte STATE_LONESOME = 2;
+
+ public static final byte STATE_AWAY = 3;
+
+ public static final byte STATE_DO_NOT_DISTURB = 4;
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolUtil.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolUtil.java
new file mode 100644
index 0000000000..674bfc6b0c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/internal/common/protocol/ProtocolUtil.java
@@ -0,0 +1,225 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.common.protocol;
+
+import org.eclipse.net4j.buddies.common.IAccount;
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.IBuddyContainer;
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ProtocolUtil
+{
+ private ProtocolUtil()
+ {
+ }
+
+ public static void writeBuddies(ExtendedDataOutputStream out, Collection<IBuddy> buddies) throws IOException
+ {
+ if (buddies == null)
+ {
+ out.writeInt(0);
+ }
+ else
+ {
+ out.writeInt(buddies.size());
+ for (IBuddy buddy : buddies)
+ {
+ out.writeString(buddy.getUserID());
+ }
+ }
+ }
+
+ public static Set<IBuddy> readBuddies(ExtendedDataInputStream in, IBuddyContainer buddyContainer) throws IOException
+ {
+ int size = in.readInt();
+ Set<IBuddy> buddies = new HashSet<IBuddy>();
+ for (int i = 0; i < size; i++)
+ {
+ String userID = in.readString();
+ IBuddy buddy = buddyContainer.getBuddy(userID);
+ if (buddy != null)
+ {
+ buddies.add(buddy);
+ }
+ }
+ return buddies;
+ }
+
+ public static String[] readUserIDs(ExtendedDataInputStream in) throws IOException
+ {
+ int size = in.readInt();
+ String[] userIDs = new String[size];
+ for (int i = 0; i < size; i++)
+ {
+ userIDs[i] = in.readString();
+ }
+
+ return userIDs;
+ }
+
+ public static void writeAccount(ExtendedDataOutputStream out, IAccount account) throws IOException
+ {
+ if (account != null)
+ {
+ out.writeBoolean(true);
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(account);
+ }
+ else
+ {
+ out.writeBoolean(false);
+ }
+ }
+
+ public static IAccount readAccount(ExtendedDataInputStream in) throws IOException
+ {
+ boolean exists = in.readBoolean();
+ if (!exists)
+ {
+ return null;
+ }
+
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(in);
+ return (IAccount)ois.readObject();
+ }
+ catch (IOException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public static void writeState(ExtendedDataOutputStream out, IBuddy.State state) throws IOException
+ {
+ switch (state)
+ {
+ case AVAILABLE:
+ out.writeByte(ProtocolConstants.STATE_AVAILABLE);
+ break;
+
+ case LONESOME:
+ out.writeByte(ProtocolConstants.STATE_LONESOME);
+ break;
+
+ case AWAY:
+ out.writeByte(ProtocolConstants.STATE_AWAY);
+ break;
+
+ case DO_NOT_DISTURB:
+ out.writeByte(ProtocolConstants.STATE_DO_NOT_DISTURB);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Illegal state: " + state);
+ }
+ }
+
+ public static IBuddy.State readState(ExtendedDataInputStream in) throws IOException
+ {
+ byte state = in.readByte();
+ switch (state)
+ {
+ case ProtocolConstants.STATE_AVAILABLE:
+ return IBuddy.State.AVAILABLE;
+
+ case ProtocolConstants.STATE_LONESOME:
+ return IBuddy.State.LONESOME;
+
+ case ProtocolConstants.STATE_AWAY:
+ return IBuddy.State.AWAY;
+
+ case ProtocolConstants.STATE_DO_NOT_DISTURB:
+ return IBuddy.State.DO_NOT_DISTURB;
+
+ default:
+ throw new IllegalArgumentException("Illegal state: " + state);
+ }
+ }
+
+ public static void writeFacilityTypes(ExtendedDataOutputStream out, String[] facilityTypes) throws IOException
+ {
+ if (facilityTypes == null)
+ {
+ out.writeInt(0);
+ }
+ else
+ {
+ out.writeInt(facilityTypes.length);
+ for (String facilityType : facilityTypes)
+ {
+ out.writeString(facilityType);
+ }
+ }
+ }
+
+ public static String[] readFacilityTypes(ExtendedDataInputStream in) throws IOException
+ {
+ int size = in.readInt();
+ String[] facilityTypes = new String[size];
+ for (int i = 0; i < size; i++)
+ {
+ facilityTypes[i] = in.readString();
+ }
+
+ return facilityTypes;
+ }
+
+ public static void writeMessage(ExtendedDataOutputStream out, IMessage message) throws IOException
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(message);
+ }
+
+ public static IMessage readMessage(ExtendedDataInputStream in, final ClassLoader classLoader) throws IOException
+ {
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(in)
+ {
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
+ {
+ String className = desc.getName();
+ return classLoader.loadClass(className);
+ }
+ };
+
+ return (IMessage)ois.readObject();
+ }
+ catch (IOException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ClientFacilityFactory.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ClientFacilityFactory.java
new file mode 100644
index 0000000000..46c2aaf28f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ClientFacilityFactory.java
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.spi.common;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ClientFacilityFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.buddies.clientFacilities";
+
+ public ClientFacilityFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Facility.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Facility.java
new file mode 100644
index 0000000000..0b3ac8b72c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Facility.java
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.spi.common;
+
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IFacility;
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.buddies.internal.common.Collaboration;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Facility extends Lifecycle implements IFacility
+{
+ private String type;
+
+ private Collaboration collaboration;
+
+ public Facility(String type)
+ {
+ this.type = type;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public Collaboration getCollaboration()
+ {
+ return collaboration;
+ }
+
+ public void setCollaboration(ICollaboration collaboration)
+ {
+ this.collaboration = (Collaboration)collaboration;
+ }
+
+ /**
+ * @see PlatformObject#getAdapter(Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter)
+ {
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+ }
+
+ public void sendMessage(IMessage message)
+ {
+ collaboration.sendMessage(collaboration.getID(), type, message);
+ }
+
+ public abstract void handleMessage(IMessage message);
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Message.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Message.java
new file mode 100644
index 0000000000..4a1879955e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/Message.java
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.spi.common;
+
+import org.eclipse.net4j.buddies.common.IMessage;
+import org.eclipse.net4j.util.StringUtil;
+
+import org.eclipse.core.runtime.PlatformObject;
+
+import java.io.Serializable;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Message extends PlatformObject implements IMessage, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String senderID;
+
+ protected Message()
+ {
+ }
+
+ public String getSenderID()
+ {
+ return senderID;
+ }
+
+ public void setSenderID(String senderID)
+ {
+ this.senderID = senderID;
+ }
+
+ protected String encode(String text)
+ {
+ return text.replaceAll(StringUtil.NL, "\n");
+ }
+
+ protected String decode(String text)
+ {
+ return text.replaceAll("\n", StringUtil.NL);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ServerFacilityFactory.java b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ServerFacilityFactory.java
new file mode 100644
index 0000000000..8bbca8a70e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.common/src/org/eclipse/net4j/buddies/spi/common/ServerFacilityFactory.java
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.spi.common;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ServerFacilityFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.buddies.serverFacilities";
+
+ public ServerFacilityFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}

Back to the top