KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmailadmin > JMailAdminPlugin


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.jmailadmin;
20
21 import java.util.ArrayList JavaDoc;
22
23 import org.lucane.applications.jmailadmin.gui.MainFrame;
24 import org.lucane.client.*;
25 import org.lucane.client.widgets.DialogBox;
26 import org.lucane.common.ConnectInfo;
27 import org.lucane.common.net.ObjectConnection;
28
29
30 public class JMailAdminPlugin
31   extends StandalonePlugin
32 {
33     private ConnectInfo service;
34
35     public JMailAdminPlugin()
36     {
37     }
38     
39     public Plugin newInstance(ConnectInfo[] friends)
40     {
41         return new JMailAdminPlugin();
42     }
43
44     public void start()
45     {
46         this.service = Communicator.getInstance().getConnectInfo("org.lucane.applications.jmailadmin");
47         MainFrame mf = new MainFrame(this);
48         mf.setExitPluginOnClose(true);
49         mf.show();
50     }
51     
52     public boolean storeAccount(Account a)
53     {
54         boolean result = true;
55         
56         JMailAdminAction jma = new JMailAdminAction(JMailAdminAction.STORE_ACCOUNT, a);
57         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
58                 service, service.getName(), jma);
59
60         try {
61             if(oc.readString().startsWith("OK"))
62                 DialogBox.info(tr("msg.accountStored"));
63             else
64             {
65                 DialogBox.error(tr("err.storeAccount"));
66                 result = false;
67             }
68         } catch(Exception JavaDoc e) {
69             result = false;
70             DialogBox.error(tr("err.storeAccount"));
71             e.printStackTrace();
72         }
73         oc.close();
74         
75         return result;
76     }
77     
78     public Account getAccount(String JavaDoc user)
79     {
80         Account a = null;
81         JMailAdminAction jma = new JMailAdminAction(JMailAdminAction.GET_ACCOUNT, user);
82         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
83                 service, service.getName(), jma);
84         
85         try {
86             if(oc.readString().startsWith("OK"))
87                 a = (Account)oc.read();
88         } catch(Exception JavaDoc e) {
89             //probably no account yet
90
a = new Account(user);
91         }
92         
93         oc.close();
94         return a;
95     }
96     
97     public ArrayList JavaDoc getUsers()
98     {
99         ArrayList JavaDoc users = null;
100         JMailAdminAction jma = new JMailAdminAction(JMailAdminAction.GET_USERS);
101         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
102                 service, service.getName(), jma);
103         
104         try {
105             if(oc.readString().startsWith("OK"))
106                 users = (ArrayList JavaDoc)oc.read();
107         } catch(Exception JavaDoc e) {
108             DialogBox.error(tr("err.unableToGetUserList"));
109         }
110         
111         oc.close();
112         return users;
113     }
114 }
115
Popular Tags