gNotification flag implementation in utils to optimize notification search and notification listener addition in YMS

Change-Id: Iea666ca7af9641869cba2a67e23a025cbc1b7317
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
index 2d29f9e..e19ed56 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
@@ -20,4 +20,20 @@
  * Represents class having rpc and notification.
  */
 public interface RpcNotificationContainer {
+
+    /**
+     * Sets notification presence flag.
+     *
+     * @param notificationPresent notification presence flag
+     */
+    void setNotificationPresenceFlag(boolean notificationPresent);
+
+    /**
+     * Adds to notification enumeration map.
+     *
+     * @param nameOfNotificationInEnum name of notification in enum
+     * @param notficationSchemaNode    schema node of notification
+     */
+    void addToNotificationEnumMap(String nameOfNotificationInEnum,
+                                  YangSchemaNode notficationSchemaNode);
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
index 77df35a..847b98b 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
@@ -20,7 +20,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -64,7 +63,8 @@
  */
 public abstract class YangLeaf
         implements YangCommonInfo, Parsable, Cloneable, Serializable,
-        YangMustHolder, YangIfFeatureHolder, YangWhenHolder, YangSchemaNode, YangConfig {
+        YangMustHolder, YangIfFeatureHolder, YangWhenHolder, YangSchemaNode,
+        YangConfig {
 
     private static final long serialVersionUID = 806201635L;
 
@@ -368,7 +368,8 @@
     @Override
     public void validateDataOnExit()
             throws DataModelException {
-        if (defaultValueInString != null && !defaultValueInString.isEmpty() && dataType != null) {
+        if (defaultValueInString != null && !defaultValueInString.isEmpty()
+                && dataType != null) {
             dataType.isValidValue(defaultValueInString);
         }
     }
@@ -434,6 +435,11 @@
     }
 
     @Override
+    public boolean isNotificationPresent() throws DataModelException {
+        throw new DataModelException("Method is called for node other than module/sub-module.");
+    }
+
+    @Override
     public YangSchemaNodeType getYangSchemaNodeType() {
         return YangSchemaNodeType.YANG_SINGLE_INSTANCE_LEAF_NODE;
     }
@@ -459,14 +465,19 @@
      *
      * @param yangSchemaNodeIdentifier YANG schema node identifier
      */
-    public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier yangSchemaNodeIdentifier) {
+    public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier
+                                                    yangSchemaNodeIdentifier) {
         if (this.yangSchemaNodeIdentifier == null) {
             this.yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
         }
         this.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier;
     }
 
-    @Override
+    /**
+     * Retrieve the name of leaf.
+     *
+     * @return leaf name
+     */
     public String getName() {
         return yangSchemaNodeIdentifier.getName();
     }
@@ -499,4 +510,11 @@
         }
         yangSchemaNodeIdentifier.setNameSpace(namespace);
     }
+
+    @Override
+    public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+            throws DataModelException {
+        throw new DataModelException("Method called for schema node other " +
+                                             "then module/sub-module");
+    }
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
index 1682723..75af697 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
@@ -20,7 +20,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -60,7 +59,8 @@
  */
 public abstract class YangLeafList
         implements YangCommonInfo, Parsable, Cloneable, Serializable,
-        YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode, YangConfig {
+        YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
+        YangConfig {
 
     private static final long serialVersionUID = 806201637L;
 
@@ -452,6 +452,11 @@
     }
 
     @Override
+    public boolean isNotificationPresent() throws DataModelException {
+        throw new DataModelException("Method is called for node other than module/sub-module.");
+    }
+
+    @Override
     public YangSchemaNodeType getYangSchemaNodeType() {
         return YangSchemaNodeType.YANG_MULTI_INSTANCE_LEAF_NODE;
     }
@@ -477,14 +482,19 @@
      *
      * @param yangSchemaNodeIdentifier YANG schema node identifier
      */
-    public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier yangSchemaNodeIdentifier) {
+    public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier
+                                                    yangSchemaNodeIdentifier) {
         if (this.yangSchemaNodeIdentifier == null) {
             this.yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
         }
         this.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier;
     }
 
-    @Override
+    /**
+     * Retrieve the name of leaf list
+     *
+     * @return leaf list name
+     */
     public String getName() {
         return yangSchemaNodeIdentifier.getName();
     }
@@ -517,4 +527,10 @@
         }
         yangSchemaNodeIdentifier.setNameSpace(namespace);
     }
