2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.common;
10 import static java.util.Objects.requireNonNull;
12 import java.io.Serial;
13 import java.io.Serializable;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
18 * Extensible enumeration of {@code error-tag} values, as defined in
19 * <a href="https://www.rfc-editor.org/rfc/rfc6241#appendix-A">RFC6241</a>. These values are an extensible enumeration,
20 * since YANG does not place restriction on possible values in
21 * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.9">RFC8040</a>.
24 * Error tag defines overall error semantics. Additional tag-specific information may be associated with a particular
28 public final class ErrorTag implements Serializable {
30 * {@code access-denied} {@link ErrorTag}.
32 public static final ErrorTag ACCESS_DENIED = new ErrorTag("access-denied");
34 * {@code bad-attribute} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 6
36 * For insert handling, if the value for the attributes "before" and
37 * "after" are not valid for the type of the appropriate key leafs,
38 * the server MUST reply with a "bad-attribute" error-tag in the rpc-
42 public static final ErrorTag BAD_ATTRIBUTE = new ErrorTag("bad-attribute");
44 * {@code bad-element} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 3
46 * If data for more than one case branch of a choice is present, the
47 * server MUST reply with a "bad-element" in the rpc-error.
50 public static final ErrorTag BAD_ELEMENT = new ErrorTag("bad-element");
52 * {@code data-exists} {@link ErrorTag}.
54 public static final ErrorTag DATA_EXISTS = new ErrorTag("data-exists");
56 * {@code data-missing} {@link ErrorTag}. Covers mechanics specified in RFC6020 sections 13.5 through 13.7.
58 public static final ErrorTag DATA_MISSING = new ErrorTag("data-missing");
60 * {@code in-use} {@link ErrorTag}.
62 public static final ErrorTag IN_USE = new ErrorTag("in-use");
64 * {@code invalid-value} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 1
66 * If a leaf data value does not match the type constraints for the
67 * leaf, including those defined in the type's "range", "length", and
68 * "pattern" properties, the server MUST reply with an
69 * "invalid-value" error-tag in the rpc-error, and with the error-
70 * app-tag and error-message associated with the constraint, if any
74 public static final ErrorTag INVALID_VALUE = new ErrorTag("invalid-value");
76 * {@code lock-denied} {@link ErrorTag}.
78 public static final ErrorTag LOCK_DENIED = new ErrorTag("lock-denied");
80 * {@code unknown-element} {@link ErrorTag}. Covers mechanics specified in
81 * <a href="https://www.rfc-editor.org/rfc/rfc6241#page-80">RFC6241, Appendix A, last item</a>. Note the
82 * specification expressly forbids reporting this tag for NETCONF clients older than {@code :base:1.1}.
84 public static final ErrorTag MALFORMED_MESSAGE = new ErrorTag("malformed-message");
86 * {@code missing-attribute} {@link ErrorTag}.
88 public static final ErrorTag MISSING_ATTRIBUTE = new ErrorTag("missing-attribute");
90 * {@code missing-element} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 2
92 * If all keys of a list entry are not present, the server MUST reply
93 * with a "missing-element" error-tag in the rpc-error.
95 * as well as RFC6020 section 7.13.2, paragraph 2
97 * If a leaf in the input tree has a "mandatory" statement with the
98 * value "true", the leaf MUST be present in a NETCONF RPC invocation.
99 * Otherwise, the server MUST return a "missing-element" error.
102 public static final ErrorTag MISSING_ELEMENT = new ErrorTag("missing-element");
104 * {@code operation-failed} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 13.1 through 13.4.
106 public static final ErrorTag OPERATION_FAILED = new ErrorTag("operation-failed");
108 * {@code operation-not-supported} {@link ErrorTag}.
110 public static final ErrorTag OPERATION_NOT_SUPPORTED = new ErrorTag("operation-not-supported");
112 * {@code partial-operation} {@link ErrorTag}.
113 * @deprecated This error-info is obsolete since RFC6241.
115 @Deprecated(since = "RFC6241")
116 public static final ErrorTag PARTIAL_OPERATION = new ErrorTag("partial-operation");
118 * {@code resource-denied} {@link ErrorTag}.
120 public static final ErrorTag RESOURCE_DENIED = new ErrorTag("resource-denied");
122 * {@code rollback-failed} {@link ErrorTag}.
124 public static final ErrorTag ROLLBACK_FAILED = new ErrorTag("rollback-failed");
126 * {@code too-big} {@link ErrorTag}.
128 public static final ErrorTag TOO_BIG = new ErrorTag("too-big");
130 * {@code unknown-element} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 7
132 * If the attributes "before" and "after" appears in any element that
133 * is not a list whose "ordered-by" property is "user", the server
134 * MUST reply with an "unknown-attribute" error-tag in the rpc-error.
137 public static final ErrorTag UNKNOWN_ATTRIBUTE = new ErrorTag("unknown-attribute");
139 * {@code unknown-element} {@link ErrorTag}. Covers mechanics specified in RFC6020 section 8.3.1, bullet 4
141 * If data for a node tagged with "if-feature" is present, and the
142 * feature is not supported by the device, the server MUST reply with
143 * an "unknown-element" error-tag in the rpc-error.
145 * as well as RFC6020 section 8.3.1, bullet 5
147 * If data for a node tagged with "when" is present, and the "when"
148 * condition evaluates to "false", the server MUST reply with an
149 * "unknown-element" error-tag in the rpc-error.
152 public static final ErrorTag UNKNOWN_ELEMENT = new ErrorTag("unknown-element");
154 * {@code unknown-namespace} {@link ErrorTag}.
156 public static final ErrorTag UNKNOWN_NAMESPACE = new ErrorTag("unknown-namespace");
159 private static final long serialVersionUID = 1L;
161 private final String elementBody;
163 public ErrorTag(final String elementBody) {
164 this.elementBody = requireNonNull(elementBody);
168 * Return the XML element body of this object.
170 * @return element body of this object
172 public String elementBody() {
177 public int hashCode() {
178 return elementBody.hashCode();
182 public boolean equals(final @Nullable Object obj) {
183 return obj == this || obj instanceof ErrorTag other && elementBody.equals(other.elementBody);
187 public String toString() {
192 Object writeReplace() {
193 return new ETv1(this);