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 java.util.EnumSet;
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
14 import org.opendaylight.controller.netconf.confignetconfconnector.exception.OperationNotPermittedException;
16 public enum EditStrategyType {
19 // additional per element
22 private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
24 public static EditStrategyType getDefaultStrategy() {
28 public boolean isEnforcing() {
39 throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
43 public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
44 EditStrategyType defaultStrategy) throws OperationNotPermittedException {
45 if (defaultStrategy.isEnforcing()) {
46 if (parsedStrategy != defaultStrategy){
47 throw new OperationNotPermittedException(String.format("With "
50 + EditConfigXmlParser.DEFAULT_OPERATION_KEY
51 + " operations on module elements are not permitted since the default option is restrictive"),
52 NetconfDocumentedException.ErrorType.application,
53 NetconfDocumentedException.ErrorTag.operation_failed,
54 NetconfDocumentedException.ErrorSeverity.error);
59 public EditConfigStrategy getFittingStrategy() {
62 return new MergeEditConfigStrategy();
64 return new ReplaceEditConfigStrategy();
66 return new DeleteEditConfigStrategy();
68 return new RemoveEditConfigStrategy();
70 return new NoneEditConfigStrategy();
72 throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);