SessionRemove.java 1.87 KB
Newer Older
Alexander Ivanov's avatar
Alexander Ivanov committed
1 2
/**
 * Copyright (c) 2013, Redsolution LTD. All rights reserved.
3
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
4 5
 * This file is part of Xabber project; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License, Version 3.
6
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
7 8 9 10
 * Xabber is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
11
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * You should have received a copy of the GNU General Public License,
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
package com.xabber.xmpp.archive;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.xmlpull.v1.XmlSerializer;

import com.xabber.xmpp.IQ;

/**
 * Packet to remove sessions from the message archive preferences.
28
 * <p/>
Alexander Ivanov's avatar
Alexander Ivanov committed
29
 * http://xmpp.org/extensions/xep-0136.html
30
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
31 32 33 34
 * @author alexander.ivanov
 */
public class SessionRemove extends IQ {

35 36
    public static final String ELEMENT_NAME = "sessionremove";
    public static final String NAMESPACE = "urn:xmpp:archive";
Alexander Ivanov's avatar
Alexander Ivanov committed
37

38
    private final Collection<Session> sessions;
Alexander Ivanov's avatar
Alexander Ivanov committed
39

40 41 42
    public SessionRemove() {
        sessions = new ArrayList<Session>();
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
43

44 45 46 47 48
    @Override
    public void serializeContent(XmlSerializer serializer) throws IOException {
        for (Session session : sessions)
            session.serialize(serializer);
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
49

50 51 52 53
    @Override
    public boolean isValid() {
        return sessions.size() > 0;
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
54

55 56 57 58
    @Override
    public String getElementName() {
        return ELEMENT_NAME;
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
59

60 61 62 63
    @Override
    public String getNamespace() {
        return NAMESPACE;
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
64

65 66 67
    public void addSession(Session session) {
        sessions.add(session);
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
68

69 70 71
    public Collection<Session> getSessions() {
        return Collections.unmodifiableCollection(sessions);
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
72 73

}