KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > core > ScheduledAction


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

18 package freecs.core;
19
20 import freecs.Server;
21
22 /**
23  * used to schedule actions of a user
24  *
25  * freecs.core
26  */

27 public class ScheduledAction {
28    public static short UNPUNISH = 1;
29
30    User usr = null, sender = null;
31    short action = 0;
32    long startTime = 0;
33
34    public ScheduledAction (short action, long startTime, User target, User sender) {
35       this.action = action;
36       this.startTime = startTime;
37       this.usr = target;
38       this.sender = sender;
39       if (Server.TRACE_CREATE_AND_FINALIZE)
40           Server.log (this, "++++++++++++++++++++++++++++++++++++++++CREATE", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
41    }
42
43    public long getStartTime () { return startTime; }
44
45    public void execute () {
46       if (action == 0) return;
47       MessageParser mp = new MessageParser ();
48       if (action == UNPUNISH) {
49          usr.setPunish (false);
50          mp.setMessageTemplate ("message.rgag.singular");
51          mp.setUsercontext (usr);
52          mp.setSender (sender);
53       }
54       Group g = usr.getGroup ();
55       if (g != null)
56          g.sendMessage (mp);
57    }
58
59    public boolean equals (Object JavaDoc o) {
60        if (!(o instanceof ScheduledAction))
61            return false;
62        ScheduledAction sa = (ScheduledAction) o;
63        return this.action == sa.getAction () && this.usr == sa.getUser () && this.sender == sa.getSender ();
64    }
65    public short getAction () { return action; }
66    public User getUser () { return usr; }
67    public User getSender () { return sender; }
68    public int hashCode () { return usr.hashCode (); }
69
70    public void finalize() {
71        if (Server.TRACE_CREATE_AND_FINALIZE)
72            Server.log(this, "----------------------------------------FINALIZED", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
73    }
74 }
Popular Tags