+
+    @Override
+    public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+            throws DataModelException {
+        throw new DataModelException("Method called for schema node other then module/sub-module");
+    }
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index c3c44fb..a433cdf 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -19,8 +19,8 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -74,8 +74,9 @@
  */
 public abstract class YangModule
         extends YangNode
-        implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
-        RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
+        implements YangLeavesHolder, YangDesc, YangReference, Parsable,
+        CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
+        YangFeatureHolder, YangIsFilterContentNodes {
 
     private static final long serialVersionUID = 806201610L;
 
@@ -232,6 +233,16 @@
     private List<YangExtension> extensionList;
 
     /**
+     * Flag to indicate the presence of notification.
+     */
+    private boolean isNotificationPresent;
+
+    /**
+     * Map of notification enum.
+     */
+    private Map<String, YangSchemaNode> notificationEnumMap;
+
+    /**
      * Creates a YANG node of module type.
      */
     public YangModule() {
@@ -251,6 +262,7 @@
         listOfLeafList = new LinkedList<>();
         extensionList = new LinkedList<>();
         listOfFeature = new LinkedList<>();
+        notificationEnumMap = new HashMap<>();
     }
 
     @Override
@@ -265,7 +277,8 @@
     }
 
     @Override
-    public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+    public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+                                     YangSchemaNode yangSchemaNode) {
         // TODO
     }
 
@@ -621,14 +634,16 @@
     }
 
     @Override
-    public void detectCollidingChild(String identifierName, YangConstructType dataType)
+    public void detectCollidingChild(String identifierName,
+                                     YangConstructType dataType)
             throws DataModelException {
         // Asks helper to detect colliding child.
         detectCollidingChildUtil(identifierName, dataType, this);
     }
 
     @Override
-    public void detectSelfCollision(String identifierName, YangConstructType dataType)
+    public void detectSelfCollision(String identifierName,
+                                    YangConstructType dataType)
             throws DataModelException {
         // Not required as module doesn't have any parent.
     }
@@ -738,4 +753,37 @@
             yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
         }
     }
+
+    @Override
+    public boolean isNotificationPresent() {
+        return isNotificationPresent;
+    }
+
+    @Override
+    public void setNotificationPresenceFlag(boolean notificationPresent) {
+        isNotificationPresent = notificationPresent;
+    }
+
+    @Override
+    public void addToNotificationEnumMap(String nameOfNotificationInEnum,
+                                         YangSchemaNode notficationSchemaNode) {
+        getNotificationEnumMap().put(nameOfNotificationInEnum,
+                                     notficationSchemaNode);
+    }
+
+    /**
+     * Returns notification enumeration map with key as the name of
+     * notification as per the enum in generated code and value as the
+     * notification schema node.
+     *
+     * @return notification enumeration map
+     */
+    private Map<String, YangSchemaNode> getNotificationEnumMap() {
+        return notificationEnumMap;
+    }
+
+    @Override
+    public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum) {
+        return getNotificationEnumMap().get(notificationNameInEnum);
+    }
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index 92b192a..c65af25 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -17,7 +17,6 @@
 
 import java.io.Serializable;
 import java.util.Map;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 
@@ -31,7 +30,8 @@
  * Represents base class of a node in data model tree.
  */
 public abstract class YangNode
