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
9 package org.opendaylight.controller.netconf.test.tool;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
14 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
15 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser;
16 import org.opendaylight.controller.netconf.util.xml.XmlElement;
17 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
18 import org.w3c.dom.Attr;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Element;
22 class SimulatedEditConfig extends AbstractConfigNetconfOperation {
23 private static final String DELETE_EDIT_CONFIG = "delete";
24 private static final String OPERATION = "operation";
25 private static final String REMOVE_EDIT_CONFIG = "remove";
26 private final DataList storage;
28 SimulatedEditConfig(final String netconfSessionIdForReporting, final DataList storage) {
29 super(null, netconfSessionIdForReporting);
30 this.storage = storage;
34 protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException {
35 final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY);
37 containsDelete(configElementData);
38 if(containsDelete(configElementData)){
39 storage.resetConfigList();
41 storage.setConfigList(configElementData.getChildElements());
44 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
48 protected String getOperationName() {
49 return EditConfigXmlParser.EDIT_CONFIG;
52 private boolean containsDelete(final XmlElement element) {
53 for (final Attr o : element.getAttributes().values()) {
54 if (o.getLocalName().equals(OPERATION)
55 && (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue()
56 .equals(REMOVE_EDIT_CONFIG))) {
62 for (final XmlElement xmlElement : element.getChildElements()) {
63 if (containsDelete(xmlElement)) {