Vidyashree Rama
Committed by Gerrit Code Review

YANG rpc, input and output listener

Change-Id: Idd9847175c61d9f033cf80213b46e9c9c949849c
......@@ -26,6 +26,9 @@ 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.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
......@@ -37,6 +40,9 @@ 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;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
/**
* Factory to create data model objects based on the target file type.
......@@ -246,4 +252,58 @@ public final class YangDataModelFactory {
}
}
}
/**
* 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 YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
return new YangJavaRpc();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
}
}
}
/**
* 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 YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
return new YangJavaInput();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
}
}
}
/**
* 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 YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
return new YangJavaOutput();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
}
}
}
}
......
......@@ -42,6 +42,7 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
......@@ -53,12 +54,14 @@ 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.OutputListener;
import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
import org.onosproject.yangutils.parser.impl.listeners.PrefixListener;
import org.onosproject.yangutils.parser.impl.listeners.PresenceListener;
import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener;
import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
import org.onosproject.yangutils.parser.impl.listeners.RpcListener;
import org.onosproject.yangutils.parser.impl.listeners.ShortCaseListener;
import org.onosproject.yangutils.parser.impl.listeners.StatusListener;
import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener;
......@@ -1062,32 +1065,48 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
// TODO: implement the method.
RpcListener.processRpcEntry(this, ctx);
}
@Override
public void exitRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
// TODO: implement the method.
RpcListener.processRpcExit(this, ctx);
}
@Override
public void enterInputStatement(GeneratedYangParser.InputStatementContext ctx) {
// TODO: implement the method.
InputListener.processInputEntry(this, ctx);
}
@Override
public void exitInputStatement(GeneratedYangParser.InputStatementContext ctx) {
// TODO: implement the method.
InputListener.processInputExit(this, ctx);
}
@Override
public void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
}
@Override
public void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
}
@Override
public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
// TODO: implement the method.
OutputListener.processOutputEntry(this, ctx);
}
@Override
public void exitOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
// TODO: implement the method.
OutputListener.processOutputExit(this, ctx);
}
@Override
public void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
}
@Override
public void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
}
@Override
......
/*
* 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.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
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;
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.getYangInputNode;
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.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* input-stmt = input-keyword optsep
* "{" stmtsep
* ;; these stmts can appear in any order
* *((typedef-stmt /
* grouping-stmt) stmtsep)
* 1*(data-def-stmt stmtsep)
* "}"
*
* inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
* inputStatementBody : typedefStatement* dataDefStatement+
* | dataDefStatement+ typedefStatement*
* | groupingStatement* dataDefStatement+
* | dataDefStatement+ groupingStatement*;
*/
/**
* Implements listener based call back function corresponding to the "input"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class InputListener {
private static final String INPUT_KEYWORD = "Input";
/**
* Creates a new input listener.
*/
private InputListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (input), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processInputEntry(TreeWalkListener listener,
GeneratedYangParser.InputStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangRpc) {
YangInput yangInput = getYangInputNode(JAVA_GENERATION);
yangInput.setName(((YangRpc) curData).getName() + INPUT_KEYWORD);
YangNode curNode = (YangNode) curData;
try {
curNode.addChild(yangInput);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
INPUT_DATA, "", ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(yangInput);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INPUT_DATA,
"", ENTRY));
}
}
/**
* It is called when parser exits from grammar rule (input), 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 processInputExit(TreeWalkListener listener,
GeneratedYangParser.InputStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangInput)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INPUT_DATA,
"", EXIT));
}
listener.getParsedDataStack().pop();
}
}
/*
* 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.YangNode;
import org.onosproject.yangutils.datamodel.YangOutput;
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;
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.getYangOutputNode;
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.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* output-stmt = output-keyword optsep
* "{" stmtsep
* ;; these stmts can appear in any order
* *((typedef-stmt /
* grouping-stmt) stmtsep)
* 1*(data-def-stmt stmtsep)
* "}"
*
* outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
* outputStatementBody : typedefStatement* dataDefStatement+
* | dataDefStatement+ typedefStatement*
* | groupingStatement* dataDefStatement+
* | dataDefStatement+ groupingStatement*;
*/
/**
* Implements listener based call back function corresponding to the "output"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class OutputListener {
private static final String OUTPUT_KEYWORD = "Output";
/**
* Creates a new output listener.
*/
private OutputListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (output), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processOutputEntry(TreeWalkListener listener,
GeneratedYangParser.OutputStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangRpc) {
YangOutput yangOutput = getYangOutputNode(JAVA_GENERATION);
yangOutput.setName(((YangRpc) curData).getName() + OUTPUT_KEYWORD);
YangNode curNode = (YangNode) curData;
try {
curNode.addChild(yangOutput);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
OUTPUT_DATA, "", ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(yangOutput);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, OUTPUT_DATA,
"", ENTRY));
}
}
/**
* It is called when parser exits from grammar rule (output), 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 processOutputExit(TreeWalkListener listener,
GeneratedYangParser.OutputStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangOutput)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, OUTPUT_DATA,
"", EXIT));
}
listener.getParsedDataStack().pop();
}
}
\ No newline at end of file
/*
* 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.YangNode;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
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.getYangRpcNode;
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.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
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.RPC_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* rpc-stmt = rpc-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)
* [input-stmt stmtsep]
* [output-stmt stmtsep]
* "}")
*
* ANTLR grammar rule
* rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
* | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | inputStatement
* | outputStatement)* RIGHT_CURLY_BRACE);
*/
/**
* Implements listener based call back function corresponding to the "rpc"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class RpcListener {
/**
* Creates a new rpc listener.
*/
private RpcListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (rpc), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processRpcEntry(TreeWalkListener listener,
GeneratedYangParser.RpcStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), RPC_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, RPC_DATA);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangSubModule) {
YangNode curNode = (YangNode) curData;
YangRpc yangRpc = getYangRpcNode(JAVA_GENERATION);
yangRpc.setName(identifier);
try {
curNode.addChild(yangRpc);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
RPC_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(yangRpc);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RPC_DATA,
ctx.identifier().getText(), ENTRY));
}
}
/**
* It is called when parser exits from grammar rule (rpc), 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 processRpcExit(TreeWalkListener listener,
GeneratedYangParser.RpcStatementContext ctx) {
//Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangRpc)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RPC_DATA,
ctx.identifier().getText(), EXIT));
}
listener.getParsedDataStack().pop();
}
/**
* Validates the cardinality of rpc sub-statements as per grammar.
*
* @param ctx context object of the grammar rule
*/
private static void validateSubStatementsCardinality(GeneratedYangParser.RpcStatementContext ctx) {
validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText());
validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
RPC_DATA, ctx.identifier().getText());
}
}
/*
* 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.YangRpc;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
/**
* Rpc information extended to support java code generation.
*/
public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
/**
* Creates an instance of java Rpc.
*/
public YangJavaRpc() {
}
/**
* Prepare the information for java code generation corresponding to YANG
* rpc info.
*
* @param codeGenDir code generation directory
* @throws IOException IO operation fail
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
// TODO
}
/**
* Create a java file using the YANG rpc info.
*
* @throws IOException IO operation fail
*/
@Override
public void generateCodeExit() throws IOException {
// TODO
}
}
......@@ -1085,7 +1085,6 @@ package org.onosproject.yangutils.parser.antlrgencode;
* [input-stmt stmtsep]
* [output-stmt stmtsep]
* "}")
* TODO : 0..1 occurance to be checked in listener
*/
rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement
| referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE);
......@@ -1099,9 +1098,12 @@ package org.onosproject.yangutils.parser.antlrgencode;
* 1*(data-def-stmt stmtsep)
* "}"
*/
inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE
((typedefStatement | groupingStatement)* | dataDefStatement+)
| (dataDefStatement+ | (typedefStatement | groupingStatement)*)RIGHT_CURLY_BRACE;
inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
inputStatementBody : typedefStatement* dataDefStatement+
| dataDefStatement+ typedefStatement*
| groupingStatement* dataDefStatement+
| dataDefStatement+ groupingStatement*;
/**
* output-stmt = output-keyword optsep
......@@ -1112,9 +1114,12 @@ package org.onosproject.yangutils.parser.antlrgencode;
* 1*(data-def-stmt stmtsep)
* "}"
*/
outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE
((typedefStatement | groupingStatement)* | dataDefStatement+)
| (dataDefStatement+ | (typedefStatement | groupingStatement)*)RIGHT_CURLY_BRACE;
outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
outputStatementBody : typedefStatement* dataDefStatement+
| dataDefStatement+ typedefStatement*
| groupingStatement* dataDefStatement+
| dataDefStatement+ groupingStatement*;
/**
* notification-stmt = notification-keyword sep
......
/*
* 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 java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangStatusType;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test cases for testing Input listener functionality.
*/
public class InputListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks input statements with data definition statements as sub-statements.
*/
@Test
public void processInputStatementWithDataDefinition() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/InputStatementWithDataDefinition.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("rock"));
YangRpc yangRpc = (YangRpc) yangNode.getChild();
assertThat(yangRpc.getName(), is("activate-software-image"));
YangInput yangInput = (YangInput) yangRpc.getChild();
assertThat(yangInput.getName(), is("activate-software-imageInput"));
ListIterator<YangLeaf> leafIterator = yangInput.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("image-name"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
YangList yangList = (YangList) yangInput.getChild();
assertThat(yangList.getName(), is("ospf"));
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
YangContainer yangContainer = (YangContainer) yangList.getNextSibling();
assertThat(yangContainer.getName(), is("isis"));
leafIterator = yangContainer.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
}
/**
* Checks input statements with type-def statement as sub-statements.
*/
@Test
public void processInputStatementWithTypedef() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/InputStatementWithTypedef.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("rock"));
YangRpc yangRpc = (YangRpc) yangNode.getChild();
assertThat(yangRpc.getName(), is("activate-software-image"));
YangInput yangInput = (YangInput) yangRpc.getChild();
assertThat(yangInput.getName(), is("activate-software-imageInput"));
YangTypeDef typeDef = (YangTypeDef) yangInput.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
}
}
/*
* 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 java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangStatusType;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test cases for testing output listener functionality.
*/
public class OutputListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks output statements with data definition statements as sub-statements.
*/
@Test
public void processOutputStatementWithDataDefinition() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/OutputStatementWithDataDefinition.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("rock"));
YangRpc yangRpc = (YangRpc) yangNode.getChild();
assertThat(yangRpc.getName(), is("activate-software-image"));
YangOutput yangOutput = (YangOutput) yangRpc.getChild();
assertThat(yangOutput.getName(), is("activate-software-imageOutput"));
ListIterator<YangLeaf> leafIterator = yangOutput.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("image-name"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
YangList yangList = (YangList) yangOutput.getChild();
assertThat(yangList.getName(), is("ospf"));
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
YangContainer yangContainer = (YangContainer) yangList.getNextSibling();
assertThat(yangContainer.getName(), is("isis"));
leafIterator = yangContainer.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
}
/**
* Checks output statements with type-def statement as sub-statements.
*/
@Test
public void processOutputStatementWithTypedef() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/OutputStatementWithTypedef.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("rock"));
YangRpc yangRpc = (YangRpc) yangNode.getChild();
assertThat(yangRpc.getName(), is("activate-software-image"));
YangOutput yangOutput = (YangOutput) yangRpc.getChild();
assertThat(yangOutput.getName(), is("activate-software-imageOutput"));
YangTypeDef typeDef = (YangTypeDef) yangOutput.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
}
}
\ No newline at end of file
/*
* 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 java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangStatusType;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test cases for testing Rpc listener functionality.
*/
public class RpcListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks valid rpc statements.
*/
@Test
public void processValidRpcStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ValidRpcStatement.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("rock"));
YangRpc yangRpc = (YangRpc) yangNode.getChild();
assertThat(yangRpc.getName(), is("rock-the-house"));
assertThat(yangRpc.getDescription(), is("\"description\""));
assertThat(yangRpc.getReference(), is("\"reference\""));
assertThat(yangRpc.getStatus(), is(YangStatusType.CURRENT));
YangTypeDef typeDef = (YangTypeDef) yangRpc.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
}
}
module rock {
namespace "http://example.net/rock";
prefix "rock";
rpc activate-software-image {
description "description";
input {
leaf image-name {
type string;
}
list ospf {
key "invalid-interval";
config true;
max-elements 10;
min-elements 3;
leaf invalid-interval {
type uint16;
}
}
container isis {
config true;
leaf invalid-interval {
type uint16;
}
}
}
}
}
module rock {
namespace "http://example.net/rock";
prefix "rock";
rpc activate-software-image {
description "description";
input {
leaf image-name {
type string;
}
typedef my-type {
status deprecated;
type int32;
}
}
}
}
module rock {
namespace "http://example.net/rock";
prefix "rock";
rpc activate-software-image {
description "description";
output {
leaf image-name {
type string;
}
list ospf {
key "invalid-interval";
config true;
max-elements 10;
min-elements 3;
leaf invalid-interval {
type uint16;
}
}
container isis {
config true;
leaf invalid-interval {
type uint16;
}
}
}
}
}
module rock {
namespace "http://example.net/rock";
prefix "rock";
rpc activate-software-image {
description "description";
output {
leaf image-name {
type string;
}
typedef my-type {
status deprecated;
type int32;
}
}
}
}
module rock {
namespace "http://example.net/rock";
prefix "rock";
rpc rock-the-house {
description "description";
status current;
reference "reference";
typedef my-type {
status deprecated;
type int32;
}
input {
leaf zip-code {
type string;
}
}
output {
leaf status {
type string;
}
}
}
}