001: /**
002: * $RCSfile$
003: * $Revision: $
004: * $Date: $
005: *
006: * Copyright (C) 2007 Jive Software. All rights reserved.
007: *
008: * This software is published under the terms of the GNU Public License (GPL),
009: * a copy of which is included in this distribution.
010: */package org.jivesoftware.openfire.muc.cluster;
011:
012: import org.dom4j.Element;
013: import org.dom4j.tree.DefaultElement;
014: import org.jivesoftware.openfire.XMPPServer;
015: import org.jivesoftware.openfire.cluster.NodeID;
016: import org.jivesoftware.openfire.muc.MUCRole;
017: import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
018: import org.jivesoftware.util.cache.ExternalizableUtil;
019: import org.xmpp.packet.JID;
020: import org.xmpp.packet.Presence;
021:
022: import java.io.IOException;
023: import java.io.ObjectInput;
024: import java.io.ObjectOutput;
025:
026: /**
027: * Task that will remove a room occupant from the list of occupants in the room.
028: *
029: * @author Gaston Dombiak
030: */
031: public class OccupantAddedEvent extends MUCRoomTask {
032: private Presence presence;
033: private int role;
034: private int affiliation;
035: private boolean voiceOnly;
036: private JID roleAddress;
037: private JID userAddress;
038: private NodeID nodeID;
039: private boolean sendPresence;
040:
041: public OccupantAddedEvent() {
042: }
043:
044: public OccupantAddedEvent(LocalMUCRoom room, MUCRole occupant) {
045: super (room);
046: presence = occupant.getPresence();
047: role = occupant.getRole().ordinal();
048: affiliation = occupant.getAffiliation().ordinal();
049: voiceOnly = occupant.isVoiceOnly();
050: roleAddress = occupant.getRoleAddress();
051: userAddress = occupant.getUserAddress();
052: nodeID = XMPPServer.getInstance().getNodeID();
053: }
054:
055: public Presence getPresence() {
056: return presence;
057: }
058:
059: public String getNickname() {
060: return presence.getTo().getResource();
061: }
062:
063: public MUCRole.Role getRole() {
064: return MUCRole.Role.values()[role];
065: }
066:
067: public MUCRole.Affiliation getAffiliation() {
068: return MUCRole.Affiliation.values()[affiliation];
069: }
070:
071: public boolean isVoiceOnly() {
072: return voiceOnly;
073: }
074:
075: public JID getRoleAddress() {
076: return roleAddress;
077: }
078:
079: public JID getUserAddress() {
080: return userAddress;
081: }
082:
083: public NodeID getNodeID() {
084: return nodeID;
085: }
086:
087: /**
088: * Sets if the room should broadcast presence of the new occupant to occupants
089: * hosted by this cluster node.
090: *
091: * @param sendPresence true if the room should broadcast presence of the new occupant to occupants
092: * hosted by this cluster node.
093: */
094: public void setSendPresence(boolean sendPresence) {
095: this .sendPresence = sendPresence;
096: }
097:
098: /**
099: * Returns true if the room should broadcast presence of the new occupant to occupants
100: * hosted by this cluster node.
101: *
102: * @return true if the room should broadcast presence of the new occupant to occupants
103: * hosted by this cluster node.
104: */
105: public boolean isSendPresence() {
106: return sendPresence;
107: }
108:
109: public Object getResult() {
110: return null;
111: }
112:
113: public void run() {
114: getRoom().occupantAdded(this );
115: }
116:
117: public void writeExternal(ObjectOutput out) throws IOException {
118: super .writeExternal(out);
119: ExternalizableUtil.getInstance().writeSerializable(out,
120: (DefaultElement) presence.getElement());
121: ExternalizableUtil.getInstance().writeInt(out, role);
122: ExternalizableUtil.getInstance().writeInt(out, affiliation);
123: ExternalizableUtil.getInstance().writeBoolean(out, voiceOnly);
124: ExternalizableUtil.getInstance().writeSerializable(out,
125: roleAddress);
126: ExternalizableUtil.getInstance().writeSerializable(out,
127: userAddress);
128: ExternalizableUtil.getInstance().writeByteArray(out,
129: nodeID.toByteArray());
130: ExternalizableUtil.getInstance()
131: .writeBoolean(out, sendPresence);
132: }
133:
134: public void readExternal(ObjectInput in) throws IOException,
135: ClassNotFoundException {
136: super .readExternal(in);
137: Element packetElement = (Element) ExternalizableUtil
138: .getInstance().readSerializable(in);
139: presence = new Presence(packetElement, true);
140: role = ExternalizableUtil.getInstance().readInt(in);
141: affiliation = ExternalizableUtil.getInstance().readInt(in);
142: voiceOnly = ExternalizableUtil.getInstance().readBoolean(in);
143: roleAddress = (JID) ExternalizableUtil.getInstance()
144: .readSerializable(in);
145: userAddress = (JID) ExternalizableUtil.getInstance()
146: .readSerializable(in);
147: nodeID = NodeID.getInstance(ExternalizableUtil.getInstance()
148: .readByteArray(in));
149: sendPresence = ExternalizableUtil.getInstance().readBoolean(in);
150: }
151: }
|