2 * Copyright (c) 2019 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.netconf.api;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNull;
15 * NETCONF modification actions, as allowed for in {@code operation} and {@code default-operation} attributes of
16 * {@code <edit-config>} operation, as defined in
17 * <a href="https://www.rfc-editor.org/rfc/rfc6241#section-7.2">RFC6241 section 7.2</a>.
20 * This concept is uncharacteristically bound to two separate semantics, but for a good reason: at the end of the day we
21 * want to know what the effective operation is.
23 public enum ModifyAction {
24 // operation and default-operation
25 MERGE("merge", true, true),
26 REPLACE("replace", true, true),
28 CREATE("create", true, false),
29 DELETE("delete", true, false),
30 REMOVE("remove", true, false),
32 // default-operation-only
33 NONE("none", false, true);
35 private final @NonNull String xmlValue;
36 private final boolean isDefaultOperation;
37 private final boolean isOperation;
39 ModifyAction(final String xmlValue, final boolean isOperation, final boolean isDefaultOperation) {
40 this.xmlValue = requireNonNull(xmlValue);
41 this.isDefaultOperation = isDefaultOperation;
42 this.isOperation = isOperation;
46 * Return the {@link ModifyAction} corresponding to a {@link #xmlValue}.
48 * @param xmlValue XML attribute or element value
49 * @return A {@link ModifyAction}
50 * @throws NullPointerException if {@code xmlValue} is {@code null}
51 * @throws IllegalArgumentException if {@code xmlValue} is not recognized
53 public static @NonNull ModifyAction ofXmlValue(final String xmlValue) {
54 return switch (xmlValue) {
55 case "merge" -> MERGE;
56 case "replace" -> REPLACE;
57 case "remove" -> REMOVE;
58 case "delete" -> DELETE;
59 case "create" -> CREATE;
61 default -> throw new IllegalArgumentException("Unknown operation " + xmlValue);
66 * Return an XML string literal corresponding to this {@link ModifyAction}.
68 * @return An XML string literal
70 public @NonNull String xmlValue() {
75 * Check if this operation is a candidate for {@code default-operation} argument.
77 * @return {@code true} if this operation can be used as {@code default-operation}, {@code false} otherwise.
78 * @deprecated Use {@link #isDefaultOperation()} instead
80 @Deprecated(since = "5.0.0", forRemoval = true)
81 public boolean isAsDefaultPermitted() {
82 return isDefaultOperation;
86 * Check if this operation is a candidate for {@code default-operation} argument.
88 * @return {@code true} if this operation can be used as {@code default-operation}, {@code false} otherwise.
90 public boolean isDefaultOperation() {
91 return isDefaultOperation;
94 @Deprecated(since = "5.0.0", forRemoval = true)
95 public boolean isOnElementPermitted() {
100 * Check if this operation is a candidate for {@code operation} attribute.
102 * @return {@code true} if this operation can be used as {@code operation}, {@code false} otherwise.
104 public boolean isOperation() {