Adjust to yangtools-2.0.0/odlparent-3.0.0 changes
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / streams / listeners / ListenerAdapter.java
index 6355769336a213b8d4b927fd9112f38d2ce091a8..2775cce13429085f1000fe0f0ebf2883473e85a5 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.netconf.sal.streams.listeners;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.io.IOException;
 import java.util.Collection;
@@ -52,7 +51,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
     private final String streamName;
     private final NotificationOutputType outputType;
 
-    private Collection<DataTreeCandidate> dataTreeCandidates;
+    private Collection<DataTreeCandidate> candidates;
 
     /**
      * Creates new {@link ListenerAdapter} listener specified by path and stream
@@ -70,13 +69,13 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
         register(this);
         this.outputType = Preconditions.checkNotNull(outputType);
         this.path = Preconditions.checkNotNull(path);
-        Preconditions.checkArgument((streamName != null) && !streamName.isEmpty());
+        Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
         this.streamName = streamName;
     }
 
     @Override
-    public void onDataTreeChanged(@Nonnull Collection<DataTreeCandidate> dataTreeCandidates) {
-        this.dataTreeCandidates = dataTreeCandidates;
+    public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> dataTreeCandidates) {
+        this.candidates = dataTreeCandidates;
         final String xml = prepareXml();
         if (checkQueryParams(xml, this)) {
             prepareAndPostData(xml);
@@ -141,7 +140,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
                 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote", "data-changed-notification");
 
         addValuesToDataChangedNotificationEventElement(doc, dataChangedNotificationEventElement,
-                                                            this.dataTreeCandidates, schemaContext, dataContextTree);
+                                                            this.candidates, schemaContext, dataContextTree);
         notificationElement.appendChild(dataChangedNotificationEventElement);
         return transformDoc(doc);
     }
@@ -173,11 +172,11 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
     }
 
     private void addNodeToDataChangeNotificationEventElement(final Document doc,
-                             final Element dataChangedNotificationEventElement, DataTreeCandidateNode candidateNode,
-                             YangInstanceIdentifier parentYiid, SchemaContext schemaContext,
-                             DataSchemaContextTree dataSchemaContextTree) {
+            final Element dataChangedNotificationEventElement, final DataTreeCandidateNode candidateNode,
+            final YangInstanceIdentifier parentYiid, final SchemaContext schemaContext,
+            final DataSchemaContextTree dataSchemaContextTree) {
 
-        Optional<NormalizedNode<?,?>> optionalNormalizedNode = Optional.absent();
+        java.util.Optional<NormalizedNode<?,?>> optionalNormalizedNode = java.util.Optional.empty();
         switch (candidateNode.getModificationType()) {
             case APPEARED:
             case SUBTREE_MODIFIED:
@@ -244,7 +243,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      *            {@link Operation}
      * @return {@link Node} node represented by changed event element.
      */
-    private Node createDataChangeEventElement(final Document doc, final YangInstanceIdentifier path,
+    private static Node createDataChangeEventElement(final Document doc, final YangInstanceIdentifier path,
             final Operation operation) {
         final Element dataChangeEventElement = doc.createElement("data-change-event");
         final Element pathElement = doc.createElement("path");
@@ -259,11 +258,11 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
     }
 
     private Node createCreatedChangedDataChangeEventElement(final Document doc,
-            YangInstanceIdentifier path, NormalizedNode normalized, final Operation operation,
+            final YangInstanceIdentifier eventPath, final NormalizedNode normalized, final Operation operation,
             final SchemaContext schemaContext, final DataSchemaContextTree dataSchemaContextTree) {
         final Element dataChangeEventElement = doc.createElement("data-change-event");
         final Element pathElement = doc.createElement("path");
-        addPathAsValueToElement(path, pathElement);
+        addPathAsValueToElement(eventPath, pathElement);
         dataChangeEventElement.appendChild(pathElement);
 
         final Element operationElement = doc.createElement("operation");
@@ -272,10 +271,10 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
 
         try {
             SchemaPath nodePath;
-            if ((normalized instanceof MapEntryNode) || (normalized instanceof UnkeyedListEntryNode)) {
-                nodePath = dataSchemaContextTree.getChild(path).getDataSchemaNode().getPath();
+            if (normalized instanceof MapEntryNode || normalized instanceof UnkeyedListEntryNode) {
+                nodePath = dataSchemaContextTree.getChild(eventPath).getDataSchemaNode().getPath();
             } else {
-                nodePath = dataSchemaContextTree.getChild(path).getDataSchemaNode().getPath().getParent();
+                nodePath = dataSchemaContextTree.getChild(eventPath).getDataSchemaNode().getPath().getParent();
             }
             final DOMResult domResult = writeNormalizedNode(normalized, schemaContext, nodePath);
             final Node result = doc.importNode(domResult.getNode().getFirstChild(), true);
@@ -300,7 +299,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      *            {@link Element}
      */
     @SuppressWarnings("rawtypes")
-    private void addPathAsValueToElement(final YangInstanceIdentifier path, final Element element) {
+    private static void addPathAsValueToElement(final YangInstanceIdentifier path, final Element element) {
         final YangInstanceIdentifier normalizedPath = ControllerContext.getInstance().toXpathRepresentation(path);
         final StringBuilder textContent = new StringBuilder();
 
@@ -343,8 +342,8 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      */
     private static void writeIdentifierWithNamespacePrefix(final Element element, final StringBuilder textContent,
             final QName qualifiedName) {
-        final Module module = ControllerContext.getInstance().getGlobalSchema()
-                .findModuleByNamespaceAndRevision(qualifiedName.getNamespace(), qualifiedName.getRevision());
+        final Module module = ControllerContext.getInstance().getGlobalSchema().findModule(qualifiedName.getModule())
+                .get();
 
         textContent.append(module.getName());
         textContent.append(":");