-        implements Cloneable, Serializable, YangSchemaNode, Comparable<YangNode> {
+        implements Cloneable, Serializable, YangSchemaNode,
+        Comparable<YangNode> {
 
     private static final long serialVersionUID = 806201601L;
 
@@ -121,7 +121,8 @@
      * @param type              of YANG node
      * @param ysnContextInfoMap YSN context info map
      */
-    protected YangNode(YangNodeType type, Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap) {
+    protected YangNode(YangNodeType type,
+                       Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap) {
         setNodeType(type);
         this.ysnContextInfoMap = ysnContextInfoMap;
     }
@@ -226,7 +227,8 @@
     public void addChild(YangNode newChild)
             throws DataModelException {
         if (newChild.getNodeType() == null) {
-            throw new DataModelException("Abstract node cannot be inserted into a tree");
+            throw new DataModelException("Abstract node cannot be inserted " +
+                                                 "into a tree");
         }
 
         if (newChild.getParent() == null) {
@@ -236,15 +238,20 @@
         }
 
         if (newChild.getChild() != null) {
-            throw new DataModelException("Child to be added is not atomic, it already has a child");
+            throw new DataModelException("Child to be added is not atomic, " +
+                                                 "it already has a child");
         }
 
         if (newChild.getNextSibling() != null) {
-            throw new DataModelException("Child to be added is not atomic, it already has a next sibling");
+            throw new DataModelException("Child to be added is not atomic, " +
+                                                 "it already has a next " +
+                                                 "sibling");
         }
 
         if (newChild.getPreviousSibling() != null) {
-            throw new DataModelException("Child to be added is not atomic, it already has a previous sibling");
+            throw new DataModelException("Child to be added is not atomic, " +
+                                                 "it already has a previous " +
+                                                 "sibling");
         }
 
         /* First child to be added */
@@ -274,8 +281,9 @@
      * @param name      name of the node
      * @param namespace namespace of the node
      */
-    protected void processAdditionOfSchemaNodeToParentMap(String name, String namespace) {
-        processAdditionOfSchemaNodeToMap(getName(), getNameSpace(), this, getParent());
+    protected void processAdditionOfSchemaNodeToParentMap(String name,
+                                                          String namespace) {
+        processAdditionOfSchemaNodeToMap(name, namespace, this, getParent());
     }
 
     /**
@@ -285,8 +293,9 @@
      * @param namespace      namespace of the node
      * @param yangSchemaNode YANG schema node
      */
-    public void processAdditionOfSchemaNodeToCurNodeMap(String name, String namespace, YangSchemaNode
-            yangSchemaNode) {
+    public void processAdditionOfSchemaNodeToCurNodeMap(String name,
+                                                        String namespace,
+                                                        YangSchemaNode yangSchemaNode) {
         processAdditionOfSchemaNodeToMap(name, namespace, yangSchemaNode, this);
     }
 
@@ -298,7 +307,9 @@
      * @param yangSchemaNode       YANG schema node
      * @param childSchemaMapHolder child schema map holder
      */
-    private void processAdditionOfSchemaNodeToMap(String name, String namespace, YangSchemaNode yangSchemaNode,
+    private void processAdditionOfSchemaNodeToMap(String name,
+                                                  String namespace,
+                                                  YangSchemaNode yangSchemaNode,
                                                   YangNode childSchemaMapHolder) {
         // Addition of node to schema node map.
         // Create YANG schema node identifier with child node name.
@@ -310,7 +321,8 @@
         yangSchemaNodeContextInfo.setSchemaNode(yangSchemaNode);
         // Invoke parent method to add the created entry.
         try {
-            childSchemaMapHolder.addToChildSchemaMap(yangSchemaNodeIdentifier, yangSchemaNodeContextInfo);
+            childSchemaMapHolder.addToChildSchemaMap(yangSchemaNodeIdentifier,
+                                                     yangSchemaNodeContextInfo);
         } catch (DataModelException e) {
             //TODO
         }
@@ -360,7 +372,8 @@
      * @param yangUses    YANG uses
      * @throws DataModelException data model error
      */
-    public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode, YangUses yangUses)
+    public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode,
+                                    YangUses yangUses)
             throws DataModelException {
 
         YangNode nextNodeToClone = srcRootNode;
@@ -385,11 +398,14 @@
         try {
             while (nextNodeToClone != srcRootNode) {
                 if (nextNodeToClone == null) {
-                    throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached");
+                    throw new DataModelException("Internal error: Cloning " +
+                                                         "failed, source tree " +
+                                                         "null pointer reached");
                 }
                 if (curTraversal != PARENT) {
                     newNode = nextNodeToClone.clone(yangUses);
-                    detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal);
+                    detectCollisionWhileCloning(clonedTreeCurNode, newNode,
+                                                curTraversal);
                 }
 
                 if (curTraversal == CHILD) {
@@ -447,24 +463,31 @@
      * @param addAs       traversal type of the node
      * @throws DataModelException data model error
      */
-    private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs)
+    private static void detectCollisionWhileCloning(YangNode currentNode,
+                                                    YangNode newNode,
+                                                    TraversalType addAs)
             throws DataModelException {
         if (!(currentNode instanceof CollisionDetector)
                 || !(newNode instanceof Parsable)) {
-            throw new DataModelException("Node in data model tree does not support collision detection");
+            throw new DataModelException("Node in data model tree does not " +
+                                                 "support collision detection");
         }
 
         CollisionDetector collisionDetector = (CollisionDetector) currentNode;
         Parsable parsable = (Parsable) newNode;
         if (addAs == TraversalType.CHILD) {
-            collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
+            collisionDetector.detectCollidingChild(newNode.getName(),
+                                                   parsable.getYangConstructType());
         } else if (addAs == TraversalType.SIBILING) {
             currentNode = currentNode.getParent();
             if (!(currentNode instanceof CollisionDetector)) {
-                throw new DataModelException("Node in data model tree does not support collision detection");
+                throw new DataModelException("Node in data model tree does " +
+                                                     "not support collision " +
+                                                     "detection");
             }
             collisionDetector = (CollisionDetector) currentNode;
-            collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
+            collisionDetector.detectCollidingChild(newNode.getName(),
+                                                   parsable.getYangConstructType());
         } else {
             throw new DataModelException("Errored tree cloning");
         }
@@ -499,7 +522,8 @@
             throws DataModelException {
 
         if (newSibling.getNodeType() == null) {
-            throw new DataModelException("Cloned abstract node cannot be inserted into a tree");
+            throw new DataModelException("Cloned abstract node cannot be " +
+                                                 "inserted into a tree");
         }
 
         if (newSibling.getParent() == null) {
@@ -510,31 +534,40 @@
             newSibling.setParent(getParent());
 
         } else {
-            throw new DataModelException("Node is already part of a tree, and cannot be added as a sibling");
+            throw new DataModelException("Node is already part of a tree, " +
+                                                 "and cannot be added as a " +
+                                                 "sibling");
         }
 
         if (newSibling.getPreviousSibling() == null) {
             newSibling.setPreviousSibling(this);
             setNextSibling(newSibling);
         } else {
-            throw new DataModelException("New sibling to be added is not atomic, it already has a previous sibling");
+            throw new DataModelException("New sibling to be added is not " +
+                                                 "atomic, it already has a " +
+                                                 "previous sibling");
         }
 
         if (newSibling.getChild() != null) {
-            throw new DataModelException("Sibling to be added is not atomic, it already has a child");
+            throw new DataModelException("Sibling to be added is not atomic, " +
+                                                 "it already has a child");
         }
 
         if (newSibling.getNextSibling() != null) {
-            throw new DataModelException("Sibling to be added is not atomic, it already has a next sibling");
+            throw new DataModelException("Sibling to be added is not atomic, " +
+                                                 "it already has a next sibling");
         }
     }
 
     @Override
     public YangSchemaNodeContextInfo getChildSchema(YangSchemaNodeIdentifier dataNodeIdentifier)
             throws DataModelException {
-        YangSchemaNodeContextInfo childSchemaContext = ysnContextInfoMap.get(dataNodeIdentifier);
+        YangSchemaNodeContextInfo childSchemaContext =
+                ysnContextInfoMap.get(dataNodeIdentifier);
         if (childSchemaContext == null) {
-            throw new DataModelException("Requested " + dataNodeIdentifier.getName() + "is not child in "
+            throw new DataModelException("Requested " +
+                                                 dataNodeIdentifier.getName() +
+                                                 "is not child in "
                     + getName());
         }
         return childSchemaContext;
@@ -551,6 +584,11 @@
         return defaultChildMap;
     }
 
+    @Override
+    public boolean isNotificationPresent() throws DataModelException {
+        throw new DataModelException("Method is called for node other than module/sub-module.");
+    }
+
     /**
      * Adds child schema in child schema map, this is used to add the schema
      * to the map in case of leaf as a child.
@@ -600,7 +638,8 @@
      *
      * @return YANG schema node context info map
      */
-    public Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> getYsnContextInfoMap() {
+    public Map<YangSchemaNodeIdentifier,
+            YangSchemaNodeContextInfo> getYsnContextInfoMap() {
         return ysnContextInfoMap;
     }
 
@@ -632,7 +671,8 @@
      *
      * @param ysnContextInfoMap YSN context info map
      */
-    public void setYsnContextInfoMap(Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap) {
+    public void setYsnContextInfoMap(Map<YangSchemaNodeIdentifier,
+            YangSchemaNodeContextInfo> ysnContextInfoMap) {
         this.ysnContextInfoMap = ysnContextInfoMap;
     }
 
@@ -642,7 +682,8 @@
      * @param yangSchemaNodeIdentifier  YANG schema node identifier
      * @param yangSchemaNodeContextInfo YANG schema node context info
      */
-    public void addToYsnContextInfoMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNodeContextInfo
+    public void addToYsnContextInfoMap(YangSchemaNodeIdentifier
+                                               yangSchemaNodeIdentifier, YangSchemaNodeContextInfo
             yangSchemaNodeContextInfo) {
         getYsnContextInfoMap().put(yangSchemaNodeIdentifier, yangSchemaNodeContextInfo);
     }
@@ -703,4 +744,11 @@
         }
         yangSchemaNodeIdentifier.setNameSpace(namespace);
     }
+
+    @Override
+    public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+            throws DataModelException {
+        throw new DataModelException("Method called for schema node other " +
+                                             "then module/sub-module");
+    }
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
index 3cac03d..861f2a1 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
@@ -17,7 +17,6 @@
 package org.onosproject.yangutils.datamodel;
 
 import java.util.Map;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 
 /**
@@ -41,8 +40,7 @@
      * @return YANG data node context information
      * @throws DataModelException data model exception in searching the child
      */
-    YangSchemaNodeContextInfo getChildSchema(
-            YangSchemaNodeIdentifier dataNodeIdentifier)
+    YangSchemaNodeContextInfo getChildSchema(YangSchemaNodeIdentifier dataNodeIdentifier)
             throws DataModelException;
 
     /**
@@ -56,8 +54,8 @@
             throws DataModelException;
 
     /**
-     * Returns count of mandatory child nodes, this is used by YMS to
-     * identify whether in request all mandatory child nodes are available.
+     * Returns count of mandatory child nodes, this is used by YMS to identify
+     * whether in request all mandatory child nodes are available.
      *
      * @return count of YANG schema nodes
      * @throws DataModelException a violation in data model rule
@@ -66,20 +64,18 @@
             throws DataModelException;
 
     /**
-     * Returns map of default child nodes, this is used by YMS to identify
-     * whether in request all default child nodes are available.
+     * Returns map of default child nodes, this is used by YMS to identify whether
+     * in request all default child nodes are available.
      *
      * @param dataNodeIdentifier YANG data node identifier
      * @return map of default child nodes
      */
-    Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(
-            YangSchemaNodeIdentifier dataNodeIdentifier);
+    Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(YangSchemaNodeIdentifier dataNodeIdentifier);
 
     /**
      * Get Java class's package corresponding to the schema node.
      *
-     * @return java package, it is null, if the Java type is a built in data
-     * type
+     * @return java package, it is null, if the Java type is a built in data type
      */
     String getJavaPackage();
 
@@ -117,4 +113,26 @@
      * @return name of the node
      */
     String getNameSpace();
+
+    /**
+     * Checks for the presence of notification in module/sub-module. Exception
+     * will be thrown if this is called for any other node type.
+     *
+     * @return true if notification is present, false otherwise
+     * @throws DataModelException a violation in data model rule
+     */
+    boolean isNotificationPresent() throws DataModelException;
+
+    /**
+     * Returns notification shcema node corresponding to the name of notification
+     * as per the generated code enumeration. This is to be used for notification
+     * processing in YMS.
+     *
+     * @param notificationNameInEnum notification name as per the generated
+     *                               code enumeration.
+     * @return notification schema node
+     * @throws DataModelException a violation in data model rule
+     */
+    YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+            throws DataModelException;
 }
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index d41b023..8986a2b 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -19,8 +19,8 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -82,8 +82,9 @@
  */
 public abstract class YangSubModule
         extends YangNode
-        implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
-        RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
+        implements YangLeavesHolder, YangDesc, YangReference, Parsable,
+        CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
+        YangFeatureHolder, YangIsFilterContentNodes {
 
     private static final long serialVersionUID = 806201614L;
 
@@ -235,6 +236,16 @@
     private List<YangResolutionInfo> augmentResolutionList;
 
     /**
+     * Flag to indicate the presence of notification.
+     */
+    private boolean isNotificationPresent;
+
+    /**
+     * Map of notification enum.
+     */
+    private Map<String, YangSchemaNode> notificationEnumMap;
+
+    /**
      * Creates a sub module node.
      */
     public YangSubModule() {
@@ -254,6 +265,7 @@
         extensionList = new LinkedList<>();
         compilerAnnotationList = new LinkedList<>();
         listOfFeature = new LinkedList<>();
+        notificationEnumMap = new HashMap<>();
     }
 
     @Override
@@ -268,7 +280,8 @@
     }
 
     @Override
-    public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+    public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+                                     YangSchemaNode yangSchemaNode) {
         // TODO
     }
 
@@ -568,14 +581,16 @@
     }
 
     @Override
-    public void detectCollidingChild(String identifierName, YangConstructType dataType)
+    public void detectCollidingChild(String identifierName,
+                                     YangConstructType dataType)
             throws DataModelException {
         // Asks helper to detect colliding child.
         detectCollidingChildUtil(identifierName, dataType, this);
     }
 
     @Override
-    public void detectSelfCollision(String identifierName, YangConstructType dataType)
+    public void detectSelfCollision(String identifierName,
+                                    YangConstructType dataType)
             throws DataModelException {
         // Not required as module doesn't have any parent.
     }
@@ -742,4 +757,37 @@
         }
     }
 
+
+    @Override
+    public boolean isNotificationPresent() {
+        return isNotificationPresent;
+    }
+
+    @Override
+    public void setNotificationPresenceFlag(boolean notificationPresent) {
+        this.isNotificationPresent = notificationPresent;
+    }
+
+    @Override
+    public void addToNotificationEnumMap(String nameOfNotificationInEnum,
+                                         YangSchemaNode notficationSchemaNode) {
+        getNotificationEnumMap().put(nameOfNotificationInEnum,
+                                     notficationSchemaNode);
+    }
+
+    /**
+     * Returns notification enumeration map with key as the name of
+     * notification as per the enum in generated code and value as the
+     * notification schema node.
+     *
+     * @return notification enumeration map
+     */
+    private Map<String, YangSchemaNode> getNotificationEnumMap() {
+        return notificationEnumMap;
+    }
+
+    @Override
+    public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum) {
+        return getNotificationEnumMap().get(notificationNameInEnum);
+    }
 }
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
index f04862e..94369d7 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
 import org.onosproject.yangutils.datamodel.YangModule;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNotification;
@@ -92,9 +93,11 @@
                                                 GeneratedYangParser.NotificationStatementContext ctx) {
 
         // Check for stack to be non empty.
-        checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA, ctx.identifier().getText(), ENTRY);
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA,
+                             ctx.identifier().getText(), ENTRY);
 
-        String identifier = getValidIdentifier(ctx.identifier().getText(), NOTIFICATION_DATA, ctx);
+        String identifier = getValidIdentifier(ctx.identifier().getText(),
+                                               NOTIFICATION_DATA, ctx);
 
         // Validate sub statement cardinality.
         validateSubStatementsCardinality(ctx);
@@ -102,13 +105,15 @@
         // Check for identifier collision
         int line = ctx.getStart().getLine();
         int charPositionInLine = ctx.getStart().getCharPositionInLine();
-        detectCollidingChildUtil(listener, line, charPositionInLine, identifier, NOTIFICATION_DATA);
+        detectCollidingChildUtil(listener, line, charPositionInLine, identifier,
+                                 NOTIFICATION_DATA);
 
         Parsable curData = listener.getParsedDataStack().peek();
         if (curData instanceof YangModule || curData instanceof YangSubModule) {
 
             YangNotification notification = getYangNotificationNode(JAVA_GENERATION);
             notification.setName(identifier);
+            ((RpcNotificationContainer) curData).setNotificationPresenceFlag(true);
             YangNode curNode = (YangNode) curData;
             try {
                 curNode.addChild(notification);
@@ -119,7 +124,7 @@
             listener.getParsedDataStack().push(notification);
         } else {
             throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NOTIFICATION_DATA,
-                    ctx.identifier().getText(), ENTRY));
+                                                                    ctx.identifier().getText(), ENTRY));
         }
     }
 
