blob: e9e4577563d887ea97bfec59bf27d46c93be482e (
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
|
/****************************************************************************
* Copyright (c) 2008 Marcelo Mayworm.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors: Marcelo Mayworm - initial API and implementation
*
*
* SPDX-License-Identifier: EPL-2.0
*****************************************************************************/
package org.eclipse.ecf.presence.search;
import java.util.*;
/**
* Abstract implementation of IUserSearchManager. Provides implementations of listener
* methods that subsclasses may use to avoid having to implement them
* themselves. This class may be subclassed as needed.
* @since 2.0
*/
public abstract class AbstractUserSearchManager implements IUserSearchManager {
/** keep the list of listeners */
private final List userSearchListeners = new ArrayList(5);
/**
* Add listener to {@link IUserSearchListener}. The listener's handleEvent method will be
* asynchronously called.
* @param l
* the IUserSearchListener to add
*/
public void addListener(IUserSearchListener l) {
synchronized (userSearchListeners) {
userSearchListeners.add(l);
}
}
/**
* Remove listener from the listener list.
*
* @param l
* the IUserSearchListener to remove
*/
public void removeListener(IUserSearchListener l) {
synchronized (userSearchListeners) {
userSearchListeners.remove(l);
}
}
/**
* Fires a user search event, invoking the {@link IUserSearchListener}.
*
* @param event IUserSearchEvent.
*/
protected void fireUserSearchEvent(IUserSearchEvent event) {
List toNotify = null;
// Copy array
synchronized (userSearchListeners) {
toNotify = new ArrayList(userSearchListeners);
}
// Notify all in toNotify
for (Iterator i = toNotify.iterator(); i.hasNext();) {
IUserSearchListener l = (IUserSearchListener) i.next();
l.handleUserSearchEvent(event);
}
}
}
|