• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

igniterealtime / Smack / #2874

pending completion
#2874

push

github-actions

vanitasvitae
Bump PGPainless to 1.5.3

1 of 1 new or added line in 1 file covered. (100.0%)

16372 of 41845 relevant lines covered (39.13%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.59
/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java
1
/**
2
 *
3
 * Copyright 2017-2022 Florian Schmaus
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.jivesoftware.smackx.jingle.element;
18

19
import java.util.HashMap;
20
import java.util.Map;
21

22
import org.jivesoftware.smack.packet.XmlElement;
23
import org.jivesoftware.smack.packet.XmlEnvironment;
24
import org.jivesoftware.smack.util.StringUtils;
25
import org.jivesoftware.smack.util.XmlStringBuilder;
26

27
/**
28
 * The Jingle 'reason' element.
29
 *
30
 * @see <a href="https://xmpp.org/extensions/xep-0166.html#def-reason">XEP-0166 ยง 7.4</a>
31
 *
32
 */
33
public class JingleReason implements XmlElement {
34

35
    public static final String ELEMENT = "reason";
36
    public static final String NAMESPACE = Jingle.NAMESPACE;
37
    public static final String TEXT_ELEMENT = "text";
38

39
    public static AlternativeSession AlternativeSession(String sessionId) {
40
        return new AlternativeSession(sessionId);
1✔
41
    }
42

43
    public static final JingleReason Busy = new JingleReason(Reason.busy);
1✔
44
    public static final JingleReason Cancel = new JingleReason(Reason.cancel);
1✔
45
    public static final JingleReason ConnectivityError = new JingleReason(Reason.connectivity_error);
1✔
46
    public static final JingleReason Decline = new JingleReason(Reason.decline);
1✔
47
    public static final JingleReason Expired = new JingleReason(Reason.expired);
1✔
48
    public static final JingleReason FailedApplication = new JingleReason(Reason.failed_application);
1✔
49
    public static final JingleReason FailedTransport = new JingleReason(Reason.failed_transport);
1✔
50
    public static final JingleReason GeneralError = new JingleReason(Reason.general_error);
1✔
51
    public static final JingleReason Gone = new JingleReason(Reason.gone);
1✔
52
    public static final JingleReason IncompatibleParameters = new JingleReason(Reason.incompatible_parameters);
1✔
53
    public static final JingleReason MediaError = new JingleReason(Reason.media_error);
1✔
54
    public static final JingleReason SecurityError = new JingleReason(Reason.security_error);
1✔
55
    public static final JingleReason Success = new JingleReason(Reason.success);
1✔
56
    public static final JingleReason Timeout = new JingleReason(Reason.timeout);
1✔
57
    public static final JingleReason UnsupportedApplications = new JingleReason(Reason.unsupported_applications);
1✔
58
    public static final JingleReason UnsupportedTransports = new JingleReason(Reason.unsupported_transports);
1✔
59

60
    public enum Reason {
1✔
61
        alternative_session,
1✔
62
        busy,
1✔
63
        cancel,
1✔
64
        connectivity_error,
1✔
65
        decline,
1✔
66
        expired,
1✔
67
        failed_application,
1✔
68
        failed_transport,
1✔
69
        general_error,
1✔
70
        gone,
1✔
71
        incompatible_parameters,
1✔
72
        media_error,
1✔
73
        security_error,
1✔
74
        success,
1✔
75
        timeout,
1✔
76
        unsupported_applications,
1✔
77
        unsupported_transports,
1✔
78
        ;
79

80
        static final Map<String, Reason> LUT = new HashMap<>(Reason.values().length);
1✔
81

82
        static {
83
            for (Reason reason : Reason.values()) {
1✔
84
                LUT.put(reason.toString(), reason);
1✔
85
            }
86
        }
1✔
87

88
        final String asString;
89

90
        Reason() {
1✔
91
            asString = name().replace('_', '-');
1✔
92
        }
1✔
93

94
        @Override
95
        public String toString() {
96
            return asString;
1✔
97
        }
98

99
        public static Reason fromString(String string) {
100
            Reason reason = LUT.get(string);
1✔
101
            if (reason == null) {
1✔
102
                throw new IllegalArgumentException("Unknown reason: " + string);
1✔
103
            }
104
            return reason;
1✔
105
        }
106
    }
107

108
    protected final Reason reason;
109
    private final String text;
110
    private final XmlElement element;
111

112
    public JingleReason(Reason reason) {
113
        this(reason, null, null);
1✔
114
    }
1✔
115

116
    public JingleReason(Reason reason, String text, XmlElement element) {
1✔
117
        this.reason = reason;
1✔
118
        this.text = text;
1✔
119
        this.element = element;
1✔
120
    }
1✔
121

122
    @Override
123
    public String getElementName() {
124
        return ELEMENT;
1✔
125
    }
126

127
    @Override
128
    public String getNamespace() {
129
        return NAMESPACE;
1✔
130
    }
131

132
    /**
133
     * An optional text that provides human-readable information about the reason for the action.
134
     *
135
     * @return a human-readable text with information regarding this reason or <code>null</code>.
136
     * @since 4.4.5
137
     */
138
    public String getText() {
139
        return text;
×
140
    }
141

142
    /**
143
     * An optional element that provides more detailed machine-readable information about the reason for the action.
144
     *
145
     * @return an element with machine-readable information about this reason or <code>null</code>.
146
     * @since 4.4.5
147
     */
148
    public XmlElement getElement() {
149
        return element;
1✔
150
    }
151

152
    @Override
153
    public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
154
        XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
1✔
155
        xml.rightAngleBracket();
1✔
156

157
        xml.emptyElement(reason);
1✔
158
        xml.optElement(TEXT_ELEMENT, text);
1✔
159
        xml.optAppend(element);
1✔
160

161
        xml.closeElement(this);
1✔
162
        return xml;
1✔
163
    }
164

165
    public Reason asEnum() {
166
        return reason;
1✔
167
    }
168

169

170
    public static class AlternativeSession extends JingleReason {
171

172
        public static final String SID = "sid";
173
        private final String sessionId;
174

175
        public AlternativeSession(String sessionId) {
176
            this(sessionId, null, null);
1✔
177
        }
1✔
178

179
        public AlternativeSession(String sessionId, String text, XmlElement element) {
180
            super(Reason.alternative_session, text, element);
1✔
181
            if (StringUtils.isNullOrEmpty(sessionId)) {
1✔
182
                throw new NullPointerException("SessionID must not be null or empty.");
1✔
183
            }
184
            this.sessionId = sessionId;
1✔
185
        }
1✔
186

187
        @Override
188
        public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
189
            XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
1✔
190
            xml.rightAngleBracket();
1✔
191

192
            xml.openElement(reason.asString);
1✔
193
            xml.openElement(SID);
1✔
194
            xml.append(sessionId);
1✔
195
            xml.closeElement(SID);
1✔
196
            xml.closeElement(reason.asString);
1✔
197

198
            xml.closeElement(this);
1✔
199
            return xml;
1✔
200
        }
201

202
        public String getAlternativeSessionId() {
203
            return sessionId;
×
204
        }
205
    }
206
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc