Migrate netconf-console to Karaf 4 way
[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.api.xml.XmlUtil;
13 import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
14 import org.w3c.dom.Document;
15 import org.w3c.dom.Element;
16
17 public class SimulatedGet extends AbstractLastNetconfOperation {
18
19     private final DataList storage;
20
21     public SimulatedGet(final String netconfSessionIdForReporting, final DataList storage) {
22         super(netconfSessionIdForReporting);
23         this.storage = storage;
24     }
25
26     @Override
27     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
28         final Element element = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY);
29
30         for (final XmlElement e : storage.getConfigList()) {
31             final Element domElement = e.getDomElement();
32             element.appendChild(element.getOwnerDocument().importNode(domElement, true));
33         }
34
35         return element;
36     }
37
38     @Override
39     protected String getOperationName() {
40         return XmlNetconfConstants.GET;
41     }
42 }