2 * Copyright (c) 2015 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.config.facade.xml.strategy;
11 import java.util.EnumSet;
13 import org.opendaylight.controller.config.facade.xml.exception.OperationNotPermittedException;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
16 public enum EditStrategyType {
19 // additional per element
20 delete, remove, recreate;
22 private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
24 public static EditStrategyType getDefaultStrategy() {
28 public boolean isEnforcing() {
40 throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
44 public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
45 EditStrategyType defaultStrategy) throws OperationNotPermittedException {
46 if (defaultStrategy.isEnforcing()) {
47 if (parsedStrategy != defaultStrategy){
48 throw new OperationNotPermittedException(String.format("With "
50 + " as default-operation operations on module elements are not permitted since the default option is restrictive"),
51 DocumentedException.ErrorType.APPLICATION,
52 DocumentedException.ErrorTag.OPERATION_FAILED,
53 DocumentedException.ErrorSeverity.ERROR);
58 public EditConfigStrategy getFittingStrategy() {
61 return new MergeEditConfigStrategy();
63 return new ReplaceEditConfigStrategy();
65 return new DeleteEditConfigStrategy();
67 return new RemoveEditConfigStrategy();
69 return new ReCreateEditConfigStrategy();
71 return new NoneEditConfigStrategy();
73 throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);