001/**
002 *
003 * Copyright © 2016 Fernando Ramirez
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.mam.element;
018
019import org.jivesoftware.smack.packet.IQ;
020
021import org.jivesoftware.smackx.rsm.packet.RSMSet;
022
023/**
024 * MAM fin IQ class.
025 *
026 * @see <a href="http://xmpp.org/extensions/xep-0313.html">XEP-0313: Message
027 *      Archive Management</a>
028 * @author Fernando Ramirez
029 *
030 */
031public class MamFinIQ extends IQ {
032
033    /**
034     * fin element.
035     */
036    public static final String ELEMENT = "fin";
037
038    /**
039     * RSM set.
040     */
041    private final RSMSet rsmSet;
042
043    /**
044     * if is complete.
045     */
046    private final boolean complete;
047
048    /**
049     * if is stable.
050     */
051    private final boolean stable;
052
053    /**
054     * the query id.
055     */
056    private final String queryId;
057
058    /**
059     * MamFinIQ constructor.
060     *
061     * @param version TODO javadoc me please
062     * @param queryId TODO javadoc me please
063     * @param rsmSet TODO javadoc me please
064     * @param complete TODO javadoc me please
065     * @param stable TODO javadoc me please
066     */
067    public MamFinIQ(MamVersion version, String queryId, RSMSet rsmSet, boolean complete, boolean stable) {
068        super(ELEMENT, version.getNamespace());
069        if (rsmSet == null) {
070            throw new IllegalArgumentException("rsmSet must not be null");
071        }
072        this.rsmSet = rsmSet;
073        this.complete = complete;
074        this.stable = stable;
075        this.queryId = queryId;
076    }
077
078    /**
079     * Get RSM set.
080     *
081     * @return the RSM set
082     */
083    public RSMSet getRSMSet() {
084        return rsmSet;
085    }
086
087    /**
088     * Return if it is complete.
089     *
090     * @return true if it is complete
091     */
092    public boolean isComplete() {
093        return complete;
094    }
095
096    /**
097     * Return if it is stable.
098     *
099     * @return true if it is stable
100     */
101    public boolean isStable() {
102        return stable;
103    }
104
105    /**
106     * Get query id.
107     *
108     * @return the query id
109     */
110    public final String getQueryId() {
111        return queryId;
112    }
113
114    @Override
115    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
116        xml.optAttribute("queryid", queryId);
117        xml.optBooleanAttribute("complete", complete);
118        xml.optBooleanAttribute("stable", stable);
119        if (rsmSet == null) {
120            xml.setEmptyElement();
121        } else {
122            xml.rightAngleBracket();
123            xml.append(rsmSet);
124        }
125        return xml;
126    }
127
128}