Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bfa7ebe8576ff18d74b4de49776f4ec5498ee2f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/******************************************************************************
 * Copyright (c) 2008 Versant Corporation and others.
 * 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:
 *     Remy Chi Jian Suen (Versant Corporation) - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.internal.example.collab.presence;

import java.util.Map;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.user.IUser;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject;
import org.eclipse.ecf.internal.example.collab.ClientPlugin;
import org.eclipse.ecf.presence.*;
import org.eclipse.ecf.presence.history.IHistoryManager;
import org.eclipse.ecf.presence.im.*;
import org.eclipse.ecf.presence.im.IChatMessage.Type;
import org.eclipse.ecf.presence.roster.IRosterManager;
import org.eclipse.ecf.presence.search.IUserSearchManager;
import org.eclipse.ecf.presence.search.message.IMessageSearchManager;
import org.eclipse.ecf.presence.service.IPresenceService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class PresenceContainer extends AbstractPresenceContainer implements IChatManager, IChatMessageSender, IPresenceSender, IPresenceService {

	private final ListenerList messageListeners = new ListenerList();

	private final EclipseCollabSharedObject sharedObject;
	private final IContainer container;
	private final IRosterManager manager;
	private ServiceRegistration serviceRegistration;

	public PresenceContainer(EclipseCollabSharedObject sharedObject, IContainer container, IUser user) {
		this.sharedObject = sharedObject;
		this.container = container;
		manager = new RosterManager(this, user);

		BundleContext bundleContext = ClientPlugin.getDefault().getBundle().getBundleContext();
		serviceRegistration = bundleContext.registerService(IPresenceService.class.getName(), this, null);
	}

	public void unregister() {
		if (serviceRegistration != null) {
			serviceRegistration.unregister();
			serviceRegistration = null;
		}
	}

	public IChatManager getChatManager() {
		return this;
	}

	public IRosterManager getRosterManager() {
		return manager;
	}

	public Object getAdapter(Class adapter) {
		if (adapter.isInstance(this)) {
			return this;
		} else if (adapter == IContainer.class) {
			return container;
		}
		return super.getAdapter(adapter);
	}

	public void fireMessageEvent(IIMMessageEvent messageEvent) {
		Object[] listeners = messageListeners.getListeners();
		for (int i = 0; i < listeners.length; i++) {
			IIMMessageListener listener = (IIMMessageListener) listeners[i];
			listener.handleMessageEvent(messageEvent);
		}
	}

	public void addMessageListener(IIMMessageListener listener) {
		messageListeners.add(listener);
	}

	public void removeMessageListener(IIMMessageListener listener) {
		messageListeners.remove(listener);
	}

	public void sendPresenceUpdate(ID targetId, IPresence presence) throws ECFException {
		// unimplemented as we have no concept of presence support, either online or offline
	}

	public IChat createChat(ID targetUser, IIMMessageListener messageListener) throws ECFException {
		return null;
	}

	public IChatMessageSender getChatMessageSender() {
		return this;
	}

	public IHistoryManager getHistoryManager() {
		return null;
	}

	public ITypingMessageSender getTypingMessageSender() {
		return null;
	}

	public void sendChatMessage(ID toId, ID threadId, Type type, String subject, String body, Map properties) throws ECFException {
		sharedObject.sendPrivateMessageToUser(toId, body);
	}

	public void sendChatMessage(ID toId, String body) throws ECFException {
		sendChatMessage(toId, null, null, null, body, null);
	}

	public IUserSearchManager getUserSearchManager() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ecf.presence.im.IChatManager#getMessageSearchManager()
	 */
	public IMessageSearchManager getMessageSearchManager() {
		return null;
	}

}

Back to the top