@@ -134,13 +139,14 @@
                                                GeneratedYangParser.NotificationStatementContext ctx) {
 
         // Check for stack to be non empty.
-        checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA, ctx.identifier().getText(), EXIT);
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA,
+                             ctx.identifier().getText(), EXIT);
 
         if (listener.getParsedDataStack().peek() instanceof YangNotification) {
             listener.getParsedDataStack().pop();
         } else {
             throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, NOTIFICATION_DATA,
-                    ctx.identifier().getText(), EXIT));
+                                                                    ctx.identifier().getText(), EXIT));
         }
     }
 
@@ -151,10 +157,13 @@
      */
     private static void validateSubStatementsCardinality(GeneratedYangParser.NotificationStatementContext ctx) {
 
-        validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, NOTIFICATION_DATA, ctx.identifier().getText());
-        validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, NOTIFICATION_DATA,
-                ctx.identifier().getText());
-        validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA,
-                ctx.identifier().getText());
+        validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA,
+                                  NOTIFICATION_DATA, ctx.identifier().getText());
+        validateCardinalityMaxOne(ctx.descriptionStatement(),
+                                  DESCRIPTION_DATA, NOTIFICATION_DATA,
+                                  ctx.identifier().getText());
+        validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA,
+                                  NOTIFICATION_DATA,
+                                  ctx.identifier().getText());
     }
 }
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
index d6f81b9..a44164f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
@@ -17,23 +17,25 @@
 package org.onosproject.yangutils.translator.tojava.javamodel;
 
 import java.io.IOException;
