aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/stanzas/IqPacketGenerator.java
blob: 01204a96354962acad07a6aaabded4c882d91115 (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
package de.thedevstack.conversationsplus.xmpp.stanzas;

import de.thedevstack.conversationsplus.xml.Element;

/**
 * Created by tzur on 15.01.2016.
 */
public final class IqPacketGenerator {

    private static IqPacket generateIqPacket(IqPacket.TYPE type) {
        return new IqPacket(type);
    }

    public static IqPacket generateIqSetPacket() {
        return generateIqPacket(IqPacket.TYPE.SET);
    }

    public static IqPacket generateIqGetPacket() {
        return generateIqPacket(IqPacket.TYPE.GET);
    }

    public static IqPacket generateIqResultPacket() {
        return generateIqPacket(IqPacket.TYPE.RESULT);
    }

    public static IqPacket generateIqResultResponse(IqPacket packet) {
        IqPacket responsePacket = generateIqResultPacket();
        responsePacket.setTo(packet.getFrom());
        responsePacket.setId(packet.getId());

        return responsePacket;
    }

    public static ErrorIqPacket generateIqErrorPacketResponse(IqErrorCondition condition, IqPacket packet) {
        ErrorIqPacket errorPacket = new ErrorIqPacket(condition);
        errorPacket.setTo(packet.getFrom());
        errorPacket.setId(packet.getId());
        return errorPacket;
    }

    private IqPacketGenerator() {
        // avoid Instantiation
    }
}