Merge "Bug 164"
[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 //FIXME: make thread safe
15 public enum EditStrategyType {
16     // can be default
17     merge, replace, none,
18     // additional per element
19     delete, remove;
20
21     private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
22
23     public static EditStrategyType getDefaultStrategy() {
24         return merge;
25     }
26
27     public boolean isEnforcing() {
28         switch (this) {
29         case merge:
30         case none:
31         case remove:
32         case delete:
33             return false;
34         case replace:
35             return true;
36
37         default:
38             throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
39                     + this);
40         }
41     }
42
43     public EditConfigStrategy getFittingStrategy() {
44         switch (this) {
45         case merge:
46             return new MergeEditConfigStrategy();
47         case replace:
48             return new ReplaceEditConfigStrategy();
49         case delete:
50             return new DeleteEditConfigStrategy();
51         case remove:
52             return new RemoveEditConfigStrategy();
53         case none:
54             return new NoneEditConfigStrategy();
55         default:
56             throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);
57         }
58     }
59 }