-
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
 import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
 import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaNotification;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
 import org.onosproject.yangutils.translator.exception.TranslatorException;
 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
 import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
 import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
 import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
 
 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -71,7 +73,8 @@
     public JavaFileInfoTranslator getJavaFileInfo() {
 
         if (javaFileInfo == null) {
-            throw new TranslatorException("Missing java info in java datamodel node");
+            throw new TranslatorException("Missing java info in java " +
+                                                  "datamodel node");
         }
         return (JavaFileInfoTranslator) javaFileInfo;
     }
@@ -114,11 +117,14 @@
      * @throws TranslatorException translator operation fail
      */
     @Override
-    public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+    public void generateCodeEntry(YangPluginConfig yangPlugin)
+            throws TranslatorException {
 
         /*
-         * As part of the notification support the following files needs to be generated.
-         * 1) Subject of the notification(event), this is simple interface with builder class.
+         * As part of the notification support the following files needs to
+         * be generated.
+         * 1) Subject of the notification(event), this is simple interface with
+         * builder class.
          * 2) Event class extending "AbstractEvent" and defining event type enum.
          * 3) Event listener interface extending "EventListener".
          *
@@ -132,7 +138,8 @@
             addNotificationToExtendsList();
         } catch (IOException e) {
             throw new TranslatorException(
-                    "Failed to prepare generate code entry for notification node " + getName());
+                    "Failed to prepare generate code entry for notification " +
+                            "node " + getName());
         }
     }
 
@@ -167,8 +174,34 @@
         try {
             getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
         } catch (IOException e) {
-            throw new TranslatorException("Failed to generate code for notification node " + getName());
+            throw new TranslatorException("Failed to generate code for " +
+                                                  "notification node " +
+                                                  getName());
         }
 
     }
+
+    @Override
+    public void setNameSpaceAndAddToParentSchemaMap() {
+        // Get parent namespace.
+        if (this.getParent() != null) {
+            String nameSpace = this.getParent().getNameSpace();
+            // Set namespace for self node.
+            setNameSpace(nameSpace);
+            // Process addition of leaf to the child schema map of parent.
+            processAdditionOfSchemaNodeToParentMap(getName(), getNameSpace());
+            // Obtain the notification name as per enum in notification.
+            String enumName = getEnumJavaAttribute(getJavaFileInfo().getJavaName()).toUpperCase();
+
+            ((RpcNotificationContainer) this.getParent()).addToNotificationEnumMap(enumName, this);
+
+        }
+        /*
+         * Check if node contains leaf/leaf-list, if yes add namespace for leaf
+         * and leaf list.
+         */
+        if (this instanceof YangLeavesHolder) {
+            ((YangLeavesHolder) this).setLeafNameSpaceAndAddToParentSchemaMap();
+        }
+    }
 }
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/SchemaNodeTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/SchemaNodeTest.java
index 88a4e2d..5d77724 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/SchemaNodeTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/SchemaNodeTest.java
@@ -22,6 +22,7 @@
 import java.util.Map;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.junit.Test;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
 import org.onosproject.yangutils.datamodel.YangNode;
