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.api.xml.XmlUtil;
14 import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
15 import org.w3c.dom.Attr;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
19 public class SimulatedEditConfig extends AbstractLastNetconfOperation {
20 private static final String DELETE_EDIT_CONFIG = "delete";
21 private static final String OPERATION = "operation";
22 private static final String REMOVE_EDIT_CONFIG = "remove";
23 private final DataList storage;
25 public SimulatedEditConfig(final String netconfSessionIdForReporting, final DataList storage) {
26 super(netconfSessionIdForReporting);
27 this.storage = storage;
31 protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
32 throws DocumentedException {
33 final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY);
35 containsDelete(configElementData);
36 if (containsDelete(configElementData)) {
37 storage.resetConfigList();
39 storage.setConfigList(configElementData.getChildElements());
42 return XmlUtil.createElement(document, XmlNetconfConstants.OK);
46 protected String getOperationName() {
50 private boolean containsDelete(final XmlElement element) {
51 for (final Attr o : element.getAttributes().values()) {
52 if (o.getLocalName().equals(OPERATION)
53 && (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue()
54 .equals(REMOVE_EDIT_CONFIG))) {
60 for (final XmlElement xmlElement : element.getChildElements()) {
61 if (containsDelete(xmlElement)) {