2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
11 import com.google.common.collect.Multimap;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.confignetconfconnector.exception.OperationNotPermittedException;
15 import java.util.EnumSet;
18 public enum EditStrategyType {
21 // additional per element
24 private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
26 public static EditStrategyType getDefaultStrategy() {
30 public boolean isEnforcing() {
41 throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
45 public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
46 EditStrategyType defaultStrategy) throws OperationNotPermittedException {
47 if (defaultStrategy.isEnforcing()) {
48 if (parsedStrategy != defaultStrategy){
49 throw new OperationNotPermittedException(String.format("With "
52 + EditConfigXmlParser.DEFAULT_OPERATION_KEY
53 + " operations on module elements are not permitted since the default option is restrictive"),
54 NetconfDocumentedException.ErrorType.application,
55 NetconfDocumentedException.ErrorTag.operation_failed,
56 NetconfDocumentedException.ErrorSeverity.error);
61 public EditConfigStrategy getFittingStrategy(Multimap<String, String> providedServices) {
64 return new MergeEditConfigStrategy(providedServices);
66 return new ReplaceEditConfigStrategy(providedServices);
68 return new DeleteEditConfigStrategy();
70 return new RemoveEditConfigStrategy();
72 return new NoneEditConfigStrategy();
74 throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);