Remove CursorAwareDataTreeSnapshot.createCursor()
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / ModifyAction.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.data.api;
9
10 import java.util.Arrays;
11
12 /**
13  * Edit operation, as defined by <a href="https://tools.ietf.org/html/rfc6241#section-7.2">RFC6241 section 7.2</a>.
14  */
15 // FIXME: 3.0.0: rename to EditOperation, consider remodeling to take into account MERGE/REPLACE/NONE versus
16 //               CREATE/DELETE/REMOVE.
17 public enum ModifyAction {
18     MERGE(true), REPLACE(true), CREATE(false), DELETE(false), REMOVE(false), NONE(true, false);
19
20     public static ModifyAction fromXmlValue(final String xmlNameOfAction) {
21         switch (xmlNameOfAction) {
22             case "merge":
23                 return MERGE;
24             case "replace":
25                 return REPLACE;
26             case "remove":
27                 return REMOVE;
28             case "delete":
29                 return DELETE;
30             case "create":
31                 return CREATE;
32             case "none":
33                 return NONE;
34             default:
35                 throw new IllegalArgumentException("Unknown operation " + xmlNameOfAction + " available operations "
36                         + Arrays.toString(ModifyAction.values()));
37         }
38     }
39
40     private final boolean asDefaultPermitted;
41     private final boolean onElementPermitted;
42
43     ModifyAction(final boolean asDefaultPermitted, final boolean onElementPermitted) {
44         this.asDefaultPermitted = asDefaultPermitted;
45         this.onElementPermitted = onElementPermitted;
46     }
47
48     ModifyAction(final boolean asDefaultPermitted) {
49         this(asDefaultPermitted, true);
50     }
51
52     /**
53      * Check if this operation is a candidate for {@code default-operation} argument.
54      *
55      * @return True if this operation can be used as {@code default-operation}.
56      */
57     // FIXME: 3.0.0: consider moving this somewhere else, or renaming it
58     public boolean isAsDefaultPermitted() {
59         return asDefaultPermitted;
60     }
61
62     public boolean isOnElementPermitted() {
63         return onElementPermitted;
64     }
65 }