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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol.event;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* SubscriptionEvents indicate creation removal or failure of a given
* Subscription. Note that in SIP Communicator the terms Subscription and
* Contact are quite similar: A contact becomes available and it is possible
* to query its presence status and user information, once a
* subscription for this contact has been created.
*
* @author Emil Ivov
*/
public class SubscriptionEvent
extends EventObject
{
/**
* Serial version UID.
*/
private static final long serialVersionUID = 0L;
private int eventID = -1;
/**
* Indicates that the SubscriptionEvent instance was triggered by the
* creation of a new subscription
*/
public static final int SUBSCRIPTION_CREATED = 1;
/**
* Indicates that the SubscriptionEvent instance was triggered by the
* removal of an existing subscription
*/
public static final int SUBSCRIPTION_REMOVED = 2;
/**
* Indicates that the SubscriptionEvent instance was triggered by the fact
* that no confirmation of the successful completion of a new subscription
* has been received.
*/
public static final int SUBSCRIPTION_FAILED = 3;
/**
* Indicates that the SubscriptionEvent instance was triggered by the fact
* that the presence of a particular contact in the contact list has been
* confirmed by the server (resolved).
*/
public static final int SUBSCRIPTION_RESOLVED = 4;
/**
* Error code unknown
*/
public static final int ERROR_UNSPECIFIED = -1;
private ProtocolProviderService sourceProvider = null;
private ContactGroup parentGroup = null;
private int errorCode = ERROR_UNSPECIFIED;
private String errorReason = null;
/**
* Creates a new Subscription event according to the specified parameters.
* @param source the Contact instance that this subscription pertains to.
* @param provider the ProtocolProviderService instance where this event
* occurred
* @param parentGroup the ContactGroup underwhich the corresponding Contact
* is located
* @param eventID one of the SUBSCRIPTION_XXX static fields indicating the
* nature of the event.
*/
public SubscriptionEvent( Contact source,
ProtocolProviderService provider,
ContactGroup parentGroup,
int eventID)
{
this(source, provider, parentGroup, eventID, ERROR_UNSPECIFIED, null);
}
/**
* Creates a new Subscription event according to the specified parameters.
* @param source the Contact instance that this subscription pertains to.
* @param provider the ProtocolProviderService instance where this event
* occurred
* @param parentGroup the ContactGroup underwhich the corresponding Contact
* is located
* @param eventID one of the SUBSCRIPTION_XXX static fields indicating the
* nature of the event.
* @param errorCode the error code
* @param errorReason the error reason string
*/
public SubscriptionEvent( Contact source,
ProtocolProviderService provider,
ContactGroup parentGroup,
int eventID,
int errorCode,
String errorReason)
{
super(source);
this.sourceProvider = provider;
this.parentGroup = parentGroup;
this.eventID = eventID;
this.errorCode = errorCode;
this.errorReason = errorReason;
}
/**
* Returns the provider that the source contact belongs to.
* @return the provider that the source contact belongs to.
*/
public ProtocolProviderService getSourceProvider()
{
return sourceProvider;
}
/**
* Returns the provider that the source contact belongs to.
* @return the provider that the source contact belongs to.
*/
public Contact getSourceContact()
{
return (Contact)getSource();
}
/**
* Returns (if applicable) the group containing the contact that cause this
* event. In the case of a non persistent presence operation set this
* field is null.
* @return the ContactGroup (if there is one) containing the contact that
* caused the event.
*/
public ContactGroup getParentGroup()
{
return parentGroup;
}
/**
* Returns a String representation of this ContactPresenceStatusChangeEvent
*
* @return A a String representation of this <tt>SubscriptionEvent</tt>.
*/
@Override
public String toString()
{
StringBuffer buff
= new StringBuffer("SubscriptionEvent-[ ContactID=");
buff.append(getSourceContact().getAddress());
buff.append(", eventID=").append(getEventID());
if(getParentGroup() != null)
buff.append(", ParentGroup=").append(getParentGroup()
.getGroupName());
return buff.toString();
}
/**
* Returns an event id specifying whether the type of this event (e.g.
* SUBSCRIPTION_CREATED, SUBSCRIPTION_FAILED and etc.)
* @return one of the SUBSCRIPTION_XXX int fields of this class.
*/
public int getEventID()
{
return eventID;
}
/**
* If event is SUBSCRIPTION_FAILED, returns the error code
* of the failed event
* @return error code
*/
public int getErrorCode()
{
return errorCode;
}
/**
* If event is SUBSCRIPTION_FAILED, returns the reason of the error
* for the failed event
* @return the String reason for the error
*/
public String getErrorReason()
{
return errorReason;
}
}
|