0ee9956b6023c6cc7a50b2ed26c29caedbf33b09
[netconf.git] / netconf / netconf-api / src / main / java / org / opendaylight / netconf / api / ModifyAction.java
1 /*
2  * Copyright (c) 2019 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.netconf.api;
9
10 import java.util.Arrays;
11
12 public enum ModifyAction {
13     MERGE(true), REPLACE(true), CREATE(false), DELETE(false), REMOVE(false), NONE(true, false);
14
15     public static ModifyAction fromXmlValue(final String xmlNameOfAction) {
16         switch (xmlNameOfAction) {
17             case "merge":
18                 return MERGE;
19             case "replace":
20                 return REPLACE;
21             case "remove":
22                 return REMOVE;
23             case "delete":
24                 return DELETE;
25             case "create":
26                 return CREATE;
27             case "none":
28                 return NONE;
29             default:
30                 throw new IllegalArgumentException("Unknown operation " + xmlNameOfAction + " available operations "
31                         + Arrays.toString(ModifyAction.values()));
32         }
33     }
34
35     private final boolean asDefaultPermitted;
36     private final boolean onElementPermitted;
37
38     ModifyAction(final boolean asDefaultPermitted, final boolean onElementPermitted) {
39         this.asDefaultPermitted = asDefaultPermitted;
40         this.onElementPermitted = onElementPermitted;
41     }
42
43     ModifyAction(final boolean asDefaultPermitted) {
44         this(asDefaultPermitted, true);
45     }
46
47     /**
48      * Check if this operation is a candidate for {@code default-operation} argument.
49      *
50      * @return True if this operation can be used as {@code default-operation}.
51      */
52     public boolean isAsDefaultPermitted() {
53         return asDefaultPermitted;
54     }
55
56     public boolean isOnElementPermitted() {
57         return onElementPermitted;
58     }
59 }