001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smackx.muc;
019
020import org.jivesoftware.smackx.muc.packet.MUCItem;
021
022/**
023 * Represents an affiliation of a user to a given room. The affiliate's information will always have
024 * the bare jid of the real user and its affiliation. If the affiliate is an occupant of the room
025 * then we will also have information about the role and nickname of the user in the room.
026 *
027 * @author Gaston Dombiak
028 */
029public class Affiliate {
030    // Fields that must have a value
031    private final String jid;
032    private final MUCAffiliation affiliation;
033
034    // Fields that may have a value
035    private final MUCRole role;
036    private final String nick;
037
038    Affiliate(MUCItem item) {
039        this.jid = item.getJid();
040        this.affiliation = item.getAffiliation();
041        this.role = item.getRole();
042        this.nick = item.getNick();
043    }
044
045    /**
046     * Returns the bare JID of the affiliated user. This information will always be available.
047     *
048     * @return the bare JID of the affiliated user.
049     */
050    public String getJid() {
051        return jid;
052    }
053
054    /**
055     * Returns the affiliation of the afffiliated user. Possible affiliations are: "owner", "admin",
056     * "member", "outcast". This information will always be available.
057     *
058     * @return the affiliation of the afffiliated user.
059     */
060    public MUCAffiliation getAffiliation() {
061        return affiliation;
062    }
063
064    /**
065     * Returns the current role of the affiliated user if the user is currently in the room.
066     * If the user is not present in the room then the answer will be 'none'.
067     *
068     * @return the current role of the affiliated user in the room or null if the user is not in
069     *         the room.
070     */
071    public MUCRole getRole() {
072        return role;
073    }
074
075    /**
076     * Returns the current nickname of the affiliated user if the user is currently in the room.
077     * If the user is not present in the room then the answer will be null.
078     *
079     * @return the current nickname of the affiliated user in the room or null if the user is not in
080     *         the room.
081     */
082    public String getNick() {
083        return nick;
084    }
085}