+ public synchronized DOMNotification toNotification(final NetconfMessage message) {
+ final Map.Entry<Date, XmlElement> stripped = stripNotification(message);
+ final QName notificationNoRev;
+ try {
+ // How to construct QName with no revision ?
+ notificationNoRev = QName.cachedReference(QName.create(stripped.getValue().getNamespace(), "0000-00-00", stripped.getValue().getName()).withoutRevision());
+ } catch (final MissingNameSpaceException e) {
+ throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e);
+ }
+
+ final Collection<NotificationDefinition> notificationDefinitions = mappedNotifications.get(notificationNoRev);
+ Preconditions.checkArgument(notificationDefinitions.size() > 0,
+ "Unable to parse notification %s, unknown notification. Available notifications: %s", notificationDefinitions, mappedNotifications.keySet());
+
+ // FIXME if multiple revisions for same notifications are present, we should pick the most recent. Or ?
+ // We should probably just put the most recent notification versions into our map. We can expect that the device sends the data according to the latest available revision of a model.
+ final NotificationDefinition next = notificationDefinitions.iterator().next();
+
+ // We wrap the notification as a container node in order to reuse the parsers and builders for container node
+ final ContainerSchemaNode notificationAsContainerSchemaNode = NetconfMessageTransformUtil.createSchemaForNotification(next);
+ final ContainerNode content = parserFactory.getContainerNodeParser().parse(Collections.singleton(stripped.getValue().getDomElement()),
+ notificationAsContainerSchemaNode);
+ return new NetconfDeviceNotification(content, stripped.getKey());
+ }
+
+ // FIXME move somewhere to util
+ private static Map.Entry<Date, XmlElement> stripNotification(final NetconfMessage message) {
+ final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument());
+ final List<XmlElement> childElements = xmlElement.getChildElements();
+ Preconditions.checkArgument(childElements.size() == 2, "Unable to parse notification %s, unexpected format", message);
+
+ final XmlElement eventTimeElement;
+ final XmlElement notificationElement;
+
+ if (childElements.get(0).getName().equals(EVENT_TIME)) {
+ eventTimeElement = childElements.get(0);
+ notificationElement = childElements.get(1);
+ }
+ else if(childElements.get(1).getName().equals(EVENT_TIME)) {
+ eventTimeElement = childElements.get(1);
+ notificationElement = childElements.get(0);