*/
package org.opendaylight.netconf.messagebus.eventsources.netconf;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatus;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatusNotification;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
/**
* Topic registration on event-source-status-notification.
*/
+@Deprecated(forRemoval = true)
class ConnectionNotificationTopicRegistration extends NotificationTopicRegistration {
-
private static final Logger LOG = LoggerFactory.getLogger(ConnectionNotificationTopicRegistration.class);
- public static final SchemaPath EVENT_SOURCE_STATUS_PATH = SchemaPath
- .create(true, QName.create(EventSourceStatusNotification.QNAME, "event-source-status"));
+ public static final Absolute EVENT_SOURCE_STATUS_PATH =
+ Absolute.of(QName.create(EventSourceStatusNotification.QNAME, "event-source-status"));
private static final NodeIdentifier EVENT_SOURCE_STATUS_ARG = NodeIdentifier.create(
EventSourceStatusNotification.QNAME);
- private static final String XMLNS_ATTRIBUTE_KEY = "xmlns";
- private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
private final DOMNotificationListener domNotificationListener;
ConnectionNotificationTopicRegistration(final String sourceName,
final DOMNotificationListener domNotificationListener) {
super(NotificationSourceType.ConnectionStatusChange, sourceName,
- EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString());
- this.domNotificationListener = Preconditions.checkNotNull(domNotificationListener);
+ EVENT_SOURCE_STATUS_PATH.lastNodeIdentifier().getNamespace().toString());
+ this.domNotificationListener = requireNonNull(domNotificationListener);
LOG.info("Connection notification source has been initialized.");
setActive(true);
setReplaySupported(false);
DOMNotification dn = new DOMNotification() {
@Override
- public SchemaPath getType() {
+ public Absolute getType() {
return EVENT_SOURCE_STATUS_PATH;
}
return dn;
}
- private static AnyXmlNode encapsulate(final EventSourceStatusNotification notification) {
+ private static DOMSourceAnyxmlNode encapsulate(final EventSourceStatusNotification notification) {
Document doc = UntrustedXML.newDocumentBuilder().newDocument();
- final Optional<String> namespace = Optional.of(EVENT_SOURCE_STATUS_ARG.getNodeType().getNamespace().toString());
- final Element rootElement = createElement(doc, "EventSourceStatusNotification", namespace);
+ final Element rootElement = XmlUtil.createElement(doc, "EventSourceStatusNotification",
+ Optional.of(EVENT_SOURCE_STATUS_ARG.getNodeType().getNamespace().toString()));
final Element sourceElement = doc.createElement("status");
sourceElement.appendChild(doc.createTextNode(notification.getStatus().name()));
return Builders.anyXmlBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG)
.withValue(new DOMSource(rootElement)).build();
}
-
- // Helper to create root XML element with correct namespace and attribute
- private static Element createElement(final Document document, final String qualifiedName,
- final Optional<String> namespaceURI) {
- if (namespaceURI.isPresent()) {
- final Element element = document.createElementNS(namespaceURI.get(), qualifiedName);
- String name = XMLNS_ATTRIBUTE_KEY;
- if (element.getPrefix() != null) {
- name += ":" + element.getPrefix();
- }
- element.setAttributeNS(XMLNS_URI, name, namespaceURI.get());
- return element;
- }
- return document.createElement(qualifiedName);
- }
}