1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-06-19 18:14:52 +02:00
Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java
Florian Schmaus 3d4e7938a7 Make ExtensionElement marker interface wrt. QNAME field
ExtensionElement is now a marker interface that requires all
implementation non-abstract classes to carry a static final QNAME
field (of type QName). This is verified by a new unit test.

Also FullyQualifiedElement is renamed to simply XmlElement. XmlElement
is used over ExtensionElement when implementing classes do not
statically know the qualified name of the XML elements they
represent. In general, XmlElement should be used sparingly, and every
XML element should be modeled by its own Java class (implementing
ExtensionElement).
2021-04-18 21:07:19 +02:00

102 lines
2.8 KiB
Java

/**
*
* Copyright 2003-2005 Jive Software, 2017-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.element;
import java.util.Locale;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
public final class JingleError implements XmlElement {
public static String NAMESPACE = "urn:xmpp:jingle:errors:1";
public static final JingleError OUT_OF_ORDER = new JingleError("out-of-order");
public static final JingleError TIE_BREAK = new JingleError("tie-break");
public static final JingleError UNKNOWN_SESSION = new JingleError("unknown-session");
public static final JingleError UNSUPPORTED_INFO = new JingleError("unsupported-info");
private final String errorName;
/**
* Creates a new error with the specified code and errorName.
*
* @param errorName a name describing the error.
*/
private JingleError(final String errorName) {
this.errorName = errorName;
}
/**
* Returns the name of the Jingle error.
*
* @return the name of the error.
*/
public String getMessage() {
return errorName;
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.closeEmptyElement();
return xml;
}
/**
* Returns a error instance associated with the String value.
*
* @param value the input String.
* @return the jingle error instance associated with the input String.
*/
public static JingleError fromString(String value) {
value = value.toLowerCase(Locale.US);
switch (value) {
case "out-of-order":
return OUT_OF_ORDER;
case "unknown-session":
return UNKNOWN_SESSION;
case "tie-break":
return TIE_BREAK;
case "unsupported-info":
return UNSUPPORTED_INFO;
default:
throw new IllegalArgumentException();
}
}
@Override
public String toString() {
return getMessage();
}
@Override
public String getElementName() {
return errorName;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
}