Merge "Added support for persistance of service references to netconf."
[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 //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     public static EditStrategyType getDefaultStrategy() {
26         return merge;
27     }
28
29     public boolean isEnforcing() {
30         switch (this) {
31         case merge:
32         case none:
33         case remove:
34         case delete:
35             return false;
36         case replace:
37             return true;
38
39         default:
40             throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
41                     + this);
42         }
43     }
44
45     public EditConfigStrategy getFittingStrategy(Multimap<String, String> providedServices) {
46         switch (this) {
47         case merge:
48             return new MergeEditConfigStrategy(providedServices);
49         case replace:
50             return new ReplaceEditConfigStrategy(providedServices);
51         case delete:
52             return new DeleteEditConfigStrategy(providedServices);
53         case remove:
54             return new RemoveEditConfigStrategy();
55         case none:
56             return new NoneEditConfigStrategy();
57         default:
58             throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);
59         }
60     }
61 }