2 * Copyright (c) 2014 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
8 package org.opendaylight.netconf.test.tool.rpc;
10 import org.opendaylight.netconf.api.DocumentedException;
11 import org.opendaylight.netconf.api.xml.XmlElement;
12 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
13 import org.opendaylight.netconf.server.api.operations.AbstractLastNetconfOperation;
14 import org.w3c.dom.Attr;
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
18 public class SimulatedEditConfig extends AbstractLastNetconfOperation {
19 private static final String DELETE_EDIT_CONFIG = "delete";
20 private static final String OPERATION = "operation";
21 private static final String REMOVE_EDIT_CONFIG = "remove";
22 private final DataList storage;
24 public SimulatedEditConfig(final String netconfSessionIdForReporting, final DataList storage) {
25 super(netconfSessionIdForReporting);
26 this.storage = storage;
30 protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
31 throws DocumentedException {
32 final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY);
34 containsDelete(configElementData);
35 if (containsDelete(configElementData)) {
36 storage.resetConfigList();
38 storage.setConfigList(configElementData.getChildElements());
41 return document.createElement(XmlNetconfConstants.OK);
45 protected String getOperationName() {
49 private boolean containsDelete(final XmlElement element) {
50 for (final Attr o : element.getAttributes().values()) {
51 if (o.getLocalName().equals(OPERATION)
52 && (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue()
53 .equals(REMOVE_EDIT_CONFIG))) {
59 for (final XmlElement xmlElement : element.getChildElements()) {
60 if (containsDelete(xmlElement)) {