Merge "Eliminate XmlUtil.createElement(Document, String)"
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / rpc / SimulatedGet.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.test.tool.rpc;
9
10 import org.opendaylight.netconf.api.xml.XmlElement;
11 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
12 import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Element;
15
16 public class SimulatedGet extends AbstractLastNetconfOperation {
17
18     private final DataList storage;
19
20     public SimulatedGet(final String netconfSessionIdForReporting, final DataList storage) {
21         super(netconfSessionIdForReporting);
22         this.storage = storage;
23     }
24
25     @Override
26     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
27         final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
28
29         for (final XmlElement e : storage.getConfigList()) {
30             final Element domElement = e.getDomElement();
31             element.appendChild(element.getOwnerDocument().importNode(domElement, true));
32         }
33
34         return element;
35     }
36
37     @Override
38     protected String getOperationName() {
39         return XmlNetconfConstants.GET;
40     }
41 }