Expose parameter names as String constants
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / WithDefaultsParam.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.restconf.nb.rfc8040;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.net.URI;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * Enumeration of possible {@code with-defaults} parameter values as defined by
18  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.9">RFC8040, section 4.8.9</a>.
19  */
20 public enum WithDefaultsParam implements RestconfQueryParam<WithDefaultsParam> {
21     /**
22      * Data nodes set to the YANG default by the client are reported.
23      */
24     EXPLICIT("explicit"),
25     /**
26      * All data nodes are reported.
27      */
28     REPORT_ALL("report-all"),
29     /**
30      * All data nodes are reported, and defaults are tagged.
31      */
32     REPORT_ALL_TAGGED("report-all-tagged"),
33     /**
34      * Data nodes set to the YANG default are not reported.
35      */
36     TRIM("trim");
37
38     // API consistency: must not be confused with enum constants
39     @SuppressWarnings("checkstyle:ConstantName")
40     public static final @NonNull String uriName = "with-defaults";
41
42     private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:with-defaults:1.0");
43
44     private final @NonNull String uriValue;
45
46     WithDefaultsParam(final String uriValue) {
47         this.uriValue = requireNonNull(uriValue);
48     }
49
50     @Override
51     public Class<@NonNull WithDefaultsParam> javaClass() {
52         return WithDefaultsParam.class;
53     }
54
55     @Override
56     public String paramName() {
57         return uriName;
58     }
59
60     @Override
61     public String paramValue() {
62         return uriValue;
63     }
64
65     public static @Nullable WithDefaultsParam forUriValue(final String uriValue) {
66         switch (uriValue) {
67             case "explicit":
68                 return EXPLICIT;
69             case "report-all":
70                 return REPORT_ALL;
71             case "report-all-tagged":
72                 return REPORT_ALL_TAGGED;
73             case "trim":
74                 return TRIM;
75             default:
76                 return null;
77         }
78     }
79
80     public static @NonNull URI capabilityUri() {
81         return CAPABILITY;
82     }
83 }