package org.opendaylight.controller.netconf.util.mapping;
+import com.google.common.base.Optional;
import java.util.Map;
-
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import com.google.common.base.Optional;
-
public abstract class AbstractNetconfOperation implements NetconfOperation {
private final String netconfSessionIdForReporting;
- private static final Logger logger = LoggerFactory.getLogger(AbstractNetconfOperation.class);
- protected AbstractNetconfOperation(String netconfSessionIdForReporting) {
+ protected AbstractNetconfOperation(final String netconfSessionIdForReporting) {
this.netconfSessionIdForReporting = netconfSessionIdForReporting;
}
}
@Override
- public HandlingPriority canHandle(Document message) throws NetconfDocumentedException {
+ public HandlingPriority canHandle(final Document message) throws DocumentedException {
OperationNameAndNamespace operationNameAndNamespace = null;
operationNameAndNamespace = new OperationNameAndNamespace(message);
return canHandle(operationNameAndNamespace.getOperationName(), operationNameAndNamespace.getNamespace());
public static final class OperationNameAndNamespace {
private final String operationName, namespace;
+ private final XmlElement operationElement;
- public OperationNameAndNamespace(Document message) throws NetconfDocumentedException {
+ public OperationNameAndNamespace(final Document message) throws DocumentedException {
XmlElement requestElement = null;
requestElement = getRequestElementWithCheck(message);
-
- XmlElement operationElement = requestElement.getOnlyChildElement();
+ operationElement = requestElement.getOnlyChildElement();
operationName = operationElement.getName();
namespace = operationElement.getNamespace();
}
public String getNamespace() {
return namespace;
}
+
+ public XmlElement getOperationElement() {
+ return operationElement;
+ }
}
- protected static XmlElement getRequestElementWithCheck(Document message) throws NetconfDocumentedException {
+ protected static XmlElement getRequestElementWithCheck(final Document message) throws DocumentedException {
return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY,
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
}
- protected HandlingPriority canHandle(String operationName, String operationNamespace) {
+ protected HandlingPriority canHandle(final String operationName, final String operationNamespace) {
return operationName.equals(getOperationName()) && operationNamespace.equals(getOperationNamespace())
? getHandlingPriority()
: HandlingPriority.CANNOT_HANDLE;
protected abstract String getOperationName();
@Override
- public Document handle(Document requestMessage,
- NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
+ public Document handle(final Document requestMessage,
+ final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
XmlElement requestElement = getRequestElementWithCheck(requestMessage);
Map<String, Attr> attributes = requestElement.getAttributes();
Element response = handle(document, operationElement, subsequentOperation);
- Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+ Element rpcReply = XmlUtil.createElement(document, XmlMappingConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
if(XmlElement.fromDomElement(response).hasNamespace()) {
rpcReply.appendChild(response);
rpcReply.appendChild(responseNS);
}
- for (String attrName : attributes.keySet()) {
- rpcReply.setAttributeNode((Attr) document.importNode(attributes.get(attrName), true));
+ for (Attr attribute : attributes.values()) {
+ rpcReply.setAttributeNode((Attr) document.importNode(attribute, true));
}
document.appendChild(rpcReply);
return document;
}
protected abstract Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation)
- throws NetconfDocumentedException;
+ throws DocumentedException;
@Override
public String toString() {