0f19b117983ba11fd4a6197efd1c39b7dddf5f47
[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
9 package org.opendaylight.netconf.test.tool.rpc;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.util.xml.DocumentedException;
13 import org.opendaylight.controller.config.util.xml.XmlElement;
14 import org.opendaylight.controller.config.util.xml.XmlUtil;
15 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
16 import org.opendaylight.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public class SimulatedGet extends AbstractConfigNetconfOperation {
21
22     private final DataList storage;
23
24     public SimulatedGet(final String netconfSessionIdForReporting, final DataList storage) {
25         super(null, netconfSessionIdForReporting);
26         this.storage = storage;
27     }
28
29     @Override
30     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
31             throws DocumentedException {
32         final Element element = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent());
33
34         for (final XmlElement e : storage.getConfigList()) {
35             final Element domElement = e.getDomElement();
36             element.appendChild(element.getOwnerDocument().importNode(domElement, true));
37         }
38
39         return element;
40     }
41
42     @Override
43     protected String getOperationName() {
44         return XmlNetconfConstants.GET;
45     }
46 }