2 * Copyright (c) 2013 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.netconf.confignetconfconnector.operations.getconfig;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
13 import org.opendaylight.controller.config.facade.xml.Datastore;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
15 import org.opendaylight.controller.config.util.xml.XmlElement;
16 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
17 import org.opendaylight.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
23 public class GetConfig extends AbstractConfigNetconfOperation {
25 public static final String GET_CONFIG = "get-config";
27 private final Optional<String> maybeNamespace;
29 private static final Logger LOG = LoggerFactory.getLogger(GetConfig.class);
31 public GetConfig(final ConfigSubsystemFacade configSubsystemFacade, final Optional<String> maybeNamespace, final String netconfSessionIdForReporting) {
32 super(configSubsystemFacade, netconfSessionIdForReporting);
33 this.maybeNamespace = maybeNamespace;
36 public static Datastore fromXml(XmlElement xml) throws DocumentedException {
38 xml.checkName(GET_CONFIG);
39 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
41 XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY,
42 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
43 XmlElement sourceNode = sourceElement.getOnlyChildElement();
44 String sourceParsed = sourceNode.getName();
45 LOG.debug("Setting source datastore to '{}'", sourceParsed);
47 // Filter option: ignore for now, TODO only load modules specified by the filter
49 return Datastore.valueOf(sourceParsed);
54 protected String getOperationName() {
59 public Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws DocumentedException {
60 return getConfigSubsystemFacade().getConfiguration(document, fromXml(xml), maybeNamespace);