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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (c) 2010-2015, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.elements;
/**
* Class representing Presence stanza
*
*/
public class Presence extends Stanza {
private Type type_;
/**
* Presence Stanza Type
*
*/
public enum Type {
Available, Error, Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed
};
/**
* Create the Presence object
*/
public Presence() {
type_ = Type.Available;
}
/**
* Create a Presence object from the specified object by
* creating a copy
* @param copy presence object to be copied, not null
*/
public Presence(Presence copy) {
super(copy);
this.type_ = copy.type_;
}
/**
* Create the Presence object using the status string
* @param status status string, not null
*/
public Presence(String status) {
type_ = Type.Available;
setStatus(status);
}
/**
* Get the Presence Stanza type
* @return presence type, not null
*/
public Type getType() {
return type_;
}
/**
* Set the Presence stanza type
* @param type stanza type, not null
*/
public void setType(Type type) {
type_ = type;
}
public StatusShow.Type getShow() {
StatusShow show = getPayload (new StatusShow());
if (show != null) {
return show.getType();
}
return type_ == Type.Available ? StatusShow.Type.Online : StatusShow.Type.None;
}
/**
* Set the show status type
* @param show status type, not null
*/
public void setShow(StatusShow.Type show) {
updatePayload(new StatusShow(show));
}
/**
* Get the status message
* @return status message, not null but can be empty
*/
public String getStatus() {
Status status = getPayload(new Status());
if (status != null) {
return status.getText();
}
return "";
}
/**
* Set the status string
* @param status status string, not null
*/
public void setStatus(String status) {
updatePayload(new Status(status));
}
/**
* Get the priority of presence stanza
* @return priority of presence stanza
*/
public int getPriority() {
Priority priority = getPayload(new Priority());
return (priority != null ? priority.getPriority() : 0);
}
/**
* Set the priority of presence message.
* @param priority priority value (allowed values -127 to 128)
*/
public void setPriority(int priority) {
updatePayload(new Priority(priority));
}
public boolean isAvailable() {
return type_ != null && type_ == Type.Available;
}
@Override
public String toString() {
return super.toString() + " Type=" + type_;
}
}
|