[ONOS-5148] Defect fix for incorrect event/listener reference when module name ends with Service

Change-Id: Ie3301d18aad36c29f531babead1963da18810172
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 4dd6d68..1696893 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;
 
@@ -323,7 +322,7 @@
      * @param childSchemaMapHolder child schema map holder
      */
     private void processAdditionOfSchemaNodeToMap(String name, String namespace, YangSchemaNode yangSchemaNode,
-            YangNode childSchemaMapHolder) {
+                                                  YangNode childSchemaMapHolder) {
         // Addition of node to schema node map.
         // Create YANG schema node identifier with child node name.
         YangSchemaNodeIdentifier yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
@@ -343,7 +342,7 @@
     @Override
     public int compareTo(YangNode otherNode) {
         if (priority == otherNode.getPriority()) {
-            return 1;
+            return 0;
         }
         return ((Integer) otherNode.getPriority()).compareTo(priority);
     }
@@ -584,7 +583,7 @@
      * @throws DataModelException a violation in data model rule
      */
     public abstract void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
-            YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+                                             YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
             throws DataModelException;
 
     /**
@@ -608,7 +607,7 @@
      * @param yangSchemaNode           YANG schema node
      */
     public abstract void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
-            YangSchemaNode yangSchemaNode);
+                                              YangSchemaNode yangSchemaNode);
 
     /**
      * Returns default child map.
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
index eac0ff1..e106c8f 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
@@ -48,7 +48,7 @@
 /**
  * Represents data model node to maintain information defined in YANG union.
  */
-public class YangUnion extends YangNode implements Parsable, YangTypeHolder {
+public class YangUnion extends YangNode implements Parsable, YangTypeHolder, CollisionDetector {
 
     private static final long serialVersionUID = 806201616L;
 
@@ -162,4 +162,14 @@
     public void validateDataOnExit() throws DataModelException {
         //TODO: implement the method.
     }
+
+    @Override
+    public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+        // Do nothing
+    }
+
+    @Override
+    public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+        // Do nothing
+    }
 }
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 641af4c..74dec9d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -21,7 +21,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-
 import org.onosproject.yangutils.datamodel.ResolvableType;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangReferenceResolver;
@@ -190,6 +189,11 @@
                         + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
                 throw new LinkerException(errorInfo);
                 // TODO add file path in exception message in util manager.
+            } catch (LinkerException e) {
+                String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+                        + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
+                throw new LinkerException(errorInfo);
+                // TODO add file path in exception message in util manager.
             }
         }
     }
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
index 89d2dbe..82301a2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -22,7 +22,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
-
 import org.onosproject.yangutils.datamodel.YangAtomicPath;
 import org.onosproject.yangutils.datamodel.YangAugment;
 import org.onosproject.yangutils.datamodel.YangCase;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index 9ffb424..1422d27 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -223,9 +223,11 @@
                 translatorErrorHandler(getRootNode(), yangPlugin);
                 deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
             } catch (IOException ex) {
+                e.printStackTrace();
                 throw new MojoExecutionException(
                         "Error handler failed to delete files for data model node.");
             }
+            e.printStackTrace();
             throw new MojoExecutionException(
                     "Exception occurred due to " + e.getLocalizedMessage() + " in " + fileName
                             + " YANG file.");
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 7634a9c..da23e83 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -23,9 +23,9 @@
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNotification;
 import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
 import org.onosproject.yangutils.translator.exception.TranslatorException;
 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.TempJavaCodeFragmentFilesContainer;
 
@@ -305,10 +305,11 @@
     private static String getRpcInterfaceDefinitionWhenItExtends(String yangName) {
 
         if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
-            String[] strArray = yangName.split(SERVICE);
+            StringBuilder newString = new StringBuilder(yangName);
+            newString.replace(yangName.lastIndexOf("Service"), yangName.lastIndexOf("Service") + 7, "");
             return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION
-                    + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
-                    + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
+                    + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + newString + EVENT_STRING + COMMA
+                    + SPACE + newString + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
                     + OPEN_CURLY_BRACKET + NEW_LINE;
         }
         yangName = yangName.substring(0, yangName.length() - 7);