@@ -32,6 +33,7 @@
 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
 
 import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
@@ -46,10 +48,14 @@
     /**
      * Checks method to get schema node from map.
      *
-     * @throws MojoExecutionException
+     * @throws IOException a violation in IO rule
+     * @throws ParserException a violation in parser rule
+     * @throws MojoExecutionException a violation in mojo rule
+     * @throws DataModelException a violation in data model rule
      */
     @Test
-    public void processSchemaNodeMap() throws IOException, ParserException, MojoExecutionException {
+    public void processSchemaNodeMap() throws IOException, ParserException,
+            MojoExecutionException, DataModelException {
 
         String searchDir = "src/test/resources/schemaMap";
         utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
@@ -63,13 +69,23 @@
         Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
         YangNode rootNode = yangNodeIterator.next();
 
+        // Validate the notification enum map
+        assertThat(rootNode.getChild().getNextSibling(),
+                   is(rootNode.getNotificationSchemaNode("TESTNOTIFICATION1")));
+
+        // Validate the notification enum map shouldn't have container
+        assertThat(rootNode.getNotificationSchemaNode("TESTCONTAINER"),
+                   is(nullValue()));
+
         assertThat(rootNode.getYsnContextInfoMap(), is(notNullValue()));
-        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap = rootNode.getYsnContextInfoMap();
+        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap =
+                rootNode.getYsnContextInfoMap();
         YangSchemaNodeIdentifier yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
         yangSchemaNodeIdentifier.setName("testcontainer");
         yangSchemaNodeIdentifier.setNameSpace("http://huawei.com");
         assertThat(schemaMap.get(yangSchemaNodeIdentifier), is(notNullValue()));
-        YangSchemaNodeContextInfo yangSchemaNodeContextInfo = schemaMap.get(yangSchemaNodeIdentifier);
+        YangSchemaNodeContextInfo yangSchemaNodeContextInfo =
+                schemaMap.get(yangSchemaNodeIdentifier);
         assertThat(yangSchemaNodeContextInfo.getSchemaNode(), is(rootNode.getChild()));
 
         assertThat(rootNode.getChild().getYsnContextInfoMap(), is(notNullValue()));
@@ -84,21 +100,26 @@
         assertThat(schemaMap2.get(yangSchemaNodeIdentifier), is(notNullValue()));
 
         assertThat(rootNode.getChild().getChild().getYsnContextInfoMap(), is(notNullValue()));
-        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap3 = rootNode.getChild().getChild()
+        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap3 =
+                rootNode.getChild().getChild()
                 .getYsnContextInfoMap();
         yangSchemaNodeIdentifier.setName("pretzel");
         yangSchemaNodeIdentifier.setNameSpace("http://huawei.com");
         assertThat(schemaMap3.get(yangSchemaNodeIdentifier), is(notNullValue()));
-        YangSchemaNodeContextInfo yangSchemaNodeContextInfo3 = schemaMap3.get(yangSchemaNodeIdentifier);
+        YangSchemaNodeContextInfo yangSchemaNodeContextInfo3 =
+                schemaMap3.get(yangSchemaNodeIdentifier);
 
-        assertThat(rootNode.getChild().getChild().getChild().getYsnContextInfoMap(), is(notNullValue()));
-        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap4 = rootNode.getChild().getChild().getChild()
+        assertThat(rootNode.getChild().getChild().getChild().getYsnContextInfoMap(),
+                   is(notNullValue()));
+        Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> schemaMap4 =
+                rootNode.getChild().getChild().getChild()
                 .getYsnContextInfoMap();
         yangSchemaNodeIdentifier.setName("pretzel");
         yangSchemaNodeIdentifier.setNameSpace("http://huawei.com");
         assertThat(schemaMap4.get(yangSchemaNodeIdentifier), is(notNullValue()));
 
-        YangSchemaNodeContextInfo yangSchemaNodeContextInfo2 = schemaMap4.get(yangSchemaNodeIdentifier);
+        YangSchemaNodeContextInfo yangSchemaNodeContextInfo2 =
+                schemaMap4.get(yangSchemaNodeIdentifier);
         List<YangLeaf> yangListOfLeaf = ((YangLeavesHolder) rootNode.getChild().getChild().getChild()).getListOfLeaf();
         YangLeaf yangLeaf = yangListOfLeaf.get(0);
         assertThat(yangSchemaNodeContextInfo2.getSchemaNode(), is(yangLeaf));
@@ -109,4 +130,33 @@
         deleteDirectory("target/schemaMap/");
     }
 
+    /**
+     * Checks that notification map shouldn't be present in other YANG node.
+     *
+     * @throws IOException a violation in IO rule
+     * @throws ParserException a violation in parser rule
+     * @throws MojoExecutionException a violation in mojo rule
+     * @throws DataModelException a violation in data model rule
+     */
+    @Test(expected = DataModelException.class)
+    public void processNotificationEnumMapInvalidScenario() throws IOException,
+            ParserException, MojoExecutionException,
+            DataModelException {
+
+        String searchDir = "src/test/resources/schemaMap";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.createYangNodeSet();
+        utilManager.resolveDependenciesUsingLinker();
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir("target/schemaMap/");
+        utilManager.translateToJava(yangPluginConfig);
+
+        Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+        YangNode rootNode = yangNodeIterator.next();
+
+        deleteDirectory("target/schemaMap/");
+
+        rootNode.getChild().getNotificationSchemaNode("TESTNOTIFICATION1");
+    }
 }
diff --git a/plugin/src/test/resources/schemaMap/SchemaMap.yang b/plugin/src/test/resources/schemaMap/SchemaMap.yang
index b8b5c48..34c989c 100644
--- a/plugin/src/test/resources/schemaMap/SchemaMap.yang
+++ b/plugin/src/test/resources/schemaMap/SchemaMap.yang
@@ -14,4 +14,12 @@
              }
         }
     }
+    notification testnotification1 {
+        leaf type {
+            type string;
+        }
+        leaf severity {
+            type string;
+        }
+    }
 }