Separate out ReadDataParams
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / ContentParam.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 org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14
15 /**
16  * Enumeration of possible {@code content} values as defined by
17  * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.1">RFC8040, section 4.8.1</a>.
18  */
19 public enum ContentParam implements RestconfQueryParam<ContentParam> {
20     /**
21      * Return all descendant data nodes.
22      */
23     ALL("all"),
24     /**
25      * Return only configuration descendant data nodes.
26      */
27     CONFIG("config"),
28     /**
29      * Return only non-configuration descendant data nodes.
30      */
31     NONCONFIG("nonconfig");
32
33     private final @NonNull String uriValue;
34
35     ContentParam(final String uriValue) {
36         this.uriValue = requireNonNull(uriValue);
37     }
38
39     @Override
40     public final Class<@NonNull ContentParam> javaClass() {
41         return ContentParam.class;
42     }
43
44     @Override
45     public final String paramName() {
46         return uriName();
47     }
48
49     @Override
50     public String paramValue() {
51         return uriValue;
52     }
53
54     public static @NonNull String uriName() {
55         return "content";
56     }
57
58     // Note: returns null of unknowns
59     public static @Nullable ContentParam forUriValue(final String uriValue) {
60         switch (uriValue) {
61             case "all":
62                 return ALL;
63             case "config":
64                 return CONFIG;
65             case "nonconfig":
66                 return NONCONFIG;
67             default:
68                 return null;
69         }
70     }
71 }