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
022import org.jxmpp.jid.Jid;
023import org.jxmpp.jid.parts.Resourcepart;
024
025/**
026 * Represents an affiliation of a user to a given room. The affiliate's information will always have
027 * the bare jid of the real user and its affiliation. If the affiliate is an occupant of the room
028 * then we will also have information about the role and nickname of the user in the room.
029 *
030 * @author Gaston Dombiak
031 */
032public class Affiliate {
033    // Fields that must have a value
034    private final Jid jid;
035    private final MUCAffiliation affiliation;
036
037    // Fields that may have a value
038    private final MUCRole role;
039    private final Resourcepart nick;
040
041    Affiliate(MUCItem item) {
042        this.jid = item.getJid();
043        this.affiliation = item.getAffiliation();
044        this.role = item.getRole();
045        this.nick = item.getNick();
046    }
047
048    /**
049     * Returns the bare JID of the affiliated user. This information will always be available.
050     *
051     * @return the bare JID of the affiliated user.
052     */
053    public Jid getJid() {
054        return jid;
055    }
056
057    /**
058     * Returns the affiliation of the afffiliated user. Possible affiliations are: "owner", "admin",
059     * "member", "outcast". This information will always be available.
060     *
061     * @return the affiliation of the afffiliated user.
062     */
063    public MUCAffiliation getAffiliation() {
064        return affiliation;
065    }
066
067    /**
068     * Returns the current role of the affiliated user if the user is currently in the room.
069     * If the user is not present in the room then the answer will be 'none'.
070     *
071     * @return the current role of the affiliated user in the room or null if the user is not in
072     *         the room.
073     */
074    public MUCRole getRole() {
075        return role;
076    }
077
078    /**
079     * Returns the current nickname of the affiliated user if the user is currently in the room.
080     * If the user is not present in the room then the answer will be null.
081     *
082     * @return the current nickname of the affiliated user in the room or null if the user is not in
083     *         the room.
084     */
085    public Resourcepart getNick() {
086        return nick;
087    }
088}