Fix config-netconf-connector needed for interacting with yuma's yangcli.
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / editconfig / EditStrategyType.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
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
10
11 import java.util.EnumSet;
12 import java.util.Set;
13
14 import com.google.common.base.Preconditions;
15
16 //FIXME: make thread safe
17 public enum EditStrategyType {
18     // can be default
19     merge, replace, none,
20     // additional per element
21     delete, remove;
22
23     private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
24
25     private static EditStrategyType defaultStrat = merge;
26
27     public static EditStrategyType defaultStrategy() {
28         return defaultStrat;
29     }
30
31     public static void setDefaultStrategy(EditStrategyType strat) {
32         Preconditions.checkArgument(strat.canBeDefault(), "Default edit strategy can be only of value " + defaultStrats
33                 + ", but was " + strat);
34         defaultStrat = strat;
35     }
36
37     public static void resetDefaultStrategy() {
38         setDefaultStrategy(EditStrategyType.merge);
39     }
40
41     public boolean isEnforcing() {
42         switch (this) {
43         case merge:
44         case none:
45         case remove:
46         case delete:
47             return false;
48         case replace:
49             return true;
50
51         default:
52             throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
53                     + this);
54         }
55     }
56
57     private static final EnumSet<EditStrategyType> defaults;
58
59     static {
60         defaults = EnumSet.of(merge, replace, none);
61     }
62
63     private boolean canBeDefault() {
64         return defaults.contains(this);
65     }
66
67     public EditConfigStrategy getFittingStrategy() {
68         switch (this) {
69         case merge:
70             return new MergeEditConfigStrategy();
71         case replace:
72             return new ReplaceEditConfigStrategy();
73         case delete:
74             return new DeleteEditConfigStrategy();
75         case remove:
76             return new RemoveEditConfigStrategy();
77         case none:
78             return new NoneEditConfigStrategy();
79         default:
80             throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);
81         }
82     }
83 }