KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > maininterface > MainInterfaceService


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.maininterface;
20
21 import org.lucane.common.*;
22 import org.lucane.common.concepts.*;
23 import org.lucane.common.net.ObjectConnection;
24 import org.lucane.server.*;
25 import org.lucane.server.store.Store;
26
27 import java.io.IOException JavaDoc;
28 import java.util.*;
29
30 public class MainInterfaceService
31 extends Service
32 {
33   private Store store = null;
34
35   public MainInterfaceService()
36   {
37   }
38
39   public void init(Server parent)
40   {
41       store = parent.getStore();
42   }
43
44   public void process(ObjectConnection oc, Message message)
45   {
46     MainInterfaceAction mia = (MainInterfaceAction)message.getData();
47     String JavaDoc user = message.getSender().getName();
48     ArrayList result = null;
49
50     switch(mia.action)
51     {
52         case MainInterfaceAction.GET_MY_GROUPS:
53             result = getMyGroups(user);
54             break;
55         case MainInterfaceAction.GET_CONNECTED_USERS_FOR_GROUP:
56             result = getConnectedUsersForGroup(mia.param);
57             break;
58     }
59         
60     try {
61         oc.write(result);
62     } catch (IOException JavaDoc e) {
63         //nothing can be done here
64
Logging.getLogger().warning("unable to send result");
65     }
66   }
67   
68   private ArrayList getMyGroups(String JavaDoc login)
69   {
70     ArrayList groups = new ArrayList();
71
72     try {
73         UserConcept user = store.getUserStore().getUser(login);
74         Iterator i = store.getUserStore().getAllUserGroups(user);
75         while(i.hasNext())
76         {
77             GroupConcept group = (GroupConcept)i.next();
78             groups.add(group.getName());
79         }
80     } catch(Exception JavaDoc e) {
81         e.printStackTrace();
82     }
83     
84     return groups;
85   }
86   
87   private ArrayList getConnectedUsersForGroup(String JavaDoc group)
88   {
89     ArrayList users = new ArrayList();
90
91     try {
92         Iterator i = store.getGroupStore().getUsersFor(new GroupConcept(group));
93         while(i.hasNext())
94         {
95             UserConcept user = (UserConcept)i.next();
96             if(ConnectInfoManager.getInstance().isConnected(user.getName()))
97                 users.add(user.getName());
98         }
99     } catch(Exception JavaDoc e) {
100         e.printStackTrace();
101     }
102     
103     return users;
104   }
105 }
106
107
Popular Tags