KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > userprofile > UserProfileService


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.userprofile;
20
21 import org.lucane.common.*;
22 import org.lucane.server.*;
23 import org.lucane.common.concepts.UserConcept;
24 import org.lucane.common.net.ObjectConnection;
25 import org.lucane.server.store.UserStore;
26
27 public class UserProfileService extends Service
28 {
29     private UserStore store;
30     
31     public UserProfileService()
32     {
33     }
34     
35     public void init(Server parent)
36     {
37         this.store = parent.getStore().getUserStore();
38     }
39     
40     public void process(ObjectConnection oc, Message message)
41     {
42         UserProfileAction upa = (UserProfileAction)message.getData();
43         String JavaDoc login = message.getSender().getName();
44         
45         try {
46             switch(upa.getAction())
47             {
48             case UserProfileAction.GET_PROFILE:
49                 ProfileInfo profile = getProfile(login);
50                 oc.write("OK");
51                 oc.write(profile);
52                 break;
53             
54             case UserProfileAction.SET_PROFILE:
55                 setProfile(login, upa.getProfile());
56                 oc.write("OK");
57                 break;
58             }
59         } catch(Exception JavaDoc e) {
60             try {
61                 oc.write("FAILED " + e);
62             } catch(Exception JavaDoc e2) {}
63         }
64     }
65     
66     public void setProfile(String JavaDoc login, ProfileInfo profile)
67     throws Exception JavaDoc
68     {
69         UserConcept user = store.getUser(login);
70         user.setRealName(profile.getRealName());
71         user.setMailAddress(profile.getMailAddress());
72         user.setLanguage(profile.getLanguage());
73         store.updateUser(user);
74     }
75     
76     public ProfileInfo getProfile(String JavaDoc login)
77     throws Exception JavaDoc
78     {
79         UserConcept user = store.getUser(login);
80         return new ProfileInfo(user.getRealName(), user.getMailAddress(), user.getLanguage());
81     }
82 }
Popular Tags