yang Notification Listener
Change-Id: I1073be0342bee083495e2c103bad8351f492441c
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
index e7687b5..92b3420 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
@@ -25,6 +25,7 @@
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
@@ -35,6 +36,7 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
/**
* Factory to create data model objects based on the target file type.
@@ -51,8 +53,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -69,8 +71,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -87,8 +89,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -105,8 +107,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -123,8 +125,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -141,8 +143,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -159,8 +161,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -177,8 +179,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -195,8 +197,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -213,8 +215,8 @@
* Based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
- * generated.
- * @return the corresponding inherited node based on the target language.
+ * generated
+ * @return the corresponding inherited node based on the target language
*/
public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
@@ -226,4 +228,22 @@
}
}
}
+
+ /**
+ * Based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaNotification();
+ }
+ default: {
+ throw new RuntimeException("Only YANG to Java is supported.");
+ }
+ }
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 820139e..029a4d7 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -49,6 +49,7 @@
import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
+import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
@@ -1090,12 +1091,12 @@
@Override
public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- // TODO: implement the method.
+ NotificationListener.processNotificationEntry(this, ctx);
}
@Override
public void exitNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- // TODO: implement the method.
+ NotificationListener.processNotificationExit(this, ctx);
}
@Override
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
index 06dd0d5..1677cf6 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
@@ -21,6 +21,10 @@
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -127,7 +131,10 @@
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangContainer
- || curData instanceof YangList || curData instanceof YangCase) {
+ || curData instanceof YangList || curData instanceof YangCase
+ || curData instanceof YangNotification
+ || curData instanceof YangInput || curData instanceof YangOutput
+ || curData instanceof YangAugment) {
YangNode curNode = (YangNode) curData;
try {
curNode.addChild(container);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
index fe5e451..b21bd71 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
@@ -21,6 +21,10 @@
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -134,7 +138,9 @@
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangContainer
- || curData instanceof YangList || curData instanceof YangCase) {
+ || curData instanceof YangList || curData instanceof YangCase
+ || curData instanceof YangNotification || curData instanceof YangInput
+ || curData instanceof YangOutput || curData instanceof YangAugment) {
curNode = (YangNode) curData;
try {
curNode.addChild(yangList);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
new file mode 100644
index 0000000..3a87414
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
+import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangNotificationNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
+import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * notification-stmt = notification-keyword sep
+ * identifier-arg-str optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * *(if-feature-stmt stmtsep)
+ * [status-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * *((typedef-stmt /
+ * grouping-stmt) stmtsep)
+ * *(data-def-stmt stmtsep)
+ * "}")
+ *
+ * ANTLR grammar rule
+ * notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
+ * | statusStatement | descriptionStatement | referenceStatement | typedefStatement
+ * | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Implements listener based call back function corresponding to the "notification"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class NotificationListener {
+
+ /**
+ * Creates a new notification listener.
+ */
+ private NotificationListener() {
+ }
+
+ /**
+ * It is called when parser receives an input matching the grammar rule
+ * (notification), performs validation and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processNotificationEntry(TreeWalkListener listener,
+ GeneratedYangParser.NotificationStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA, ctx.identifier().getText(), ENTRY);
+
+ String identifier = getValidIdentifier(ctx.identifier().getText(), NOTIFICATION_DATA, ctx);
+
+ // Validate sub statement cardinality.
+ validateSubStatementsCardinality(ctx);
+
+ // Check for identifier collision
+ int line = ctx.getStart().getLine();
+ int charPositionInLine = ctx.getStart().getCharPositionInLine();
+ 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);
+ YangNode curNode = (YangNode) curData;
+ try {
+ curNode.addChild(notification);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ NOTIFICATION_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
+ }
+ listener.getParsedDataStack().push(notification);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NOTIFICATION_DATA,
+ ctx.identifier().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * It is called when parser exits from grammar rule (notification), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processNotificationExit(TreeWalkListener listener,
+ GeneratedYangParser.NotificationStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ 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));
+ }
+ }
+
+ /**
+ * Validates the cardinality of notification sub-statements as per grammar.
+ *
+ * @param ctx context object of the grammar rule
+ */
+ 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());
+ validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
+ NOTIFICATION_DATA, ctx.identifier().getText());
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
index 01c337a..3ca81fb 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
@@ -25,6 +25,10 @@
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -129,9 +133,11 @@
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer
- || curData instanceof YangList) {
+ || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc
+ || curData instanceof YangInput || curData instanceof YangOutput) {
+
/*
- * TODO YangGrouping, YangRpc, YangInput, YangOutput, Notification.
+ * TODO YangGrouping.
*/
YangNode curNode = (YangNode) curData;
try {
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
new file mode 100644
index 0000000..ac9a588
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.translator.tojava.javamodel;
+
+import java.io.IOException;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
+import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
+
+/**
+ * Notification information extended to support java code generation.
+ */
+public class YangJavaNotification extends YangNotification
+ implements JavaCodeGenerator, HasJavaFileInfo,
+ HasJavaImportData, HasTempJavaCodeFragmentFiles {
+
+ /**
+ * Contains information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * Contains information of the imports to be inserted in the java file
+ * generated.
+ */
+ private JavaImportData javaImportData;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates an instance of java Notification.
+ */
+ public YangJavaNotification() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ setJavaImportData(new JavaImportData());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new RuntimeException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Set the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the data of java imports to be included in generated file.
+ *
+ * @return data of java imports to be included in generated file
+ */
+ @Override
+ public JavaImportData getJavaImportData() {
+
+ return javaImportData;
+ }
+
+ /**
+ * Set the data of java imports to be included in generated file.
+ *
+ * @param javaImportData data of java imports to be included in generated
+ * file
+ */
+ @Override
+ public void setJavaImportData(JavaImportData javaImportData) {
+
+ this.javaImportData = javaImportData;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+
+ if (tempFileHandle == null) {
+ throw new RuntimeException("Missing temporary file handle for" +
+ "current node " + getJavaFileInfo().getJavaName());
+ }
+ return tempFileHandle;
+ }
+
+ /**
+ * Set temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * notification info.
+ *
+ * @param codeGenDir code generation directory
+ * @throws IOException IO operation fail
+ */
+ @Override
+ public void generateCodeEntry(String codeGenDir) throws IOException {
+
+ getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
+ getJavaFileInfo().setPackage(getCurNodePackage(this));
+ getJavaFileInfo().setPackageFilePath(
+ getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
+ getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+
+ String absolutePath = getAbsolutePackagePath(
+ getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath());
+
+ setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
+ getJavaFileInfo().getGeneratedFileTypes(), absolutePath,
+ getJavaFileInfo().getJavaName()));
+
+ getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
+
+ getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
+ }
+
+ /**
+ * Create a java file using the YANG notification info.
+ */
+ @Override
+ public void generateCodeExit() {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/main/resources/GeneratedYang.g4 b/src/main/resources/GeneratedYang.g4
index 629929c..3fc0f9a 100644
--- a/src/main/resources/GeneratedYang.g4
+++ b/src/main/resources/GeneratedYang.g4
@@ -1132,9 +1132,9 @@
* "}")
* TODO : 0..1 occurance to be checked in listener
*/
- notificationStatement : NOTIFICATION_KEYWORD IDENTIFIER (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | dataDefStatement)*
- RIGHT_CURLY_BRACE);
+ notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
+ | statusStatement | descriptionStatement | referenceStatement | typedefStatement
+ | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
/**
* deviation-stmt = deviation-keyword sep
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
new file mode 100644
index 0000000..b6a57d9
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangStatusType;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.ListIterator;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing notification listener functionality.
+ */
+public class NotificationListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks valid notification statement.
+ */
+ @Test
+ public void processValidNotificationStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValidNotificationStatement.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("rock"));
+
+ YangNotification yangNotification = (YangNotification) yangNode.getChild();
+ assertThat(yangNotification.getName(), is("link-failure"));
+ assertThat(yangNotification.getDescription(), is("\"A link failure has been detected\""));
+ assertThat(yangNotification.getStatus(), is(YangStatusType.DEPRECATED));
+ assertThat(yangNotification.getReference(), is("\"reference\""));
+
+ YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild();
+ assertThat(typeDef.getName(), is("my-type"));
+ assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
+ assertThat(typeDef.getDerivedType().getDataTypeExtendedInfo()
+ .getBaseType().getDataType(), is(YangDataTypes.INT32));
+
+ ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getLeafName(), is("if-name"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref"));
+ }
+}
diff --git a/src/test/resources/ValidNotificationStatement.yang b/src/test/resources/ValidNotificationStatement.yang
new file mode 100644
index 0000000..b96fc54
--- /dev/null
+++ b/src/test/resources/ValidNotificationStatement.yang
@@ -0,0 +1,25 @@
+module rock {
+ namespace "http://example.net/rock";
+ prefix "rock";
+
+ notification link-failure {
+ description "A link failure has been detected";
+ status deprecated;
+ reference "reference";
+ typedef my-type {
+ status deprecated;
+ type int32;
+ }
+ leaf if-name {
+ type leafref {
+ path "/interface/name";
+ }
+ }
+ leaf if-admin-status {
+ type admin-status;
+ }
+ leaf if-oper-status {
+ type oper-status;
+ }
+ }
+}