2 * Copyright (c) 2015, 2017 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> DEFAULT_STRATS = EnumSet.of(merge, replace, none);
24 public static EditStrategyType getDefaultStrategy() {
28 public boolean isEnforcing() {
40 throw new IllegalStateException(
41 "Default edit strategy can be only of value " + DEFAULT_STRATS + " but was " + this);
45 public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
46 EditStrategyType defaultStrategy) throws OperationNotPermittedException {
47 if (defaultStrategy.isEnforcing()) {
48 if (parsedStrategy != defaultStrategy) {
49 throw new OperationNotPermittedException("With " + defaultStrategy
50 + " as default-operation operations on module elements are not permitted since the default "
51 + "option is restrictive",
52 DocumentedException.ErrorType.APPLICATION,
53 DocumentedException.ErrorTag.OPERATION_FAILED,
54 DocumentedException.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 ReCreateEditConfigStrategy();
72 return new NoneEditConfigStrategy();
74 throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);