Merge "ModifAction enum added NONE operation + additional checks Added Modify Action...
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / ModifyAction.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.yangtools.yang.data.api;\r
9 \r
10 import java.util.Arrays;\r
11 \r
12 // TODO rename to ModifyOperation\r
13 \r
14 /**\r
15  * http://tools.ietf.org/html/rfc6241#section-7.2\r
16  */\r
17 public enum ModifyAction {\r
18     MERGE, REPLACE, CREATE, DELETE, REMOVE, NONE;\r
19 \r
20     public static ModifyAction fromXmlValue(String xmlNameOfAction) {\r
21         switch (xmlNameOfAction) {\r
22         case "merge":\r
23             return MERGE;\r
24         case "replace":\r
25             return REPLACE;\r
26         case "remove":\r
27             return REMOVE;\r
28         case "delete":\r
29             return DELETE;\r
30         case "create":\r
31             return CREATE;\r
32         case "none":\r
33             return NONE;\r
34         default:\r
35             throw new IllegalArgumentException("Unknown operation " + xmlNameOfAction + " available operations "\r
36                     + Arrays.toString(ModifyAction.values()));\r
37         }\r
38     }\r
39 \r
40     public boolean isAsDefaultPermitted() {\r
41         boolean isPermitted = this == MERGE;\r
42         isPermitted |= this == REPLACE;\r
43         isPermitted |= this == NONE;\r
44         return isPermitted;\r
45     }\r
46 \r
47     public boolean isOnElementPermitted() {\r
48         return this != NONE;\r
49     }\r
50 \r
51 }\r