import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.MessageCounter;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
}
@Override
- public NetconfMessage toRpcRequest(final SchemaPath rpc, final NormalizedNode<?, ?> payload) {
+ public NetconfMessage toRpcRequest(final QName rpc, final NormalizedNode<?, ?> payload) {
// In case no input for rpc is defined, we can simply construct the payload here
- final QName rpcQName = rpc.getLastComponent();
- final RpcDefinition mappedRpc = Preconditions.checkNotNull(mappedRpcs.get(rpcQName),
- "Unknown rpc %s, available rpcs: %s", rpcQName, mappedRpcs.keySet());
- final DOMResult domResult = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpcQName, counter);
+ final RpcDefinition mappedRpc = Preconditions.checkNotNull(mappedRpcs.get(rpc),
+ "Unknown rpc %s, available rpcs: %s", rpc, mappedRpcs.keySet());
+ final DOMResult domResult = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter);
if (mappedRpc.getInput().getChildNodes().isEmpty()) {
return new NetconfMessage(domResult.getNode().getOwnerDocument());
}
- Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpcQName);
+ Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpc);
Preconditions.checkArgument(payload instanceof ContainerNode,
- "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpcQName, payload);
+ "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpc, payload);
- // Set the path to the input of rpc for the payload stream writer
- final SchemaPath inputPath = rpc.createChild(YangConstants.operationInputQName(rpcQName.getModule()));
final DOMResult result = domResult;
-
try {
- NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, inputPath, modelContext);
+ NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, Absolute.of(rpc),
+ modelContext);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
- throw new IllegalStateException("Unable to serialize " + inputPath, e);
+ throw new IllegalStateException("Unable to serialize input of " + rpc, e);
}
final Document node = result.getNode().getOwnerDocument();
}
@Override
- public DOMRpcResult toRpcResult(final NetconfMessage message, final SchemaPath rpc) {
+ public DOMRpcResult toRpcResult(final NetconfMessage message, final QName rpc) {
final NormalizedNode<?, ?> normalizedNode;
- final QName rpcQName = rpc.getLastComponent();
- if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpcQName)) {
+ if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) {
final Element xmlData = NetconfMessageTransformUtil.getDataSubtree(message.getDocument());
final Document data = XmlUtil.newDocument();
data.appendChild(data.importNode(xmlData, true));
} else {
//other base rpcs don't have any output, we can simply construct the payload here
Preconditions.checkArgument(isOkPresent(message.getDocument()),
- "Unexpected content in response of rpc: %s, %s", rpc.getLastComponent(), message);
+ "Unexpected content in response of rpc: %s, %s", rpc, message);
normalizedNode = null;
}