2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.client.mdsal.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkNotNull;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.annotations.Beta;
15 import com.google.common.annotations.VisibleForTesting;
16 import com.google.common.collect.ImmutableList;
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.collect.ImmutableSet;
19 import com.google.common.collect.Iterables;
20 import com.google.common.collect.Maps;
21 import com.google.common.collect.Multimap;
22 import com.google.common.collect.Multimaps;
23 import com.google.common.collect.Streams;
24 import java.io.IOException;
25 import java.time.Instant;
26 import java.util.AbstractMap;
27 import java.util.ArrayDeque;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.Deque;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.Map.Entry;
36 import java.util.Optional;
38 import java.util.function.Function;
39 import java.util.stream.Collectors;
40 import javax.xml.stream.XMLStreamException;
41 import javax.xml.transform.dom.DOMResult;
42 import javax.xml.transform.dom.DOMSource;
43 import org.checkerframework.checker.lock.qual.GuardedBy;
44 import org.eclipse.jdt.annotation.NonNull;
45 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
46 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
47 import org.opendaylight.mdsal.dom.api.DOMEvent;
48 import org.opendaylight.mdsal.dom.api.DOMNotification;
49 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
50 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
51 import org.opendaylight.netconf.api.messages.NetconfMessage;
52 import org.opendaylight.netconf.api.xml.MissingNameSpaceException;
53 import org.opendaylight.netconf.api.xml.XmlElement;
54 import org.opendaylight.netconf.client.mdsal.api.ActionTransformer;
55 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchema;
56 import org.opendaylight.netconf.client.mdsal.api.NotificationTransformer;
57 import org.opendaylight.netconf.client.mdsal.api.RpcTransformer;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.GetConfig;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscription;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
61 import org.opendaylight.yangtools.yang.common.QName;
62 import org.opendaylight.yangtools.yang.common.Revision;
63 import org.opendaylight.yangtools.yang.common.RpcResult;
64 import org.opendaylight.yangtools.yang.common.XMLNamespace;
65 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
66 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
67 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
68 import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext;
69 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
70 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
71 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
72 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
73 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
74 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
75 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
76 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
77 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
78 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
79 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
80 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
81 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
82 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
83 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
84 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
85 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
86 import org.opendaylight.yangtools.yang.model.api.Module;
87 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
88 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
89 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
90 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
91 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
92 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
93 import org.slf4j.Logger;
94 import org.slf4j.LoggerFactory;
95 import org.w3c.dom.Document;
96 import org.w3c.dom.Element;
97 import org.w3c.dom.Node;
98 import org.w3c.dom.NodeList;
100 public class NetconfMessageTransformer
101 implements ActionTransformer, NotificationTransformer, RpcTransformer<ContainerNode, DOMRpcResult> {
102 private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageTransformer.class);
104 private static final ImmutableSet<XMLNamespace> BASE_OR_NOTIFICATION_NS = ImmutableSet.of(
105 GetConfig.QNAME.getNamespace(),
106 NetconfCapabilityChange.QNAME.getNamespace(),
107 CreateSubscription.QNAME.getNamespace());
109 private final MountPointContext mountContext;
110 private final DataSchemaContextTree contextTree;
111 private final BaseNetconfSchema baseSchema;
112 private final MessageCounter counter;
113 private final ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
114 private final Multimap<QName, ? extends NotificationDefinition> mappedNotifications;
115 private final boolean strictParsing;
116 private final ImmutableMap<Absolute, ActionDefinition> actions;
118 public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing,
119 final BaseNetconfSchema baseSchema) {
120 counter = new MessageCounter();
121 this.mountContext = requireNonNull(mountContext);
123 final EffectiveModelContext modelContext = mountContext.modelContext();
124 contextTree = DataSchemaContextTree.from(modelContext);
126 mappedRpcs = Maps.uniqueIndex(modelContext.getOperations(), SchemaNode::getQName);
127 actions = getActions(modelContext);
129 // RFC6020 normal notifications
130 mappedNotifications = Multimaps.index(modelContext.getNotifications(),
131 node -> node.getQName().withoutRevision());
132 this.baseSchema = baseSchema;
133 this.strictParsing = strictParsing;
137 static ImmutableMap<Absolute, ActionDefinition> getActions(final EffectiveModelContext schemaContext) {
138 final var builder = ImmutableMap.<Absolute, ActionDefinition>builder();
139 findAction(schemaContext, new ArrayDeque<>(), builder);
140 return builder.build();
143 private static void findAction(final DataSchemaNode dataSchemaNode, final Deque<QName> path,
144 final ImmutableMap.Builder<Absolute, ActionDefinition> builder) {
145 if (dataSchemaNode instanceof ActionNodeContainer) {
146 for (ActionDefinition actionDefinition : ((ActionNodeContainer) dataSchemaNode).getActions()) {
147 path.addLast(actionDefinition.getQName());
148 builder.put(Absolute.of(path), actionDefinition);
152 if (dataSchemaNode instanceof DataNodeContainer) {
153 for (DataSchemaNode innerDataSchemaNode : ((DataNodeContainer) dataSchemaNode).getChildNodes()) {
154 path.addLast(innerDataSchemaNode.getQName());
155 findAction(innerDataSchemaNode, path, builder);
158 } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
159 for (CaseSchemaNode caze : ((ChoiceSchemaNode) dataSchemaNode).getCases()) {
160 path.addLast(caze.getQName());
161 findAction(caze, path, builder);
168 public synchronized DOMNotification toNotification(final NetconfMessage message) {
169 final Entry<Instant, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
170 final QName notificationNoRev;
172 notificationNoRev = QName.create(
173 stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
174 } catch (final MissingNameSpaceException e) {
175 throw new IllegalArgumentException(
176 "Unable to parse notification " + message + ", cannot find namespace", e);
179 final var matchingTopLevel = mappedNotifications.get(notificationNoRev);
180 final var element = stripped.getValue().getDomElement();
181 if (!matchingTopLevel.isEmpty()) {
182 final var notification = getMostRecentNotification(matchingTopLevel);
183 // FIXME: we really should have a pre-constructed identifier here
184 return new NetconfDeviceNotification(toNotification(Absolute.of(notification.getQName()), element),
188 final var nestedInfo = findNestedNotification(message, element)
189 .orElseThrow(() -> new IllegalArgumentException("Unable to parse notification for " + element
190 + ". Available notifications: " + mappedNotifications.keySet()));
191 final var schemaPath = nestedInfo.schemaPath;
192 return new NetconfDeviceTreeNotification(toNotification(schemaPath, nestedInfo.element), schemaPath,
193 stripped.getKey(), nestedInfo.instancePath);
197 private ContainerNode toNotification(final Absolute notificationPath, final Element element) {
198 final NormalizationResultHolder resultHolder = new NormalizationResultHolder();
200 final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
201 final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext,
202 SchemaInferenceStack.of(mountContext.modelContext(), notificationPath).toInference(), strictParsing);
203 xmlParser.traverse(new DOMSource(element));
204 } catch (XMLStreamException | IOException | UnsupportedOperationException e) {
205 throw new IllegalArgumentException(String.format("Failed to parse notification %s", element), e);
207 return (ContainerNode) resultHolder.getResult().data();
210 private Optional<NestedNotificationInfo> findNestedNotification(final NetconfMessage message,
211 final Element element) {
212 final var modules = mountContext.modelContext().findModules(XMLNamespace.of(element.getNamespaceURI()))
214 if (!modules.hasNext()) {
215 throw new IllegalArgumentException(
216 "Unable to parse notification " + message + ", cannot find top level module");
218 final Module module = modules.next();
219 final QName topLevelNodeQName = QName.create(element.getNamespaceURI(), element.getLocalName());
220 for (DataSchemaNode childNode : module.getChildNodes()) {
221 if (topLevelNodeQName.isEqualWithoutRevision(childNode.getQName())) {
222 return Optional.of(traverseXmlNodeContainingNotification(element, childNode, new ArrayList<>(),
223 YangInstanceIdentifier.builder()));
226 return Optional.empty();
229 // FIXME: this method is using QNames which are not bound to a Revision. Why is that?
230 // FIXME: furthermore this does not handle the entirety of schema layout: notably missing a choice/case schema nodes
231 private NestedNotificationInfo traverseXmlNodeContainingNotification(final Node xmlNode,
232 final SchemaNode schemaNode, final List<QName> schemaBuilder,
233 final InstanceIdentifierBuilder instanceBuilder) {
234 if (schemaNode instanceof ContainerSchemaNode containerSchema) {
235 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
236 schemaBuilder.add(containerSchema.getQName());
238 Entry<Node, SchemaNode> xmlContainerChildPair = findXmlContainerChildPair(xmlNode, containerSchema);
239 return traverseXmlNodeContainingNotification(xmlContainerChildPair.getKey(),
240 xmlContainerChildPair.getValue(), schemaBuilder, instanceBuilder);
241 } else if (schemaNode instanceof ListSchemaNode listSchema) {
242 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
243 schemaBuilder.add(listSchema.getQName());
245 Map<QName, Object> listKeys = findXmlListKeys(xmlNode, listSchema);
246 instanceBuilder.nodeWithKey(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()), listKeys);
248 Entry<Node, SchemaNode> xmlListChildPair = findXmlListChildPair(xmlNode, listSchema);
249 return traverseXmlNodeContainingNotification(xmlListChildPair.getKey(),
250 xmlListChildPair.getValue(), schemaBuilder, instanceBuilder);
251 } else if (schemaNode instanceof NotificationDefinition) {
252 // FIXME: this should not be here: it does not form a valid YangInstanceIdentifier
253 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
254 schemaBuilder.add(schemaNode.getQName());
256 return new NestedNotificationInfo(Absolute.of(schemaBuilder),
257 DOMDataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, instanceBuilder.build()), xmlNode);
259 throw new IllegalStateException("No notification found");
262 private static Entry<Node, SchemaNode> findXmlContainerChildPair(final Node xmlNode,
263 final ContainerSchemaNode container) {
264 final NodeList nodeList = xmlNode.getChildNodes();
265 final Map<QName, SchemaNode> childrenWithoutRevision =
266 Streams.concat(container.getChildNodes().stream(), container.getNotifications().stream())
267 .collect(Collectors.toMap(child -> child.getQName().withoutRevision(), Function.identity()));
269 for (int i = 0; i < nodeList.getLength(); i++) {
270 Node currentNode = nodeList.item(i);
271 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
272 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
273 SchemaNode schemaChildNode = childrenWithoutRevision.get(currentNodeQName);
274 if (schemaChildNode != null) {
275 return Map.entry(currentNode, schemaChildNode);
279 throw new IllegalStateException("No container child found.");
282 private static Map<QName, Object> findXmlListKeys(final Node xmlNode, final ListSchemaNode listSchemaNode) {
283 Map<QName, Object> listKeys = new HashMap<>();
284 NodeList nodeList = xmlNode.getChildNodes();
285 Set<QName> keyDefinitionsWithoutRevision = listSchemaNode.getKeyDefinition().stream()
286 .map(QName::withoutRevision).collect(Collectors.toSet());
287 for (int i = 0; i < nodeList.getLength(); i++) {
288 Node currentNode = nodeList.item(i);
289 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
290 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
291 if (keyDefinitionsWithoutRevision.contains(currentNodeQName)) {
292 listKeys.put(currentNodeQName, currentNode.getFirstChild().getNodeValue());
296 if (listKeys.isEmpty()) {
297 throw new IllegalStateException("Notification cannot be contained in list without key statement.");
302 private static Entry<Node, SchemaNode> findXmlListChildPair(final Node xmlNode, final ListSchemaNode list) {
303 final NodeList nodeList = xmlNode.getChildNodes();
304 for (int i = 0; i < nodeList.getLength(); i++) {
305 Node currentNode = nodeList.item(i);
306 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
307 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
308 for (SchemaNode childNode : Iterables.concat(list.getChildNodes(), list.getNotifications())) {
309 if (!list.getKeyDefinition().contains(childNode.getQName())
310 && currentNodeQName.isEqualWithoutRevision(childNode.getQName())) {
311 return new AbstractMap.SimpleEntry<>(currentNode, childNode);
316 throw new IllegalStateException("No list child found.");
319 private static NotificationDefinition getMostRecentNotification(
320 final Collection<? extends NotificationDefinition> notificationDefinitions) {
321 return Collections.max(notificationDefinitions, (o1, o2) ->
322 Revision.compare(o1.getQName().getRevision(), o2.getQName().getRevision()));
326 public NetconfMessage toRpcRequest(final QName rpc, final ContainerNode payload) {
327 // In case no input for rpc is defined, we can simply construct the payload here
329 // Determine whether a base netconf operation is being invoked
330 // and also check if the device exposed model for base netconf.
331 // If no, use pre built base netconf operations model
332 final boolean needToUseBaseCtx = mappedRpcs.get(rpc) == null && isBaseOrNotificationRpc(rpc);
333 final ImmutableMap<QName, ? extends RpcDefinition> currentMappedRpcs;
334 if (needToUseBaseCtx) {
335 currentMappedRpcs = baseSchema.mappedRpcs();
337 currentMappedRpcs = mappedRpcs;
340 final RpcDefinition mappedRpc = checkNotNull(currentMappedRpcs.get(rpc),
341 "Unknown rpc %s, available rpcs: %s", rpc, currentMappedRpcs.keySet());
342 if (mappedRpc.getInput().getChildNodes().isEmpty()) {
343 return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter)
344 .getNode().getOwnerDocument());
347 checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpc);
349 final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter);
351 // If the schema context for netconf device does not contain model for base netconf operations,
352 // use default pre build context with just the base model
353 // This way operations like lock/unlock are supported even if the source for base model was not provided
354 final var modelContext = needToUseBaseCtx ? baseSchema.modelContext() : mountContext.modelContext();
355 NetconfMessageTransformUtil.writeNormalizedOperationInput(payload, result, Absolute.of(rpc), modelContext);
356 } catch (final XMLStreamException | IOException | IllegalStateException e) {
357 throw new IllegalStateException("Unable to serialize input of " + rpc, e);
360 final Document node = result.getNode().getOwnerDocument();
362 return new NetconfMessage(node);
366 public NetconfMessage toActionRequest(final Absolute action, final DOMDataTreeIdentifier domDataTreeIdentifier,
367 final NormalizedNode payload) {
368 final ActionDefinition actionDef = actions.get(action);
369 checkArgument(actionDef != null, "Action does not exist: %s", action);
371 final InputSchemaNode inputDef = actionDef.getInput();
372 if (inputDef.getChildNodes().isEmpty()) {
373 return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree,
374 domDataTreeIdentifier, counter, actionDef.getQName()).getNode().getOwnerDocument());
377 checkNotNull(payload, "Transforming an action with input: %s, payload cannot be null", action);
378 checkArgument(payload instanceof ContainerNode,
379 "Transforming an action with input: %s, payload has to be a container, but was: %s", action, payload);
381 final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree,
382 domDataTreeIdentifier, counter, actionDef.getQName());
384 NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, action,
385 mountContext.modelContext());
386 } catch (final XMLStreamException | IOException | IllegalStateException e) {
387 throw new IllegalStateException("Unable to serialize input of " + action, e);
390 return new NetconfMessage(result.getNode().getOwnerDocument());
393 private static boolean isBaseOrNotificationRpc(final QName rpc) {
394 return BASE_OR_NOTIFICATION_NS.contains(rpc.getNamespace());
398 public synchronized DOMRpcResult toRpcResult(final RpcResult<NetconfMessage> resultPayload, final QName rpc) {
399 if (!resultPayload.isSuccessful()) {
400 return new DefaultDOMRpcResult(resultPayload.getErrors());
403 final var message = resultPayload.getResult();
404 final ContainerNode normalizedNode;
405 if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) {
406 normalizedNode = ImmutableNodes.newContainerBuilder()
407 .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID)
408 .withChild(ImmutableNodes.newAnyxmlBuilder(DOMSource.class)
409 .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_DATA_NODEID)
410 .withValue(new DOMSource(NetconfMessageTransformUtil.getDataSubtree(message.getDocument())))
414 // Determine whether a base netconf operation is being invoked
415 // and also check if the device exposed model for base netconf.
416 // If no, use pre built base netconf operations model
417 final ImmutableMap<QName, ? extends RpcDefinition> currentMappedRpcs;
418 if (mappedRpcs.get(rpc) == null && isBaseOrNotificationRpc(rpc)) {
419 currentMappedRpcs = baseSchema.mappedRpcs();
421 currentMappedRpcs = mappedRpcs;
424 final RpcDefinition rpcDefinition = currentMappedRpcs.get(rpc);
425 checkArgument(rpcDefinition != null, "Unable to parse response of %s, the rpc is unknown", rpc);
427 // In case no input for rpc is defined, we can simply construct the payload here
428 normalizedNode = parseResult(message, Absolute.of(rpc), rpcDefinition);
430 return new DefaultDOMRpcResult(normalizedNode);
434 public DOMRpcResult toActionResult(final Absolute action, final NetconfMessage message) {
435 final ActionDefinition actionDefinition = actions.get(action);
436 checkArgument(actionDefinition != null, "Action does not exist: %s", action);
437 final ContainerNode normalizedNode = parseResult(message, action, actionDefinition);
439 if (normalizedNode == null) {
440 return new DefaultDOMRpcResult(List.of());
442 return new DefaultDOMRpcResult(normalizedNode, List.of());
446 private ContainerNode parseResult(final NetconfMessage message, final Absolute operationPath,
447 final OperationDefinition operationDef) {
448 final Optional<XmlElement> okResponseElement = XmlElement.fromDomDocument(message.getDocument())
449 .getOnlyChildElementWithSameNamespaceOptionally("ok");
450 final var operOutput = operationDef.getOutput();
451 if (operOutput.getChildNodes().isEmpty()) {
452 checkArgument(okResponseElement.isPresent(), "Unexpected content in response of operation: %s, %s",
453 operationDef.getQName(), message);
456 if (okResponseElement.isPresent()) {
457 // FIXME: could be an action as well
458 LOG.debug("Received response <ok/> for RPC with defined Output");
462 final var operSteps = operationPath.getNodeIdentifiers();
463 final var outputPath = Absolute.of(ImmutableList.<QName>builderWithExpectedSize(operSteps.size() + 1)
465 .add(operOutput.getQName())
467 // FIXME: we should have a cached inference here, or XMLParserStream should accept Absolute instead
468 final var inference = SchemaInferenceStack.of(mountContext.modelContext(), outputPath).toInference();
470 final NormalizationResultHolder resultHolder = new NormalizationResultHolder();
471 final Element element = message.getDocument().getDocumentElement();
473 final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
474 final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext, inference, strictParsing);
475 xmlParser.traverse(new DOMSource(element));
476 } catch (XMLStreamException | IOException e) {
477 throw new IllegalArgumentException(String.format("Failed to parse RPC response %s", element), e);
479 return (ContainerNode) resultHolder.getResult().data();
483 public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
484 private final ContainerNode content;
485 private final Absolute schemaPath;
486 private final Instant eventTime;
488 NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
489 this.content = content;
490 this.eventTime = eventTime;
491 schemaPath = Absolute.of(content.name().getNodeType());
494 NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
495 this.content = content;
496 this.eventTime = eventTime;
497 this.schemaPath = schemaPath;
501 public Absolute getType() {
506 public ContainerNode getBody() {
511 public Instant getEventInstant() {
517 public static class NetconfDeviceTreeNotification extends NetconfDeviceNotification {
518 private final DOMDataTreeIdentifier domDataTreeIdentifier;
520 NetconfDeviceTreeNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime,
521 final DOMDataTreeIdentifier domDataTreeIdentifier) {
522 super(content, schemaPath, eventTime);
523 this.domDataTreeIdentifier = domDataTreeIdentifier;
526 public DOMDataTreeIdentifier getDomDataTreeIdentifier() {
527 return domDataTreeIdentifier;
531 private static final class NestedNotificationInfo {
532 final @NonNull DOMDataTreeIdentifier instancePath;
533 final @NonNull Absolute schemaPath;
534 final @NonNull Element element;
536 NestedNotificationInfo(final Absolute schemaPath, final DOMDataTreeIdentifier instancePath,
537 final Node documentNode) {
538 this.schemaPath = requireNonNull(schemaPath);
539 this.instancePath = requireNonNull(instancePath);
540 checkArgument(documentNode instanceof Element, "Unexpected document node %s", documentNode);
541 element = (Element) documentNode;