001/**
002 *
003 * Copyright the original author or authors
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 */
017package org.jivesoftware.smackx.pubsub;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.jivesoftware.smack.util.XmlStringBuilder;
023
024import org.jivesoftware.smackx.pubsub.Affiliation.AffiliationNamespace;
025
026/**
027 * Represents the <b>affiliations</b> element of the reply to a request for affiliations.
028 * It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a> and
029 * <a href="http://www.xmpp.org/extensions/xep-0060.html#owner-affiliations">8.9 Manage Affiliations</a>.
030 *
031 * @author Robin Collier
032 */
033public class AffiliationsExtension extends NodeExtension {
034    protected List<Affiliation> items = Collections.emptyList();
035
036    public AffiliationsExtension() {
037        this(null);
038    }
039
040    public AffiliationsExtension(List<Affiliation> subList) {
041        this(subList, null);
042    }
043
044    public AffiliationsExtension(AffiliationNamespace affiliationsNamespace, List<Affiliation> subList) {
045        this(affiliationsNamespace, subList, null);
046    }
047
048    public AffiliationsExtension(List<Affiliation> subList, String node) {
049        this(AffiliationNamespace.basic, subList, node);
050    }
051
052    public AffiliationsExtension(AffiliationNamespace affiliationsNamespace, List<Affiliation> subList, String node) {
053        super(affiliationsNamespace.type, node);
054        items = subList;
055    }
056
057    public List<Affiliation> getAffiliations() {
058        return items;
059    }
060
061    @Override
062    protected void addXml(XmlStringBuilder xml) {
063        if ((items == null) || (items.size() == 0)) {
064            xml.closeEmptyElement();
065            return;
066        }
067
068        xml.rightAngleBracket();
069        xml.append(items);
070        xml.closeElement(this);
071    }
072}