01 package biz.xsoftware.examples.listener2;
02
03 import java.util.HashSet;
04
05 /**
06 */
07 public class UserReplicationServiceImpl implements UserReplicationService
08 {
09
10 private UserService userSvc;
11 private HashSet<String> users = new HashSet<String>();
12
13 /**
14 * Creates an instance of UserReplicationServiceImpl.
15 * @param service
16 */
17 public UserReplicationServiceImpl(UserService service)
18 {
19 this.userSvc = service;
20 userSvc.addUserListener(new MyUserListener());
21 }
22
23
24 /**
25 * @see biz.xsoftware.examples.listener2.UserReplicationService#doesUserExist(java.lang.String)
26 */
27 public boolean doesUserExist(String user)
28 {
29 return users.contains(user);
30 }
31
32 private class MyUserListener implements UserListener {
33
34 /**
35 * @see biz.xsoftware.examples.listener2.UserListener#userAdded(java.lang.String)
36 */
37 public void userAdded(String userName)
38 {
39 users.add(userName);
40 }
41
42 /**
43 * @see biz.xsoftware.examples.listener2.UserListener#userDeleted(java.lang.String)
44 */
45 public void userDeleted(String userName)
46 {
47 users.remove(userName);
48 }
49
50 }
51 }
|