- public NetconfMessage toRpcRequest(final QName rpc, final CompositeNode node) {
- final CompositeNodeTOImpl rpcPayload = NetconfMessageTransformUtil.wrap(
- NetconfMessageTransformUtil.NETCONF_RPC_QNAME, NetconfMessageTransformUtil.flattenInput(node));
- final Document w3cPayload;
+ public NetconfMessage toRpcRequest(SchemaPath rpc, final NormalizedNode<?, ?> payload) {
+ // In case no input for rpc is defined, we can simply construct the payload here
+ final QName rpcQName = rpc.getLastComponent();
+ Map<QName, RpcDefinition> currentMappedRpcs = mappedRpcs;
+
+ // Determine whether a base netconf operation is being invoked and also check if the device exposed model for base netconf
+ // If no, use pre built base netconf operations model
+ final boolean needToUseBaseCtx = mappedRpcs.get(rpcQName) == null && isBaseRpc(rpcQName);
+ if(needToUseBaseCtx) {
+ currentMappedRpcs = MAPPED_BASE_RPCS;
+ }
+
+ Preconditions.checkNotNull(currentMappedRpcs.get(rpcQName), "Unknown rpc %s, available rpcs: %s", rpcQName, currentMappedRpcs.keySet());
+ if(currentMappedRpcs.get(rpcQName).getInput() == null) {
+ final Document document = XmlUtil.newDocument();
+ final Element elementNS = document.createElementNS(rpcQName.getNamespace().toString(), rpcQName.getLocalName());
+ document.appendChild(elementNS);
+ return new NetconfMessage(document);
+ }
+
+ Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpcQName);
+ Preconditions.checkArgument(payload instanceof ContainerNode,
+ "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpcQName, payload);
+
+ // Set the path to the input of rpc for the node stream writer
+ rpc = rpc.createChild(QName.cachedReference(QName.create(rpcQName, "input")));
+ final DOMResult result = prepareDomResultForRpcRequest(rpcQName);
+