01: /**
02: * $RCSfile: $
03: * $Revision: $
04: * $Date: $
05: *
06: * Copyright (C) 2007 Jive Software. All rights reserved.
07: *
08: * This software is published under the terms of the GNU Public License (GPL),
09: * a copy of which is included in this distribution.
10: */package org.jivesoftware.openfire.muc.cluster;
11:
12: import org.dom4j.Element;
13: import org.dom4j.tree.DefaultElement;
14: import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
15: import org.jivesoftware.util.cache.ExternalizableUtil;
16: import org.xmpp.packet.Presence;
17:
18: import java.io.IOException;
19: import java.io.ObjectInput;
20: import java.io.ObjectOutput;
21:
22: /**
23: * Task that changes the nickname of an existing room occupant in the cluster node. When
24: * a room occupant changes his nickname the other cluster nodes, that hold a
25: * {@link org.jivesoftware.openfire.muc.spi.RemoteMUCRole} will need to update their local
26: * information with the new nickname.
27: *
28: * @author Gaston Dombiak
29: */
30: public class ChangeNickname extends MUCRoomTask {
31: private String oldNick;
32: private String newNick;
33: private Presence presence;
34:
35: public ChangeNickname() {
36: }
37:
38: public ChangeNickname(LocalMUCRoom room, String oldNick,
39: String newNick, Presence presence) {
40: super (room);
41: this .oldNick = oldNick;
42: this .newNick = newNick;
43: this .presence = presence;
44: }
45:
46: public String getOldNick() {
47: return oldNick;
48: }
49:
50: public String getNewNick() {
51: return newNick;
52: }
53:
54: public Presence getPresence() {
55: return presence;
56: }
57:
58: public Object getResult() {
59: return null;
60: }
61:
62: public void run() {
63: getRoom().nicknameChanged(this );
64: }
65:
66: public void writeExternal(ObjectOutput out) throws IOException {
67: super .writeExternal(out);
68: ExternalizableUtil.getInstance().writeSerializable(out,
69: (DefaultElement) presence.getElement());
70: ExternalizableUtil.getInstance().writeSafeUTF(out, oldNick);
71: ExternalizableUtil.getInstance().writeSafeUTF(out, newNick);
72: }
73:
74: public void readExternal(ObjectInput in) throws IOException,
75: ClassNotFoundException {
76: super .readExternal(in);
77: Element packetElement = (Element) ExternalizableUtil
78: .getInstance().readSerializable(in);
79: presence = new Presence(packetElement, true);
80: oldNick = ExternalizableUtil.getInstance().readSafeUTF(in);
81: newNick = ExternalizableUtil.getInstance().readSafeUTF(in);
82: }
83: }
|