Deprecate simple DataTreeFactory.create()
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / ErrorSeverity.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.common;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14
15 /**
16  * Enumeration of {@code error-severity} values, as defined by
17  * <a href="https://www.rfc-editor.org/rfc/rfc4741#section-4.3">RFC4741, section 4.3</a>.
18  */
19 @NonNullByDefault
20 public enum ErrorSeverity {
21     /**
22      * An error preventing an operation from completing successfully.
23      */
24     ERROR("error"),
25     /**
26      * A warning not affecting an operation's ability to complete successfully.
27      */
28     WARNING("warning");
29
30     private final String elementBody;
31
32     ErrorSeverity(final String elementBody) {
33         this.elementBody = requireNonNull(elementBody);
34     }
35
36     /**
37      * Return the XML element body of this object.
38      *
39      * @return element body of this object
40      */
41     public String elementBody() {
42         return elementBody;
43     }
44
45     public static @Nullable ErrorSeverity forElementBody(final String elementBody) {
46         return switch (elementBody) {
47             case "error" -> ERROR;
48             case "warning" -> WARNING;
49             default -> null;
50         };
51     }
52 }