summaryrefslogtreecommitdiffstats
blob: 78d4d6a8badb5dce5f97dac56b2f2356708ab42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (c) 2010-2012, Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2010, Remko Tronçon.
 * All rights reserved.
 */
package com.isode.stroke.elements;

import com.isode.stroke.jid.JID;

public class IQ extends Stanza {
    public enum Type {Get, Set, Result, Error}

    private Type type_;

    public IQ() {
        this(Type.Get);
    }

    public IQ(Type type) {
        type_ = type;
    }

    public Type getType() {
        return type_;
    }

    public void setType(Type type) {
        type_ = type;
    }

    public static IQ createRequest(Type type, JID to, String id, Payload payload) {
        IQ iq = new IQ(type);
        iq.setTo(to);
        iq.setID(id);
        iq.addPayload(payload);
        return iq;
    }

    public static IQ createResult(JID to, String id, Payload payload) {
        IQ iq = new IQ(Type.Result);
        iq.setTo(to);
        iq.setID(id);
        iq.addPayload(payload);
        return iq;
    }

    public static IQ createError(JID to, String id, ErrorPayload.Condition condition, ErrorPayload.Type type) {
        IQ iq = new IQ(Type.Error);
        iq.setTo(to);
        iq.setID(id);
        iq.addPayload(new ErrorPayload(condition, type));
        return iq;
    }

    @Override
    public String toString() {
        return super.toString() + " Type=" + type_; 
    }
}