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