cfeddcdb3aa85675128bd5f0f975d64a2ea83222
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / ops / AbstractConfigOperation.java
1 /*
2  * Copyright (c) 2018 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.mdsal.connector.ops;
10
11 import com.google.common.base.Strings;
12 import org.opendaylight.netconf.api.DocumentedException;
13 import org.opendaylight.netconf.api.xml.XmlElement;
14 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
15 import org.w3c.dom.Element;
16 import org.w3c.dom.NodeList;
17
18 abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation {
19
20     protected AbstractConfigOperation(final String netconfSessionIdForReporting) {
21         super(netconfSessionIdForReporting);
22     }
23
24     protected static NodeList getElementsByTagName(final XmlElement parent, final String key) throws
25         DocumentedException {
26         final Element domParent = parent.getDomElement();
27         final NodeList elementsByTagName;
28
29         if (Strings.isNullOrEmpty(domParent.getPrefix())) {
30             elementsByTagName = domParent.getElementsByTagName(key);
31         } else {
32             elementsByTagName = domParent.getElementsByTagNameNS(parent.getNamespace(), key);
33         }
34
35         return elementsByTagName;
36     }
37 }