use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class NetconfDeviceRpcTest method resolveNode.
private static Node resolveNode(final DOMRpcResult result) {
DataContainerChild value = ((ContainerNode) result.getResult()).findChildByArg(NetconfMessageTransformUtil.NETCONF_DATA_NODEID).get();
Node node = ((DOMSourceAnyxmlNode) value).body().getNode();
assertNotNull(node);
return node;
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class NetconfRemoteSchemaYangSourceProvider method getSchemaFromRpc.
private static Optional<String> getSchemaFromRpc(final RemoteDeviceId id, final NormalizedNode result) {
if (result == null) {
return Optional.empty();
}
final Optional<DataContainerChild> child = ((ContainerNode) result).findChildByArg(NETCONF_DATA_PATHARG);
checkState(child.isPresent() && child.get() instanceof DOMSourceAnyxmlNode, "%s Unexpected response to get-schema, expected response with one child %s, but was %s", id, NETCONF_DATA, result);
final DOMSource wrappedNode = ((DOMSourceAnyxmlNode) child.get()).body();
final Element dataNode = (Element) requireNonNull(wrappedNode.getNode());
return Optional.of(dataNode.getTextContent().trim());
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class BaseRpcSchemalessTransformer method toRpcResult.
@Override
public DOMRpcResult toRpcResult(final NetconfMessage message, final QName rpc) {
final NormalizedNode normalizedNode;
if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) {
final Element xmlData = NetconfMessageTransformUtil.getDataSubtree(message.getDocument());
final Document data = XmlUtil.newDocument();
data.appendChild(data.importNode(xmlData, true));
DOMSourceAnyxmlNode xmlDataNode = Builders.anyXmlBuilder().withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_DATA_NODEID).withValue(new DOMSource(data)).build();
normalizedNode = Builders.containerBuilder().withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID).withChild(xmlDataNode).build();
} 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, message);
normalizedNode = null;
}
return new DefaultDOMRpcResult(normalizedNode);
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class NetconfMessageTransformUtil method createEditConfigAnyxml.
/**
* Create edit-config structure to invoke {@code operation} with {@code lastChildOverride} data on {@code dataPath}.
*
* @param ctx {@link EffectiveModelContext} device's model context
* @param dataPath {@link YangInstanceIdentifier} path to data in device's data-store
* @param operation Optional of {@link ModifyAction} action to be invoked
* @param lastChildOverride Optional of {@code NormalizedNode} data on which action will be invoked
* @return {@link DOMSourceAnyxmlNode} containing edit-config structure
*/
public static DOMSourceAnyxmlNode createEditConfigAnyxml(final EffectiveModelContext ctx, final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation, final Optional<NormalizedNode> lastChildOverride) {
if (dataPath.isEmpty()) {
Preconditions.checkArgument(lastChildOverride.isPresent(), "Data has to be present when creating structure for top level element");
Preconditions.checkArgument(lastChildOverride.get() instanceof DataContainerChild, "Data has to be either container or a list node when creating structure for top level element, " + "but was: %s", lastChildOverride.get());
}
final var element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(), Optional.of(NETCONF_CONFIG_QNAME.getNamespace().toString()));
final var metadata = operation.map(o -> leafMetadata(dataPath, o)).orElse(null);
try {
if (lastChildOverride.isPresent()) {
// FIXME remove ImmutableNodes.fromInstanceId usage
final var configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride.get());
NetconfUtil.writeNormalizedNode(configContent, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
} else {
NetconfUtil.writeNormalizedNode(dataPath, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
}
} catch (final IOException | XMLStreamException e) {
throw new IllegalStateException("Unable to serialize edit config content element for path " + dataPath, e);
}
return Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_CONFIG_NODEID).withValue(new DOMSource(element)).build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessRpcStructureTransformer method selectFromDataStructure.
/**
* Selects elements in anyxml data node, which matches path arguments QNames. Since class in not context aware,
* method searches for all elements as they are named in path.
* @param data data, must be of type {@link DOMSourceAnyxmlNode}
* @param path path to select
* @return selected data
*/
@Override
public Optional<NormalizedNode> selectFromDataStructure(final DataContainerChild data, final YangInstanceIdentifier path) {
Preconditions.checkArgument(data instanceof DOMSourceAnyxmlNode);
final List<XmlElement> xmlElements = selectMatchingNodes(getSourceElement(((DOMSourceAnyxmlNode) data).body()), path);
final Document result = XmlUtil.newDocument();
final Element dataElement = result.createElementNS(NETCONF_DATA_QNAME.getNamespace().toString(), NETCONF_DATA_QNAME.getLocalName());
result.appendChild(dataElement);
for (XmlElement xmlElement : xmlElements) {
dataElement.appendChild(result.importNode(xmlElement.getDomElement(), true));
}
final DOMSourceAnyxmlNode resultAnyxml = Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_DATA_NODEID).withValue(new DOMSource(result)).build();
return Optional.of(resultAnyxml);
}
Aggregations