X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2FSimulatedEditConfig.java;fp=opendaylight%2Fnetconf%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2FSimulatedEditConfig.java;h=e5d068d02c09c7b9bf604edee5b26c0f2b291c60;hp=0000000000000000000000000000000000000000;hb=bfae8a4c16f0fabe4e425aa0849166db1b104671;hpb=5c5b77dab25a38f8b0f9c09dc7aab9420f8dcb48 diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java new file mode 100644 index 0000000000..e5d068d02c --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.test.tool; + +import com.google.common.base.Optional; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +class SimulatedEditConfig extends AbstractConfigNetconfOperation { + private static final String DELETE_EDIT_CONFIG = "delete"; + private static final String OPERATION = "operation"; + private static final String REMOVE_EDIT_CONFIG = "remove"; + private final DataList storage; + + SimulatedEditConfig(final String netconfSessionIdForReporting, final DataList storage) { + super(null, netconfSessionIdForReporting); + this.storage = storage; + } + + @Override + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException { + final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY); + + containsDelete(configElementData); + if(containsDelete(configElementData)){ + storage.resetConfigList(); + } else { + storage.setConfigList(configElementData.getChildElements()); + } + + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); + } + + @Override + protected String getOperationName() { + return EditConfigXmlParser.EDIT_CONFIG; + } + + private boolean containsDelete(final XmlElement element) { + for (final Attr o : element.getAttributes().values()) { + if (o.getLocalName().equals(OPERATION) + && (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue() + .equals(REMOVE_EDIT_CONFIG))) { + return true; + } + + } + + for (final XmlElement xmlElement : element.getChildElements()) { + if (containsDelete(xmlElement)) { + return true; + } + + } + + return false; + } +}