[ONOS-5823]YANG Tools: Autogeneration of DefaultRpcCallable class to ease Application usage.
Change-Id: Ie77394cdfc863444dca2d16794a846a946b065af
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
index 6d42e9d..4e3534d 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -34,6 +34,7 @@
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
import org.onosproject.yang.compiler.datamodel.YangIfFeature;
import org.onosproject.yang.compiler.datamodel.YangImport;
+import org.onosproject.yang.compiler.datamodel.YangInput;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
@@ -46,6 +47,7 @@
import org.onosproject.yang.compiler.datamodel.YangMustHolder;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNotification;
+import org.onosproject.yang.compiler.datamodel.YangOutput;
import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
import org.onosproject.yang.compiler.datamodel.YangResolutionInfo;
import org.onosproject.yang.compiler.datamodel.YangRpc;
@@ -1219,4 +1221,38 @@
}
return null;
}
+
+ /**
+ * Searches for input in given RPC node.
+ *
+ * @return input node
+ */
+ public static YangNode findRpcInput(YangNode rpc) {
+ YangNode child = rpc.getChild();
+ while (child != null) {
+ if (!(child instanceof YangInput)) {
+ child = child.getNextSibling();
+ continue;
+ }
+ return child;
+ }
+ return null;
+ }
+
+ /**
+ * Searches for output in given RPC node.
+ *
+ * @return output node
+ */
+ public static YangNode findRpcOutput(YangNode rpc) {
+ YangNode child = rpc.getChild();
+ while (child != null) {
+ if (!(child instanceof YangOutput)) {
+ child = child.getNextSibling();
+ continue;
+ }
+ return child;
+ }
+ return null;
+ }
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedJavaFileType.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedJavaFileType.java
index d48c4f9..f512ef6 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedJavaFileType.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedJavaFileType.java
@@ -94,6 +94,33 @@
public static final int GENERATE_KEY_CLASS = 4096;
/**
+ * Default RPC handler class.
+ */
+ public static final int GENERATE_RPC_HANDLER_CLASS = 8192;
+
+ /**
+ * Register RPC class.
+ */
+ public static final int GENERATE_RPC_REGISTER_CLASS = 16384;
+
+ /**
+ * RPC command class.
+ */
+ public static final int GENERATE_RPC_COMMAND_CLASS = 32768;
+
+ /**
+ * Extended RPC command class.
+ */
+ public static final int GENERATE_RPC_EXTENDED_COMMAND_CLASS = 65536;
+
+ /**
+ * Java classes for RPC.
+ */
+ public static final int GENERATE_ALL_RPC_CLASS_MASK =
+ GENERATE_RPC_HANDLER_CLASS | GENERATE_RPC_REGISTER_CLASS
+ | GENERATE_RPC_EXTENDED_COMMAND_CLASS;
+
+ /**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
index 59647f9..5b53ef1 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
@@ -23,24 +23,41 @@
import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableSortedSet;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getStaticImportString;
import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yang.compiler.utils.UtilConstants.ARRAY_LIST_IMPORT;
import static org.onosproject.yang.compiler.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yang.compiler.utils.UtilConstants.BITSET;
import static org.onosproject.yang.compiler.utils.UtilConstants.COLLECTION_IMPORTS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CONFIG_PKG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DATA_NODE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DYNAMIC_CONFIG_SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.EVENT_LISTENER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EXECUTORS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EXECUTOR_SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_MATH;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_CONCURRENT_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_REGEX_PKG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.LINKED_LIST;
import static org.onosproject.yang.compiler.utils.UtilConstants.LIST;
import static org.onosproject.yang.compiler.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.MAP;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_CONVERTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.PATTERN;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUEUE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RESOURCE_ID;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_HANDLER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_INPUT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_OUTPUT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_OUTPUT_STATUS_PKG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_SUCCESS;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET;
/**
@@ -265,7 +282,7 @@
*
* @return import for list attribute
*/
- private String getImportForList() {
+ public String getImportForList() {
return getImportString(COLLECTION_IMPORTS, LIST);
}
@@ -331,4 +348,113 @@
public String getBigIntegerImport() {
return getImportString(JAVA_MATH, BIG_INTEGER);
}
+
+ /**
+ * Returns import for executor service.
+ *
+ * @return import for executor service
+ */
+ public String getExecutorServiceImport() {
+ return getImportString(JAVA_UTIL_CONCURRENT_PKG, EXECUTOR_SERVICE);
+ }
+
+ /**
+ * Returns import for executor.
+ *
+ * @return import for executor
+ */
+ public String getExecutorsImport() {
+ return getImportString(JAVA_UTIL_CONCURRENT_PKG, EXECUTORS);
+ }
+
+ /**
+ * Returns import for RPC command.
+ *
+ * @return import for RPC command
+ */
+ public String getImportForRpcCommand() {
+ return getImportString(CONFIG_PKG, RPC_COMMAND);
+ }
+
+ /**
+ * Returns import for RPC handler.
+ *
+ * @return import for RPC handler
+ */
+ public String getImportForRpcHandler() {
+ return getImportString(CONFIG_PKG, RPC_HANDLER);
+ }
+
+ /**
+ * Returns import for dynamic store service.
+ *
+ * @return import for dynamic store service
+ */
+ public String getImportForDynamicStoreService() {
+ return getImportString(CONFIG_PKG, DYNAMIC_CONFIG_SERVICE);
+ }
+
+ /**
+ * Returns import for data node.
+ *
+ * @return import for data node
+ */
+ public String getImportForDataNode() {
+ return getImportString(MODEL_PKG, DATA_NODE);
+ }
+
+ /**
+ * Returns import for RPC success.
+ *
+ * @return import for RPC success
+ */
+ public String getImportForRpcSuccess() {
+ return getStaticImportString(RPC_OUTPUT_STATUS_PKG, RPC_SUCCESS);
+ }
+
+ /**
+ * Returns import for RPC input.
+ *
+ * @return import for RPC input
+ */
+ public String getImportForRpcInput() {
+ return getImportString(CONFIG_PKG, RPC_INPUT);
+ }
+
+ /**
+ * Returns import for RPC output.
+ *
+ * @return import for RPC output
+ */
+ public String getImportForRpcOutput() {
+ return getImportString(CONFIG_PKG, RPC_OUTPUT);
+ }
+
+ /**
+ * Returns import for model converter.
+ *
+ * @return import for model converter
+ */
+ public String getImportForModelConverter() {
+ return getImportString(MODEL_PKG, MODEL_CONVERTER);
+ }
+
+ /**
+ * Returns import for resource id.
+ *
+ * @return import for resource id
+ */
+ public String getImportForResourceId() {
+ return getImportString(MODEL_PKG, RESOURCE_ID);
+ }
+
+ /**
+ * Returns import for linked list attribute.
+ *
+ * @return import for linked list attribute
+ */
+ public String getImportForLinkedList() {
+ return getImportString(COLLECTION_IMPORTS, LINKED_LIST);
+ }
+
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaCodeFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaCodeFragmentFiles.java
index 6a78c25..9c0efbb 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -24,8 +24,10 @@
import java.io.IOException;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_RPC_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_COMMAND_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
@@ -62,6 +64,16 @@
private TempJavaEventFragmentFiles eventTempFiles;
/**
+ * Has the temporary files required for RPC generated classes.
+ */
+ private TempJavaRpcFragmentFiles rpcTempFiles;
+
+ /**
+ * Has the temporary files required for RPC command generated classes.
+ */
+ private TempJavaRpcCommandFragmentFiles rpcCommandTempFiles;
+
+ /**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
@@ -90,6 +102,14 @@
if ((genType & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
eventTempFiles = new TempJavaEventFragmentFiles(javaFileInfo);
}
+
+ if ((genType & GENERATE_ALL_RPC_CLASS_MASK) != 0) {
+ rpcTempFiles = new TempJavaRpcFragmentFiles(javaFileInfo);
+ }
+
+ if ((genType & GENERATE_RPC_COMMAND_CLASS) != 0) {
+ rpcCommandTempFiles = new TempJavaRpcCommandFragmentFiles(javaFileInfo);
+ }
}
/**
@@ -139,6 +159,24 @@
}
/**
+ * Retrieves the temp file handle for RPC file generation.
+ *
+ * @return temp file handle for RPC file generation
+ */
+ public TempJavaRpcFragmentFiles getRpcFragmentFiles() {
+ return rpcTempFiles;
+ }
+
+ /**
+ * Retrieves the temp file handle for RPC command file generation.
+ *
+ * @return temp file handle for RPC command file generation
+ */
+ public TempJavaRpcCommandFragmentFiles getRpcCommandTempFiles() {
+ return rpcCommandTempFiles;
+ }
+
+ /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -179,6 +217,20 @@
if (fileType == GENERATE_ENUM_CLASS) {
enumTempFiles.generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
+
+ /*
+ * Creates RPC files.
+ */
+ if (fileType == GENERATE_ALL_RPC_CLASS_MASK) {
+ rpcTempFiles.generateJavaFile(GENERATE_ALL_RPC_CLASS_MASK, curNode);
+ }
+
+ /*
+ * Creates RPC command file.
+ */
+ if (fileType == GENERATE_RPC_COMMAND_CLASS) {
+ rpcCommandTempFiles.generateJavaFile(GENERATE_RPC_COMMAND_CLASS, curNode);
+ }
}
/**
@@ -248,5 +300,13 @@
if (eventTempFiles != null) {
eventTempFiles.freeTemporaryResources(isErrorOccurred);
}
+
+ if (rpcTempFiles != null) {
+ rpcTempFiles.freeTemporaryResources(isErrorOccurred);
+ }
+
+ if (rpcCommandTempFiles != null) {
+ rpcCommandTempFiles.freeTemporaryResources(isErrorOccurred);
+ }
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
index 4ea25c7..625f5aa 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
@@ -250,7 +250,6 @@
*/
private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
-
/**
* File name for list key class file name suffix.
*/
@@ -1639,7 +1638,6 @@
getJavaFileHandle(getJavaClassName(
KEY_CLASS_FILE_NAME_SUFFIX));
generateKeyClassFile(keyClassJavaFileHandle, curNode);
-
}
}
//Close all the file handles.
@@ -1804,5 +1802,4 @@
public void setAttrNode(YangNode attrNode) {
this.attrNode = attrNode;
}
-
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcCommandFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcCommandFragmentFiles.java
new file mode 100644
index 0000000..c73fa8a
--- /dev/null
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcCommandFragmentFiles.java
@@ -0,0 +1,497 @@
+/*
+ * Copyright 2017-present 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.yang.compiler.translator.tojava;
+
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.translator.exception.TranslatorException;
+import org.onosproject.yang.compiler.translator.tojava.utils.JavaExtendsListHolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.findRpcInput;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.findRpcOutput;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateRpcCommand;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getVariableDeclaration;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.valueAssign;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_BRANCH_POINT_SCHEMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.BUILD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CREATE_DATA_NODE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CREATE_MODEL;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DATA_NODE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_CAPS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DYNAMIC_CONFIG_SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EQUAL;
+import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.INT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_CONVERTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NULL;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CURLY_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTES;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RESOURCE_ID;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RETURN;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXTENDED_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_INPUT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_OUTPUT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_SUCCESS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH_FOR_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.STATIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SUPER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.THIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocForExecuteMethod;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocForRpcCommandConstructor;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCapitalCase;
+
+/**
+ * Represents implementation of java code fragments temporary
+ * implementations. Maintains the temp files required specific for RPC command
+ * java snippet generation.
+ */
+public class TempJavaRpcCommandFragmentFiles extends TempJavaFragmentFiles {
+
+ /**
+ * Temporary file handle for RPC command class file.
+ */
+ private File rpcCommandClassTempFileHandle;
+
+ private static final String VAR_RPC_INPUT = "rpcInput";
+ private static final String VAR_INPUT = "input";
+ private static final String VAR_OUTPUT = "output";
+ private static final String VAR_MSG_ID = "msgId";
+ private static final String VAR_STORE = "store";
+ private static final String VAR_STORE_SERVICE = "storeService";
+ private static final String VAR_MODEL_CONVERTER = "modelConverter";
+ private static final String EXECUTE = "execute";
+ private static final String GET_RESOURCE_ID = "getResourceId";
+ private static final String VAR_INPUT_OBJECT = "inputObject";
+ private static final String VAR_OUTPUT_OBJECT = "outputObject";
+ private static final String RPC_RESPONSE = "rpcResponse";
+ private static final String VAR_DATA_NODE = "dataNode";
+
+ @Override
+ public void generateJavaFile(int fileType, YangNode curNode) {
+ JavaImportData importData = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getRpcCommandTempFiles()
+ .getJavaImportData();
+ String parentPkg = curNode.getParent().getJavaPackage();
+ String parentClassName = getCapitalCase(getCamelCase(
+ curNode.getParent().getJavaClassNameOrBuiltInType(), null));
+ String className = getCapitalCase(getCamelCase(
+ curNode.getJavaClassNameOrBuiltInType(), null) + COMMAND);
+
+ // add RPC input import
+ YangNode inputNode = findRpcInput(curNode);
+ if (inputNode != null) {
+ JavaQualifiedTypeInfoTranslator inputImport = new
+ JavaQualifiedTypeInfoTranslator();
+ inputImport.setForInterface(false);
+ inputImport.setPkgInfo(inputNode.getJavaPackage());
+ inputImport.setClassInfo(getCapitalCase(getCamelCase(
+ inputNode.getJavaClassNameOrBuiltInType(), null)));
+ importData.addImportInfo(inputImport, className,
+ curNode.getJavaPackage());
+ }
+
+ // add RPC output import
+ YangNode outputNode = findRpcOutput(curNode);
+ if (outputNode != null) {
+ JavaQualifiedTypeInfoTranslator outputImport = new
+ JavaQualifiedTypeInfoTranslator();
+ outputImport.setForInterface(false);
+ outputImport.setPkgInfo(outputNode.getJavaPackage());
+ outputImport.setClassInfo(getCapitalCase(getCamelCase(
+ outputNode.getJavaClassNameOrBuiltInType(), null)));
+ importData.addImportInfo(outputImport, className,
+ curNode.getJavaPackage());
+
+ JavaQualifiedTypeInfoTranslator defaultOutput = new
+ JavaQualifiedTypeInfoTranslator();
+ defaultOutput.setForInterface(false);
+ defaultOutput.setPkgInfo(outputNode.getJavaPackage());
+ defaultOutput.setClassInfo(DEFAULT_CAPS + getCapitalCase(
+ getCamelCase(outputNode.getJavaClassNameOrBuiltInType(),
+ null)));
+ importData.addImportInfo(defaultOutput, className,
+ curNode.getJavaPackage());
+ }
+
+ // add application service import
+ JavaQualifiedTypeInfoTranslator importInfo = new
+ JavaQualifiedTypeInfoTranslator();
+ importInfo.setForInterface(false);
+ importInfo.setPkgInfo(parentPkg);
+ importInfo.setClassInfo(parentClassName + SERVICE);
+ importData.addImportInfo(importInfo, className, curNode
+ .getJavaPackage());
+
+ // add RPC extended command import
+ JavaQualifiedTypeInfoTranslator extendedCmdImport = new
+ JavaQualifiedTypeInfoTranslator();
+ extendedCmdImport.setForInterface(false);
+ extendedCmdImport.setPkgInfo(parentPkg);
+ extendedCmdImport.setClassInfo(RPC_EXTENDED_COMMAND);
+
+ importData.addImportInfo(extendedCmdImport, className,
+ curNode.getJavaPackage());
+
+ List<String> imports = importData.getImports(false);
+ imports.add(importData.getImportForModelConverter());
+ imports.add(importData.getImportForResourceId());
+ imports.add(importData.getImportForRpcInput());
+ imports.add(importData.getImportForRpcOutput());
+ imports.add(importData.getImportForDynamicStoreService());
+ imports.add(importData.getImportForDataNode());
+ imports.add(importData.getImportForRpcSuccess());
+
+ try {
+ rpcCommandClassTempFileHandle = getJavaFileHandle(className);
+ generateRpcCommand(rpcCommandClassTempFileHandle, curNode, imports);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to generate code for RPC command" + curNode.getName());
+ }
+ }
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated file information
+ * @throws IOException when fails to create new file handle
+ */
+ TempJavaRpcCommandFragmentFiles(JavaFileInfoTranslator javaFileInfo)
+ throws IOException {
+ super(javaFileInfo);
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
+ setJavaImportData(new JavaImportData());
+ setJavaFileInfo(javaFileInfo);
+ setAbsoluteDirPath(getAbsolutePackagePath(
+ getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
+ }
+
+ /**
+ * Removes all temporary file handles.
+ *
+ * @param isErrorOccurred flag to tell translator that error has occurred
+ * while code generation
+ * @throws IOException when failed to delete the temporary files
+ */
+ @Override
+ public void freeTemporaryResources(boolean isErrorOccurred)
+ throws IOException {
+ super.freeTemporaryResources(isErrorOccurred);
+ }
+
+ /**
+ * Returns RPC commands contents.
+ *
+ * @return RPC commands contents
+ */
+ public static String getRpcCommandContents(YangNode curNode) {
+ String appService = curNode.getParent()
+ .getJavaClassNameOrBuiltInType() + SERVICE;
+ String className = getCapitalCase(getCamelCase(
+ curNode.getJavaClassNameOrBuiltInType(), null)) + COMMAND;
+
+ // parameters for constructors
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(VAR_STORE, DYNAMIC_CONFIG_SERVICE);
+ param.put(VAR_MODEL_CONVERTER, MODEL_CONVERTER);
+ param.put(appService, getCapitalCase(appService));
+
+ StringBuilder builder = new StringBuilder();
+ // add attributes
+ builder.append(getVariableDeclaration(VAR_MODEL_CONVERTER, MODEL_CONVERTER,
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(appService, getCapitalCase(appService),
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(VAR_STORE_SERVICE, DYNAMIC_CONFIG_SERVICE,
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(NEW_LINE)
+
+ // add constructor
+ .append(getJavaDocForRpcCommandConstructor(
+ curNode.getJavaClassNameOrBuiltInType()))
+ .append(NEW_LINE)
+ .append(multiAttrMethodSignature(className, null, PUBLIC,
+ null, param, CLASS_TYPE,
+ FOUR_SPACE_INDENTATION))
+ .append(EIGHT_SPACE_INDENTATION).append(SUPER)
+ .append(OPEN_PARENTHESIS).append(GET_RESOURCE_ID)
+ .append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON).append(NEW_LINE)
+ .append(valueAssign(THIS + PERIOD + VAR_STORE_SERVICE, VAR_STORE,
+ EIGHT_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + VAR_MODEL_CONVERTER,
+ VAR_MODEL_CONVERTER,
+ EIGHT_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + appService, appService,
+ EIGHT_SPACE_INDENTATION))
+
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE)
+
+ //add execute method
+ .append(getRpcCommandExecuteMethod(appService, curNode))
+
+ //add get resource id method
+ .append(getResourceIdMethod(curNode));
+
+ // add execute method with msgid
+ return builder.toString();
+ }
+
+ /**
+ * Returns RPC command execute method.
+ *
+ * @return RPC command execute method
+ */
+ private static String getRpcCommandExecuteMethod(String appService,
+ YangNode node) {
+ StringBuilder builder = new StringBuilder(getOverRideString())
+
+ // execute method with only RPC input
+ .append(FOUR_SPACE_INDENTATION).append(PUBLIC).append(SPACE)
+ .append(VOID).append(SPACE).append(EXECUTE)
+ .append(OPEN_PARENTHESIS).append(RPC_INPUT)
+ .append(SPACE).append(VAR_RPC_INPUT).append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE)
+
+ // execute method with RPC input and msg id
+ .append(NEW_LINE).append(getJavaDocForExecuteMethod())
+ .append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(PUBLIC)
+ .append(SPACE).append(VOID).append(SPACE).append(EXECUTE)
+ .append(OPEN_PARENTHESIS).append(RPC_INPUT).append(SPACE)
+ .append(VAR_RPC_INPUT).append(COMMA).append(SPACE).append(INT)
+ .append(SPACE).append(VAR_MSG_ID).append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+
+ .append(getExecuteMethodContents(node, appService))
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns get resource id method.
+ *
+ * @return get resource id method
+ */
+ private static String getResourceIdMethod(YangNode node) {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+
+ builder.append(FOUR_SPACE_INDENTATION).append(PRIVATE).append(SPACE)
+ .append(STATIC).append(SPACE).append(RESOURCE_ID).append(SPACE)
+ .append(GET_RESOURCE_ID).append(OPEN_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+
+ // constructing resource id for RPC
+ .append(EIGHT_SPACE_INDENTATION).append(RETURN).append(SPACE)
+ .append(NEW).append(SPACE).append(RESOURCE_ID).append(PERIOD)
+ .append(BUILDER).append(OPEN_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS).append(PERIOD)
+ .append(ADD_BRANCH_POINT_SCHEMA).append(OPEN_PARENTHESIS)
+ .append(QUOTES).append(SLASH_FOR_STRING).append(QUOTES)
+ .append(COMMA).append(SPACE).append(NULL)
+ .append(CLOSE_PARENTHESIS).append(NEW_LINE)
+ .append(SIXTEEN_SPACE_INDENTATION).append(PERIOD)
+ .append(ADD_BRANCH_POINT_SCHEMA).append(OPEN_PARENTHESIS)
+ .append(QUOTES).append(node.getName()).append(QUOTES)
+ .append(COMMA).append(SPACE).append(QUOTES).append(
+ node.getParent().getNameSpace().getModuleNamespace())
+ .append(QUOTES).append(CLOSE_PARENTHESIS).append(PERIOD)
+ .append(BUILD).append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE).append(FOUR_SPACE_INDENTATION)
+ .append(CLOSE_CURLY_BRACKET).append(NEW_LINE);
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns execute method contents.
+ *
+ * @return execute method contents
+ */
+ private static String getExecuteMethodContents(YangNode node, String
+ appService) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(invokeCreateModelString(node))
+ .append(invokeRpcString(node, appService))
+ .append(invokeCreateDataNodeString(node))
+ .append(createRpcOutputString(node))
+ .append(invokeRpcResponseString());
+ return builder.toString();
+ }
+
+ /**
+ * Returns create model for input data node statement.
+ *
+ * @return create model for input data node statement
+ */
+ private static String invokeCreateModelString(YangNode node) {
+ StringBuilder builder = new StringBuilder();
+ YangNode inputNode = findRpcInput(node);
+ if (inputNode != null) {
+ String inputName = getCapitalCase(getCamelCase(
+ inputNode.getJavaClassNameOrBuiltInType(), null));
+ builder.append(EIGHT_SPACE_INDENTATION).append(inputName).append(SPACE)
+ .append(VAR_INPUT_OBJECT).append(SPACE).append(EQUAL).append(SPACE)
+ .append(VAR_MODEL_CONVERTER).append(PERIOD)
+ .append(CREATE_MODEL).append(OPEN_PARENTHESIS)
+ .append(VAR_RPC_INPUT).append(PERIOD).append(VAR_INPUT)
+ .append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON).append(NEW_LINE);
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Returns creating data node for output object.
+ *
+ * @return creating data node for output object
+ */
+ private static String invokeCreateDataNodeString(YangNode node) {
+ StringBuilder builder = new StringBuilder();
+ YangNode outputNode = findRpcOutput(node);
+ if (outputNode != null) {
+ String outputName = getCapitalCase(getCamelCase(
+ outputNode.getJavaClassNameOrBuiltInType(), null));
+ builder.append(EIGHT_SPACE_INDENTATION).append(DATA_NODE).append(SPACE)
+ .append(VAR_DATA_NODE).append(SPACE).append(EQUAL)
+ .append(SPACE).append(VAR_MODEL_CONVERTER).append(PERIOD)
+ .append(CREATE_DATA_NODE).append(OPEN_PARENTHESIS)
+ .append(OPEN_PARENTHESIS).append(DEFAULT_CAPS)
+ .append(outputName).append(CLOSE_PARENTHESIS).append(SPACE)
+ .append(VAR_OUTPUT_OBJECT).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE);
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Returns execute method contents.
+ *
+ * @param node YANG RPC node
+ * @param appService application service name
+ * @return execute method contents
+ */
+ private static String invokeRpcString(YangNode node, String appService) {
+ StringBuilder builder = new StringBuilder();
+ String rpc = getCamelCase(node.getJavaClassNameOrBuiltInType(), null);
+ YangNode inputNode = findRpcInput(node);
+ YangNode outputNode = findRpcOutput(node);
+ String outputName = null;
+ if (outputNode != null) {
+ outputName = getCapitalCase(getCamelCase(
+ outputNode.getJavaClassNameOrBuiltInType(), null));
+ }
+
+ if (inputNode != null && outputNode != null) {
+ builder.append(EIGHT_SPACE_INDENTATION).append(outputName)
+ .append(SPACE).append(VAR_OUTPUT_OBJECT).append(SPACE)
+ .append(EQUAL).append(SPACE).append(appService)
+ .append(PERIOD).append(rpc).append(OPEN_PARENTHESIS)
+ .append(VAR_INPUT_OBJECT).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE);
+ } else if (inputNode != null && outputNode == null) {
+ builder.append(EIGHT_SPACE_INDENTATION).append(appService)
+ .append(PERIOD).append(rpc).append(OPEN_PARENTHESIS)
+ .append(VAR_INPUT_OBJECT).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE);
+ } else if (inputNode == null && outputNode != null) {
+ builder.append(EIGHT_SPACE_INDENTATION).append(outputName)
+ .append(SPACE).append(VAR_OUTPUT_OBJECT).append(SPACE)
+ .append(EQUAL).append(SPACE).append(appService)
+ .append(PERIOD).append(rpc).append(OPEN_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON)
+ .append(NEW_LINE);
+ } else {
+ builder.append(EIGHT_SPACE_INDENTATION).append(appService)
+ .append(PERIOD).append(rpc).append(OPEN_PARENTHESIS)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON)
+ .append(NEW_LINE);
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Returns creating RPC output statement.
+ *
+ * @param node YANG RPC node
+ * @return creating RPC output statement
+ */
+ private static String createRpcOutputString(YangNode node) {
+ YangNode outputNode = findRpcOutput(node);
+ String dataNode = VAR_DATA_NODE;
+ if (outputNode == null) {
+ dataNode = NULL;
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(EIGHT_SPACE_INDENTATION).append(RPC_OUTPUT).append(SPACE)
+ .append(VAR_OUTPUT).append(SPACE).append(EQUAL).append(SPACE)
+ .append(NEW).append(SPACE).append(RPC_OUTPUT)
+ .append(OPEN_PARENTHESIS).append(RPC_SUCCESS).append(COMMA)
+ .append(SPACE).append(dataNode).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE);
+ return builder.toString();
+ }
+
+ /**
+ * Returns invoking rpc response statement.
+ *
+ * @return invoking rpc response statement
+ */
+ private static String invokeRpcResponseString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(EIGHT_SPACE_INDENTATION).append(VAR_STORE_SERVICE)
+ .append(PERIOD).append(RPC_RESPONSE).append(OPEN_PARENTHESIS)
+ .append(VAR_MSG_ID).append(COMMA).append(SPACE)
+ .append(VAR_OUTPUT).append(CLOSE_PARENTHESIS).append(SEMI_COLON)
+ .append(NEW_LINE);
+ return builder.toString();
+ }
+
+}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcFragmentFiles.java
new file mode 100644
index 0000000..b886222
--- /dev/null
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaRpcFragmentFiles.java
@@ -0,0 +1,593 @@
+/*
+ * Copyright 2017-present 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.yang.compiler.translator.tojava;
+
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.YangRpc;
+import org.onosproject.yang.compiler.translator.tojava.utils.JavaExtendsListHolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.FOUR_SPACE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateRegisterRpc;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateRpcExtendedCommand;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateRpcHandler;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getParaMeterisiedConstructor;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.createNewInstance;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithImpl;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getForLoopString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getVariableDeclaration;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodClose;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.valueAssign;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CREATE_RPC_CMD_JAVADOC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_RPC_HANDLER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DYNAMIC_CONFIG_SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EQUAL;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EXECUTORS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EXECUTOR_SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.INT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.INTEGER_WRAPPER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_CONVERTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CURLY_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OVERRIDE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.REGISTER_RPC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.REGISTER_RPC_JAVADOC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RESOURCE_ID;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXECUTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXECUTER_JAVADOC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXTENDED_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_HANDLER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_INPUT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RUN;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RUNNABLE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SUPER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.THIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
+import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.closeFile;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocForExtendedExecuteMethod;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocForRpcExecuterConstructor;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocForRpcExtendedCommandConstructor;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDocWithoutParam;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavadocForRegisterRpcConstructor;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getSmallCase;
+
+/**
+ * Represents implementation of java service code fragments temporary
+ * implementations. Maintains the temp files required specific for RPC
+ * java snippet generation.
+ */
+public class TempJavaRpcFragmentFiles extends TempJavaFragmentFiles {
+
+ /**
+ * Java file handle for RPC handler file.
+ */
+ private File rpcHandlerFileHandler;
+
+ /**
+ * Java file handle for RPC extended command file.
+ */
+ private File rpcExtendedCommandFileHandler;
+
+ /**
+ * Java file handle for RPC register file.
+ */
+ private File rpcRegisterFileHandler;
+
+ private static final String VAR_CMD_ID = "cmdId";
+ private static final String VAR_RPC_INPUT = "rpcInput";
+ private static final String VAR_EXECUTOR = "executor";
+ private static final String VAR_RPC_HANDLER = "rpcHandler";
+ private static final String VAR_CMD = "cmd";
+ private static final String VAR_INPUT = "input";
+ private static final String VAR_MSG_ID = "msgId";
+ private static final String VAR_STORE = "store";
+ private static final String VAR_RPC_COMMANDS = "rpcCommands";
+ private static final String VAR_RPC_COMMAND = "rpcCommand";
+ private static final String VAR_STORE_SERVICE = "storeService";
+ private static final String VAR_MODEL_CONVERTER = "modelConverter";
+ private static final String EXECUTE = "execute";
+ private static final String EXECUTE_RPC = "executeRpc";
+ private static final String REGISTER_RPC_METHOD = "registerRpc";
+ private static final String REGISTER_HANDLER = "registerHandler";
+ private static final String CREATE_RPC_CMDS = "createRpcCommands";
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated file information
+ * @throws IOException when fails to create new file handle
+ */
+ TempJavaRpcFragmentFiles(JavaFileInfoTranslator javaFileInfo)
+ throws IOException {
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
+ setJavaImportData(new JavaImportData());
+ setJavaFileInfo(javaFileInfo);
+ setAbsoluteDirPath(getAbsolutePackagePath(
+ getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
+ }
+
+ /**
+ * Constructs java code.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+
+ generateRpcExtendedCommandFile(curNode);
+
+ generateRpcHandlerFile(curNode);
+
+ generateRpcRegisterFile(curNode);
+
+ // close all the file handles
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Constructs RPC handler code.
+ *
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ private void generateRpcHandlerFile(YangNode curNode)
+ throws IOException {
+ JavaImportData importData = ((JavaCodeGeneratorInfo)
+ curNode).getTempJavaCodeFragmentFiles().getRpcFragmentFiles()
+ .getJavaImportData();
+
+ List<String> imports = importData.getImports(false);
+ imports.add(importData.getExecutorServiceImport());
+ imports.add(importData.getExecutorsImport());
+ imports.add(importData.getImportForRpcHandler());
+ imports.add(importData.getImportForRpcCommand());
+ imports.add(importData.getImportForRpcInput());
+
+ rpcHandlerFileHandler = getJavaFileHandle(DEFAULT_RPC_HANDLER);
+ generateRpcHandler(rpcHandlerFileHandler, curNode, imports);
+ }
+
+ /**
+ * Constructs RPC extended command code.
+ *
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ private void generateRpcExtendedCommandFile(YangNode curNode)
+ throws IOException {
+ JavaImportData importData = ((JavaCodeGeneratorInfo)
+ curNode).getTempJavaCodeFragmentFiles().getRpcFragmentFiles()
+ .getJavaImportData();
+
+ List<String> imports = importData.getImports(false);
+ imports.add(importData.getImportForResourceId());
+ imports.add(importData.getImportForRpcInput());
+ imports.add(importData.getImportForRpcCommand());
+
+ rpcExtendedCommandFileHandler = getJavaFileHandle(RPC_EXTENDED_COMMAND);
+ generateRpcExtendedCommand(rpcExtendedCommandFileHandler, curNode,
+ imports);
+ }
+
+ /**
+ * Constructs register RPC code.
+ *
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ private void generateRpcRegisterFile(YangNode curNode)
+ throws IOException {
+ JavaImportData importData = ((JavaCodeGeneratorInfo)
+ curNode).getTempJavaCodeFragmentFiles().getRpcFragmentFiles()
+ .getJavaImportData();
+
+ // add imports of all RPC commands
+ YangNode child = curNode.getChild();
+ while (child != null) {
+ if (child instanceof YangRpc) {
+ JavaQualifiedTypeInfoTranslator cmdImport = new
+ JavaQualifiedTypeInfoTranslator();
+ cmdImport.setForInterface(false);
+ cmdImport.setPkgInfo(child.getJavaPackage());
+ cmdImport.setClassInfo(getCapitalCase(getCamelCase(
+ child.getJavaClassNameOrBuiltInType(), null)) +
+ COMMAND);
+ importData.addImportInfo(cmdImport, REGISTER_RPC,
+ curNode.getJavaPackage());
+ }
+ child = child.getNextSibling();
+ }
+
+ List<String> imports = importData.getImports(false);
+ imports.add(importData.getImportForLinkedList());
+ imports.add(importData.getImportForList());
+ imports.add(importData.getImportForRpcCommand());
+ imports.add(importData.getImportForRpcHandler());
+ imports.add(importData.getImportForDynamicStoreService());
+ imports.add(importData.getImportForModelConverter());
+
+ rpcRegisterFileHandler = getJavaFileHandle(REGISTER_RPC);
+ generateRegisterRpc(rpcRegisterFileHandler, curNode, imports);
+ }
+
+ /**
+ * Removes all temporary file handles.
+ *
+ * @param errorOccurred flag indicating error
+ * @throws IOException when failed to delete the temporary files
+ */
+ @Override
+ public void freeTemporaryResources(boolean errorOccurred)
+ throws IOException {
+ closeFile(rpcHandlerFileHandler, errorOccurred);
+ closeFile(rpcExtendedCommandFileHandler, errorOccurred);
+ closeFile(rpcRegisterFileHandler, errorOccurred);
+ super.freeTemporaryResources(errorOccurred);
+ }
+
+ /**
+ * Returns RPC handler class contents.
+ *
+ * @return RPC handler class contents
+ */
+ public static String getRpcHandlerContents() {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+
+ // add executor attribute
+ builder.append(FOUR_SPACE_INDENTATION).append(PRIVATE).append(SPACE)
+ .append(EXECUTOR_SERVICE).append(SPACE).append(VAR_EXECUTOR)
+ .append(SEMI_COLON).append(NEW_LINE)
+
+ // add execute RPC method
+ .append(getExecuteRpcMethod())
+
+ // add RPC executer class
+ .append(getRpcExecuterClass());
+ return builder.toString();
+ }
+
+ /**
+ * Returns RPC extended command class contents.
+ *
+ * @return RPC extended command class contents
+ */
+ public static String getRpcExtendedCommandContents() {
+ StringBuilder builder = new StringBuilder(NEW_LINE)
+
+ // add constructor with resource id parameter
+ .append(getJavaDocForRpcExtendedCommandConstructor())
+ .append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(PUBLIC)
+ .append(SPACE).append(RPC_EXTENDED_COMMAND)
+ .append(OPEN_PARENTHESIS).append(RESOURCE_ID).append(SPACE)
+ .append(VAR_CMD_ID).append(CLOSE_PARENTHESIS).append(SPACE)
+ .append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+ .append(EIGHT_SPACE_INDENTATION).append(SUPER)
+ .append(OPEN_PARENTHESIS).append(VAR_CMD_ID)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON).append(NEW_LINE)
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE)
+
+ //add execute method
+ .append(NEW_LINE).append(getJavaDocForExtendedExecuteMethod())
+ .append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(PUBLIC)
+ .append(SPACE).append(ABSTRACT).append(SPACE).append(VOID)
+ .append(SPACE).append(EXECUTE).append(OPEN_PARENTHESIS)
+ .append(RPC_INPUT).append(SPACE).append(VAR_RPC_INPUT)
+ .append(COMMA).append(SPACE).append(INT).append(SPACE)
+ .append(VAR_MSG_ID).append(CLOSE_PARENTHESIS).append(SEMI_COLON)
+ .append(NEW_LINE);
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns register RPC class contents.
+ *
+ * @return register RPC class contents
+ */
+ public static String getRegisterRpcContents(YangNode node) {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+
+ String appService = getCamelCase(node.getJavaClassNameOrBuiltInType(),
+ null) + SERVICE;
+
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(VAR_STORE, DYNAMIC_CONFIG_SERVICE);
+ param.put(VAR_MODEL_CONVERTER, MODEL_CONVERTER);
+ param.put(appService, getCapitalCase(appService));
+
+ // add attributes
+ builder.append(getVariableDeclaration(VAR_RPC_COMMANDS, "List<RpcCommand>",
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(VAR_RPC_HANDLER, RPC_HANDLER,
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(VAR_STORE_SERVICE,
+ DYNAMIC_CONFIG_SERVICE,
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(VAR_MODEL_CONVERTER,
+ MODEL_CONVERTER,
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(getVariableDeclaration(appService, getCapitalCase(appService),
+ FOUR_SPACE_INDENTATION, PRIVATE))
+ .append(NEW_LINE)
+
+ // add constructor
+ .append(getJavadocForRegisterRpcConstructor()).append(NEW_LINE)
+
+ .append(multiAttrMethodSignature(REGISTER_RPC, null, PUBLIC,
+ null, param, CLASS_TYPE,
+ FOUR_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + VAR_RPC_COMMANDS, "new " +
+ "LinkedList<RpcCommand>()", EIGHT_SPACE_INDENTATION))
+ .append(valueAssign("this." + VAR_RPC_HANDLER,
+ "new DefaultRpcHandler()",
+ EIGHT_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + VAR_STORE_SERVICE, VAR_STORE,
+ EIGHT_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + VAR_MODEL_CONVERTER,
+ VAR_MODEL_CONVERTER,
+ EIGHT_SPACE_INDENTATION))
+ .append(valueAssign(THIS + PERIOD + appService, appService,
+ EIGHT_SPACE_INDENTATION))
+
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE)
+
+ // add register rpc method
+ .append(getRegisterRpcMethod())
+
+ // add create rpc method
+ .append(getCreateRpcCommandMethod(node));
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns execute RPC method.
+ *
+ * @return execute RPC method
+ */
+ private static String getExecuteRpcMethod() {
+ // execute method parameters
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(VAR_MSG_ID, INTEGER_WRAPPER);
+ param.put(VAR_CMD, RPC_COMMAND);
+ param.put(VAR_INPUT, RPC_INPUT);
+
+ // constructor parameters for RPC executer
+ List<String> parameters = new LinkedList<>();
+ parameters.add(VAR_MSG_ID);
+ parameters.add("(RpcExtendedCommand) cmd");
+ parameters.add(VAR_INPUT);
+
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ // method signature
+ builder.append(multiAttrMethodSignature(EXECUTE_RPC, null, PUBLIC,
+ VOID, param, CLASS_TYPE,
+ FOUR_SPACE_INDENTATION))
+
+ // method body
+ .append(valueAssign(VAR_EXECUTOR, EXECUTORS +
+ ".newSingleThreadExecutor()", EIGHT_SPACE_INDENTATION))
+
+ .append(EIGHT_SPACE_INDENTATION).append(VAR_EXECUTOR).append(PERIOD)
+ .append(EXECUTE).append(OPEN_PARENTHESIS)
+ .append(createNewInstance(RPC_EXECUTER, EMPTY_STRING,
+ parameters))
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON).append(NEW_LINE)
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ /**
+ * Returns contents of RPC executer class.
+ *
+ * @return contents of RPC executer class
+ */
+ public static String getRpcExecuterClass() {
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(VAR_MSG_ID, INTEGER_WRAPPER);
+ param.put(VAR_CMD, RPC_EXTENDED_COMMAND);
+ param.put(VAR_INPUT, RPC_INPUT);
+
+ StringBuilder builder = new StringBuilder();
+ builder.append(getJavaDocWithoutParam(RPC_EXECUTER_JAVADOC,
+ FOUR_SPACE_INDENTATION))
+ .append(FOUR_SPACE_INDENTATION).append(
+ getDefaultDefinitionWithImpl(CLASS, RPC_EXECUTER, PUBLIC,
+ RUNNABLE))
+
+ // add attributes
+ .append(getVariableDeclaration(VAR_MSG_ID, INTEGER_WRAPPER,
+ EIGHT_SPACE_INDENTATION, null))
+ .append(getVariableDeclaration(VAR_CMD, RPC_EXTENDED_COMMAND,
+ EIGHT_SPACE_INDENTATION, null))
+ .append(getVariableDeclaration(VAR_INPUT, RPC_INPUT,
+ EIGHT_SPACE_INDENTATION, null))
+
+ // add constructor
+ .append(getJavaDocForRpcExecuterConstructor()).append(NEW_LINE)
+ .append(getParaMeterisiedConstructor(RPC_EXECUTER, PUBLIC,
+ param,
+ EIGHT_SPACE_INDENTATION))
+ .append(NEW_LINE)
+
+ // add run method
+ .append(getRunMethod())
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ /**
+ * Returns run method.
+ *
+ * @return run method
+ */
+ private static String getRunMethod() {
+ StringBuilder builder = new StringBuilder();
+ // method signature
+ builder.append(EIGHT_SPACE_INDENTATION).append(OVERRIDE)
+ .append(NEW_LINE).append(EIGHT_SPACE_INDENTATION)
+ .append(PUBLIC).append(SPACE).append(VOID).append(SPACE)
+ .append(RUN).append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+
+ // method body
+ .append(TWELVE_SPACE_INDENTATION).append(VAR_CMD).append(PERIOD)
+ .append(EXECUTE).append(OPEN_PARENTHESIS).append(VAR_INPUT)
+ .append(COMMA).append(SPACE).append(VAR_MSG_ID)
+ .append(CLOSE_PARENTHESIS).append(SEMI_COLON).append(NEW_LINE)
+ .append(EIGHT_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+ return builder.toString();
+ }
+
+ /**
+ * Returns register RPC method.
+ *
+ * @return register RPC method
+ */
+ private static String getRegisterRpcMethod() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(getJavaDocWithoutParam(REGISTER_RPC_JAVADOC,
+ FOUR_SPACE_INDENTATION))
+ .append(FOUR_SPACE_INDENTATION).append(PUBLIC).append(SPACE)
+ .append(VOID).append(SPACE).append(REGISTER_RPC_METHOD)
+ .append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+
+ .append(EIGHT_SPACE_INDENTATION).append(CREATE_RPC_CMDS)
+ .append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE)
+
+ .append(getForLoopString(EIGHT_SPACE_INDENTATION, RPC_COMMAND,
+ VAR_RPC_COMMAND, VAR_RPC_COMMANDS))
+ .append(TWELVE_SPACE_INDENTATION).append(VAR_STORE_SERVICE)
+ .append(PERIOD).append(REGISTER_HANDLER).append(OPEN_PARENTHESIS)
+ .append(VAR_RPC_HANDLER).append(COMMA).append(SPACE)
+ .append(VAR_RPC_COMMAND).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE)
+
+ .append(EIGHT_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE)
+
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+ return builder.toString();
+ }
+
+ /**
+ * Returns create RPC command method.
+ *
+ * @return create RPC command method
+ */
+ private static String getCreateRpcCommandMethod(YangNode node) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(getJavaDocWithoutParam(CREATE_RPC_CMD_JAVADOC,
+ FOUR_SPACE_INDENTATION))
+ .append(FOUR_SPACE_INDENTATION).append(PUBLIC).append(SPACE)
+ .append(VOID).append(SPACE).append(CREATE_RPC_CMDS)
+ .append(OPEN_PARENTHESIS).append(CLOSE_PARENTHESIS)
+ .append(SPACE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
+ .append(getCreateRpcCmdContents(node))
+ .append(FOUR_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+ return builder.toString();
+ }
+
+ /**
+ * Returns create RPC command contents.
+ *
+ * @return create RPC command contents
+ */
+ private static String getCreateRpcCmdContents(YangNode node) {
+ StringBuilder builder = new StringBuilder();
+ YangNode child = node.getChild();
+ while (child != null) {
+ if (child instanceof YangRpc) {
+ builder.append(getCreateRpcCommand(child));
+ }
+ child = child.getNextSibling();
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Returns create RPC command method.
+ *
+ * @param node YANG RPC node
+ * @return create RPC command method
+ */
+ public static String getCreateRpcCommand(YangNode node) {
+ StringBuilder builder = new StringBuilder();
+ String appService = node.getParent().getJavaClassNameOrBuiltInType()
+ + SERVICE;
+ String cmdName = getSmallCase(node.getJavaClassNameOrBuiltInType());
+
+ // creates RPC command
+ builder.append(EIGHT_SPACE_INDENTATION).append(RPC_COMMAND).append(SPACE)
+ .append(cmdName).append(SPACE).append(EQUAL).append(SPACE)
+ .append(NEW).append(SPACE).append(getCapitalCase(
+ node.getJavaClassNameOrBuiltInType())).append(COMMAND)
+ .append(OPEN_PARENTHESIS).append(VAR_STORE_SERVICE).append(COMMA).append(SPACE)
+ .append(VAR_MODEL_CONVERTER).append(COMMA)
+ .append(SPACE).append(appService).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE)
+
+ // adds RPC command to list
+ .append(EIGHT_SPACE_INDENTATION).append(VAR_RPC_COMMANDS)
+ .append(PERIOD).append(ADD_STRING).append(OPEN_PARENTHESIS)
+ .append(cmdName).append(CLOSE_PARENTHESIS).append(SEMI_COLON)
+ .append(NEW_LINE);
+ return builder.toString();
+ }
+}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
index ddc83f2..a5d56a0 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
@@ -29,6 +29,7 @@
import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
+import org.onosproject.yang.compiler.datamodel.YangRpc;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
import org.onosproject.yang.compiler.datamodel.YangTranslatorOperatorNode;
import org.onosproject.yang.compiler.datamodel.YangType;
@@ -275,7 +276,8 @@
*/
translator.getEnumTempFiles()
.addEnumAttributeToTempFiles((YangNode) info, config);
- } else if (!(info instanceof YangChoice)) {
+ } else if (!(info instanceof YangChoice) && !(info instanceof
+ YangRpc)) {
/*Do nothing, only the interface needs to be generated for choice*/
throw new TranslatorException(
getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE, info));
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
index 51fb388..a4a3057 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
@@ -31,6 +31,7 @@
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcNotificationPresent;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_RPC_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
@@ -180,6 +181,8 @@
if (isRpcNotificationPresent(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ getTempJavaCodeFragmentFiles()
+ .generateJavaFile(GENERATE_ALL_RPC_CLASS_MASK, this);
}
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaRpcTranslator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaRpcTranslator.java
index a23a7e4..fdf032a 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaRpcTranslator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaRpcTranslator.java
@@ -34,7 +34,9 @@
import java.io.IOException;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.generateJava;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_CHILD_NODE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
@@ -59,6 +61,7 @@
*/
public YangJavaRpcTranslator() {
setJavaFileInfo(new JavaFileInfoTranslator());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_RPC_COMMAND_CLASS);
}
/**
@@ -107,8 +110,17 @@
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
- // Add package information for rpc and create corresponding folder.
- updatePackageInfo(this, yangPlugin);
+ // Add package information for RPC and create corresponding folder.
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for RPC node " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + " " + e.getLocalizedMessage());
+ }
}
/**
@@ -174,6 +186,16 @@
throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
e.getLocalizedMessage()));
}
- // No file will be generated during RPC exit.
+
+ // generate RPC command file
+ try {
+ generateJava(GENERATE_RPC_COMMAND_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for RPC node " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + " " + e.getLocalizedMessage());
+ }
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
index db01b11..1a82f0d 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -34,12 +34,17 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_EXTENDED_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_HANDLER_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_REGISTER_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yang.compiler.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND_WITH_VALUE;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.brackets;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getAbstractClassDefinitionWithExtends;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getDefaultDefinition;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithExtends;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithImpl;
@@ -53,8 +58,10 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMAND;
import static org.onosproject.yang.compiler.utils.UtilConstants.COMPARABLE;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_CAPS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_RPC_HANDLER;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.ENUM;
import static org.onosproject.yang.compiler.utils.UtilConstants.ERROR_MSG_JAVA_IDENTITY;
@@ -73,9 +80,14 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
import static org.onosproject.yang.compiler.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.REGISTER_RPC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXTENDED_COMMAND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_HANDLER;
import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
import static org.onosproject.yang.compiler.utils.UtilConstants.SUBJECT;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.trimAtLast;
@@ -148,6 +160,14 @@
return getClassDefinition(yangName);
case GENERATE_IDENTITY_CLASS:
return getIdentityClassDefinition(yangName, curNode);
+ case GENERATE_RPC_HANDLER_CLASS:
+ return getRpcHandlerClassDefinition();
+ case GENERATE_RPC_REGISTER_CLASS:
+ return getRpcRegisterClassDefination();
+ case GENERATE_RPC_COMMAND_CLASS:
+ return getRpcCommandClassDefination(curNode);
+ case GENERATE_RPC_EXTENDED_COMMAND_CLASS:
+ return getRpcExtendedCommandClassDefination();
default:
return null;
}
@@ -429,4 +449,45 @@
def = builder.toString();
return trimAtLast(def, COMMA);
}
+
+ /**
+ * Returns RPC handler class definition.
+ *
+ * @return RPC handler class definition
+ */
+ private static String getRpcHandlerClassDefinition() {
+ return getDefinitionWithImplements(CLASS, DEFAULT_RPC_HANDLER,
+ PUBLIC, RPC_HANDLER);
+ }
+
+ /**
+ * Returns register RPC class definition.
+ *
+ * @return register RPC class definition
+ */
+ private static String getRpcRegisterClassDefination() {
+ return getDefaultDefinition(CLASS, REGISTER_RPC, PUBLIC);
+ }
+
+ /**
+ * Returns RPC command class definition.
+ *
+ * @return RPC command class definition
+ */
+ private static String getRpcCommandClassDefination(YangNode yangNode) {
+ String className = getCapitalCase(getCamelCase(
+ yangNode.getJavaClassNameOrBuiltInType(), null)) + COMMAND;
+ return getDefaultDefinitionWithExtends(CLASS, className,
+ PUBLIC, RPC_EXTENDED_COMMAND);
+ }
+
+ /**
+ * Returns extended RPC command class definition.
+ *
+ * @return extended RPC command class definition
+ */
+ private static String getRpcExtendedCommandClassDefination() {
+ return getAbstractClassDefinitionWithExtends(CLASS, RPC_EXTENDED_COMMAND,
+ PUBLIC, RPC_COMMAND);
+ }
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
index 1a5deba..96c0649 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
@@ -48,6 +48,10 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_EXTENDED_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_HANDLER_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_REGISTER_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -72,6 +76,10 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles.getListOfAttributesForKey;
+import static org.onosproject.yang.compiler.translator.tojava.TempJavaRpcCommandFragmentFiles.getRpcCommandContents;
+import static org.onosproject.yang.compiler.translator.tojava.TempJavaRpcFragmentFiles.getRegisterRpcContents;
+import static org.onosproject.yang.compiler.translator.tojava.TempJavaRpcFragmentFiles.getRpcExtendedCommandContents;
+import static org.onosproject.yang.compiler.translator.tojava.TempJavaRpcFragmentFiles.getRpcHandlerContents;
import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.FOUR_SPACE;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.addStaticAttributeIntRange;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.addStaticAttributeLongRange;
@@ -123,8 +131,10 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMAND;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_CAPS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_RPC_HANDLER;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.ENUM_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.EVENT_CLASS;
@@ -142,7 +152,9 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PROTECTED;
import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.REGISTER_RPC;
import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_CLASS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_EXTENDED_COMMAND;
import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE_METHOD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.TYPEDEF_CLASS;
@@ -1037,4 +1049,91 @@
return holder.getListOfLeaf() != null &&
!holder.getListOfLeaf().isEmpty();
}
+
+ /**
+ * Generates RPC handler file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @return rpc class file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateRpcHandler(File file, YangNode curNode,
+ List<String> imports)
+ throws IOException {
+ initiateJavaFileGeneration(file, GENERATE_RPC_HANDLER_CLASS, imports,
+ curNode, DEFAULT_RPC_HANDLER);
+
+ insertDataIntoJavaFile(file, getRpcHandlerContents());
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates RPC extended command file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateRpcExtendedCommand(File file, YangNode curNode,
+ List<String> imports)
+ throws IOException {
+ initiateJavaFileGeneration(file, GENERATE_RPC_EXTENDED_COMMAND_CLASS, imports,
+ curNode, RPC_EXTENDED_COMMAND);
+
+ insertDataIntoJavaFile(file, getRpcExtendedCommandContents());
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates RPC command file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateRpcCommand(File file, YangNode curNode,
+ List<String> imports)
+ throws IOException {
+ String className = getCapitalCase(getCamelCase(
+ curNode.getJavaClassNameOrBuiltInType(), null)) + COMMAND;
+ initiateJavaFileGeneration(file, GENERATE_RPC_COMMAND_CLASS, imports,
+ curNode, className);
+
+ insertDataIntoJavaFile(file, getRpcCommandContents(curNode));
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates register RPC file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateRegisterRpc(File file, YangNode curNode,
+ List<String> imports)
+ throws IOException {
+ initiateJavaFileGeneration(file, GENERATE_RPC_REGISTER_CLASS, imports,
+ curNode, REGISTER_RPC);
+
+ insertDataIntoJavaFile(file, getRegisterRpcContents(curNode));
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
index 6668e2d..e3c418a 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -52,6 +52,10 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_EXTENDED_COMMAND_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_HANDLER_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_REGISTER_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -100,6 +104,10 @@
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.REGISTER_RPC;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.RPC_COMMAND;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.RPC_EXTENDED_CMD;
+import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.RPC_HANDLER;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
@@ -460,6 +468,21 @@
appendHeaderContents(file, pkgString, importsList);
write(file, genType, EVENT_SUBJECT_CLASS, curNode, className, false);
break;
+ case GENERATE_RPC_HANDLER_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, RPC_HANDLER, curNode, className, false);
+ break;
+ case GENERATE_RPC_REGISTER_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, REGISTER_RPC, curNode, className, false);
+ break;
+ case GENERATE_RPC_COMMAND_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, RPC_COMMAND, curNode, className, false);
+ break;
+ case GENERATE_RPC_EXTENDED_COMMAND_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, RPC_EXTENDED_CMD, curNode, className, false);
default:
break;
}
@@ -564,8 +587,9 @@
private static void write(File file, int genType, JavaDocType javaDocType,
YangNode curNode, String fileName, boolean isForClass)
throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName,
- isForClass, null));
+ insertDataIntoJavaFile(file, getJavaDoc(
+ javaDocType, curNode.getJavaClassNameOrBuiltInType(), isForClass,
+ null));
insertDataIntoJavaFile(file, generateClassDefinition(genType,
fileName, curNode));
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodClassTypes.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodClassTypes.java
index 54322cb..96cbed4 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodClassTypes.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodClassTypes.java
@@ -19,7 +19,7 @@
/**
* Represents java method types for classes.
*/
-enum MethodClassTypes {
+public enum MethodClassTypes {
//Method for interface files.
INTERFACE_TYPE,
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
index 9c14997..a5e764d 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
@@ -93,6 +93,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodSignatureClose;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.signatureClose;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.valueAssign;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_AUGMENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
@@ -1208,7 +1209,7 @@
map.put(SCHEMA_NAME, STRING_DATA_TYPE);
builder.append(multiAttrMethodSignature(className, EMPTY_STRING,
EMPTY_STRING, null,
- map, CLASS_TYPE))
+ map, CLASS_TYPE, FOUR_SPACE_INDENTATION))
.append(methodBody(SETTER, clsName, EMPTY_STRING,
EIGHT_SPACE_INDENTATION, EMPTY_STRING,
EMPTY_STRING, false, null))
@@ -1388,7 +1389,7 @@
map.put(VALUE, newType);
builder.append(multiAttrMethodSignature(VALIDATE_RANGE, EMPTY_STRING,
PRIVATE, BOOLEAN_DATA_TYPE, map,
- CLASS_TYPE));
+ CLASS_TYPE, FOUR_SPACE_INDENTATION));
if (type.contentEquals(BIG_INTEGER)) {
//Create new instance of big integer.
builder.append(getNewInstance(BIG_INTEGER, var, EIGHT_SPACE_INDENTATION,
@@ -1453,7 +1454,8 @@
param.put(attr.getAttributeName() + VALUE_CAPS, retType);
return multiAttrMethodSignature(methodName, null, null,
className, param,
- INTERFACE_TYPE);
+ INTERFACE_TYPE,
+ FOUR_SPACE_INDENTATION);
default:
return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
className, retType,
@@ -1506,7 +1508,8 @@
builder.append(multiAttrMethodSignature(methodName,
null, PUBLIC,
name, param,
- CLASS_TYPE))
+ CLASS_TYPE,
+ FOUR_SPACE_INDENTATION))
.append(getIfConditionForAddToListMethod(attr));
retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD +
PUT + getOpenCloseParaWithValue(
@@ -1930,4 +1933,28 @@
.append(signatureClose()).append(methodClose(FOUR_SPACE));
return builder.toString();
}
+
+ /**
+ * Returns parameterisied constructor string.
+ *
+ * @param name class name
+ * @param modifierType modifier type
+ * @param params parameters for constrcutors
+ * @return parameterisied constructor method string
+ */
+ public static String getParaMeterisiedConstructor(String name,
+ String modifierType,
+ Map<String, String> params,
+ String space) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(multiAttrMethodSignature(name, null, modifierType, null,
+ params, CLASS_TYPE, space));
+ for (Map.Entry<String, String> entry : params.entrySet()) {
+ builder.append(valueAssign(THIS + PERIOD + entry.getKey(),
+ entry.getKey(), space + FOUR_SPACE_INDENTATION));
+ }
+
+ builder.append(space).append(CLOSE_CURLY_BRACKET).append(NEW_LINE);
+ return builder.toString();
+ }
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
index 796079b..afe663e 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
@@ -26,6 +26,8 @@
import java.util.Arrays;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -45,6 +47,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.AND;
import static org.onosproject.yang.compiler.utils.UtilConstants.APP_INSTANCE;
@@ -129,6 +132,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.STATIC;
import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_BUILDER;
import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_BUILDER_VAR;
import static org.onosproject.yang.compiler.utils.UtilConstants.THIS;
@@ -386,9 +390,13 @@
/**
* Returns value assignment.
*
+ * @param param variable to which value to be assigned
+ * @param value value to be assigned
+ * @param indentation indentation of the statement
* @return value assignment
*/
- static String valueAssign(String param, String value, String indentation) {
+ public static String valueAssign(String param, String value, String
+ indentation) {
return indentation + param + SPACE + EQUAL + SPACE + value +
signatureClose();
}
@@ -484,13 +492,15 @@
* @param methodReturnType method's return type
* @param params parameters
* @param type type of method
+ * @param space indentation of method
* @return method signature for multi attribute methods
*/
- static String multiAttrMethodSignature(String methodName, String
+ public static String multiAttrMethodSignature(String methodName, String
prefix, String modifier, String methodReturnType,
- Map<String, String> params,
- MethodClassTypes type) {
- StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
+ Map<String, String> params,
+ MethodClassTypes type,
+ String space) {
+ StringBuilder methodBuilder = new StringBuilder(space);
String method = EMPTY_STRING;
if (modifier != null) {
method = modifier + SPACE;
@@ -533,7 +543,7 @@
* @param type method class type
* @return method signature for interface and implementation classes
*/
- static String methodSignature(
+ public static String methodSignature(
String methodName, String prefix, String modifier, String paraVal,
String methodReturnType, String paraReturnType,
MethodClassTypes type) {
@@ -965,10 +975,10 @@
* @param impl implements class name
* @return class definition
*/
- static String getDefaultDefinitionWithImpl(String classType,
- String name, String
- modifier,
- String impl) {
+ public static String getDefaultDefinitionWithImpl(String classType,
+ String name,
+ String modifier,
+ String impl) {
String mod = EMPTY_STRING;
if (modifier != null) {
mod = modifier + SPACE;
@@ -1153,8 +1163,8 @@
* @param data data variable/collection
* @return for loop string
*/
- static String getForLoopString(String space, String type, String var,
- String data) {
+ public static String getForLoopString(String space, String type, String var,
+ String data) {
return space + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE + var +
SPACE + COLON + SPACE + data + CLOSE_PARENTHESIS +
methodSignatureClose(CLASS_TYPE);
@@ -1251,4 +1261,91 @@
static String getQualifiedString(String pkg, String cls) {
return pkg + PERIOD + cls;
}
+
+ /**
+ * Returns new instance string.
+ *
+ * @param className class name
+ * @param space indentation
+ * @param parameters parameters for constructor
+ * @return new instance string
+ */
+ public static String createNewInstance(String className, String space,
+ List<String> parameters) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(space).append(NEW).append(SPACE).append(className)
+ .append(OPEN_PARENTHESIS);
+
+ if (parameters != null && !parameters.isEmpty()) {
+ Iterator<String> iterator = parameters.iterator();
+ while (iterator.hasNext()) {
+ builder.append(iterator.next());
+ if (iterator.hasNext()) {
+ builder.append(COMMA).append(SPACE);
+ }
+ }
+ }
+
+ builder.append(CLOSE_PARENTHESIS);
+ return builder.toString();
+ }
+
+ /**
+ * Returns variable declaration string.
+ *
+ * @param varName name of variable
+ * @param varType type of variable
+ * @param space indentation of the statement
+ * @param modifier modifier name
+ * @return return variable declaration string
+ */
+ public static String getVariableDeclaration(String varName, String varType,
+ String space, String modifier) {
+ StringBuilder builder = new StringBuilder(space);
+ if (modifier != null) {
+ builder.append(modifier).append(SPACE);
+ }
+ builder.append(varType).append(SPACE)
+ .append(varName).append(SEMI_COLON).append(NEW_LINE);
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns abstract class definition for java file when extends a
+ * interface.
+ *
+ * @param classType class type
+ * @param name name of class
+ * @param modifier modifier for class
+ * @param extend extends class name
+ * @return abstract class definition
+ */
+ static String getAbstractClassDefinitionWithExtends(String classType,
+ String name, String
+ modifier,
+ String extend) {
+ String mod = EMPTY_STRING;
+ if (modifier != null) {
+ mod = modifier + SPACE;
+ }
+ return mod + ABSTRACT + SPACE + classType + SPACE + name + SPACE +
+ EXTEND + SPACE
+ + extend + defCloseString();
+ }
+
+ /**
+ * Returns static import string.
+ *
+ * @param pkg package
+ * @param cls class
+ * @return static import string
+ */
+ public static String getStaticImportString(String pkg, String cls) {
+ StringBuilder builder = new StringBuilder()
+ .append(IMPORT).append(STATIC).append(SPACE)
+ .append(pkg).append(PERIOD).append(cls).append(signatureClose());
+ return builder.toString();
+ }
+
}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index e62f284..5fd7a4d 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1815,6 +1815,162 @@
*/
public static final String YANG_META_DATA = "YangMetaData.ser";
+ /**
+ * Static attribute for concurrent import package.
+ */
+ public static final String JAVA_UTIL_CONCURRENT_PKG = "java.util" +
+ ".concurrent";
+
+ /**
+ * Static attribute for config import package.
+ */
+ public static final String CONFIG_PKG = "org.onosproject.config";
+
+ /**
+ * Static attribute for model import package.
+ */
+ public static final String MODEL_PKG = "org.onosproject.yang.model";
+
+ /**
+ * Static attribute for RPC execution status import package.
+ */
+ public static final String RPC_OUTPUT_STATUS_PKG = "org.onosproject.config" +
+ ".RpcOutput.Status";
+
+ /**
+ * Static param for model converter.
+ */
+ public static final String MODEL_CONVERTER = "ModelConverter";
+
+ /**
+ * Static param for resource id.
+ */
+ public static final String RESOURCE_ID = "ResourceId";
+
+ /**
+ * Static param for dynamic config service.
+ */
+ public static final String DYNAMIC_CONFIG_SERVICE = "DynamicConfigService";
+
+ /**
+ * Static param for RPC handler.
+ */
+ public static final String RPC_HANDLER = "RpcHandler";
+
+ /**
+ * Static param for RPC command.
+ */
+ public static final String RPC_COMMAND = "RpcCommand";
+
+ /**
+ * Static param for RPC input.
+ */
+ public static final String RPC_INPUT = "RpcInput";
+
+ /**
+ * Static param for RPC output.
+ */
+ public static final String RPC_OUTPUT = "RpcOutput";
+
+ /**
+ * Static param for RPC success.
+ */
+ public static final String RPC_SUCCESS = "RPC_SUCCESS";
+
+ /**
+ * Static param for RPC executer.
+ */
+ public static final String RPC_EXECUTER = "RpcExecuter";
+
+ /**
+ * Static attribute for extends.
+ */
+ public static final String EXTENDS = "extends";
+
+ /**
+ * Static attribute for super.
+ */
+ public static final String SUPER = "super";
+
+ /**
+ * Static attribute for linked list.
+ */
+ public static final String LINKED_LIST = "LinkedList";
+
+ /**
+ * Static attribute for data node.
+ */
+ public static final String DATA_NODE = "DataNode";
+
+ /**
+ * Static attribute for executor service.
+ */
+ public static final String EXECUTOR_SERVICE = "ExecutorService";
+
+ /**
+ * Static attribute for executors.
+ */
+ public static final String EXECUTORS = "Executors";
+
+ /**
+ * Static attribute for default RPC handler.
+ */
+ public static final String DEFAULT_RPC_HANDLER = "DefaultRpcHandler";
+
+ /**
+ * Static attribute for RPC extended command.
+ */
+ public static final String RPC_EXTENDED_COMMAND = "RpcExtendedCommand";
+
+ /**
+ * Static attribute for register RPC.
+ */
+ public static final String REGISTER_RPC = "RegisterRpc";
+
+ /**
+ * JavaDocs's description for RPC handler.
+ */
+ public static final String JAVA_DOC_RPC_HANDLER = "RPC handler";
+
+ /**
+ * JavaDocs's description for register RPC.
+ */
+ public static final String JAVA_DOC_REGISTER_RPC = "register RPC";
+
+ /**
+ * JavaDocs's description for RPC executer.
+ */
+ public static final String JAVA_DOC_RPC_EXECUTER = "Runnable capable of " +
+ "invoking the appropriate RPC command's execute method";
+
+ public static final String JAVA_DOC_RPC_EXTENDED_CMD = "* Abstract " +
+ "implementation of an RPC extended command";
+
+ public static final String COMMAND = "Command";
+
+ public static final String REGISTER_RPC_JAVADOC = " * Registers RPC " +
+ "handler with dynamic config service";
+
+ public static final String CREATE_RPC_CMD_JAVADOC = " * Creates RPC " +
+ "command for all the RPC";
+
+ public static final String RPC_EXECUTER_JAVADOC = " * Runnable " +
+ "capable of invoking the appropriate RPC command's execute method";
+
+ public static final String RUNNABLE = "Runnable";
+
+ public static final String RUN = "run";
+
+ public static final String BUILDER = "Builder";
+
+ public static final String BUILD = "build";
+
+ public static final String ADD_BRANCH_POINT_SCHEMA = "addBranchPointSchema";
+
+ public static final String CREATE_MODEL = "createModel";
+
+ public static final String CREATE_DATA_NODE = "createDataNode";
+
// No instantiation.
private UtilConstants() {
}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
index 12256c7..8e5643b 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
@@ -39,8 +39,12 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_OF;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_PARAM;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_REGISTER_RPC;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_RETURN;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_RPC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_RPC_EXECUTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_RPC_EXTENDED_CMD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_RPC_HANDLER;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
@@ -155,6 +159,23 @@
case ADD_TO_LIST: {
return generateForAddToList(name, compilerAnnotation);
}
+ case RPC_HANDLER: {
+ return generateForClass(JAVA_DOC_RPC_HANDLER);
+ }
+ case RPC_COMMAND: {
+ return generateForClass(name);
+ }
+ case REGISTER_RPC: {
+ return generateForClass(JAVA_DOC_REGISTER_RPC);
+ }
+ case RPC_EXECUTER: {
+ return getJavaDocWithoutParam(JAVA_DOC_RPC_EXECUTER,
+ EMPTY_STRING);
+ }
+ case RPC_EXTENDED_CMD: {
+ return getJavaDocWithoutParam(JAVA_DOC_RPC_EXTENDED_CMD,
+ EMPTY_STRING);
+ }
default: {
return generateForConstructors(name);
}
@@ -416,6 +437,17 @@
EMPTY_STRING, isForDefaultClass);
}
+ /**
+ * Generates javaDocs for the impl class.
+ *
+ * @param className class name
+ * @return javaDocs javadocs in string
+ */
+ private static String generateForClass(String className) {
+ return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC +
+ className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
+ }
+
private static String addFlagJavaDoc() {
return " *\n" +
" * <p>\n" +
@@ -660,6 +692,107 @@
return FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
+ /**
+ * Returns data in javadoc format.
+ *
+ * @param data content of javadoc
+ * @param space indendation for javadoc
+ * @return data in javadoc format
+ */
+ public static String getJavaDocWithoutParam(String data, String space) {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+ builder.append(space).append(JAVA_DOC_FIRST_LINE).append(SPACE)
+ .append(data).append(PERIOD).append(NEW_LINE)
+ .append(space).append(JAVA_DOC_END_LINE);
+ return builder.toString();
+ }
+
+ /**
+ * Returns javadoc for RPC executer constructor.
+ *
+ * @return javadoc for RPC executer constructor
+ */
+ public static String getJavaDocForRpcExecuterConstructor() {
+ return "\n /**\n" +
+ " * Constructs a RPC executor for the given msg id, RPC command and\n" +
+ " * RPC input.\n" +
+ " *\n" +
+ " * @param msgId msgId of the RPC message to be executed\n" +
+ " * @param cmd RPC command to be executed\n" +
+ " * @param input input data to the RPC command\n" +
+ " */";
+ }
+
+ /**
+ * Returns javadoc for RPC command constructor.
+ *
+ * @return javadoc for RPC command constructor
+ */
+ public static String getJavaDocForRpcCommandConstructor(String rpcName) {
+ return " /**\n" +
+ " * Constructs a " + rpcName + " command for the given " +
+ "cmd id, model converter,\n * application service.\n *\n" +
+ " * @param cmdId identifier of RPC command\n" +
+ " * @param modelConverter model converter for convertion\n" +
+ " * @param allService application service\n */";
+ }
+
+ /**
+ * Returns javadoc for RPC extended command constructor.
+ *
+ * @return javadoc for RPC extended command constructor
+ */
+ public static String getJavaDocForRpcExtendedCommandConstructor() {
+ return " /**\n" +
+ " * Creates an instance of RPC extended command.\n" +
+ " *\n" +
+ " * @param cmdId of RPC command\n" +
+ " */";
+ }
+
+ /**
+ * Returns javadoc for RPC extended command execute method.
+ *
+ * @return javadoc for RPC extended command execute method
+ */
+ public static String getJavaDocForExtendedExecuteMethod() {
+ return " /**\n" +
+ " * Executes the RPC command.\n" +
+ " *\n" +
+ " * @param input input data to the RPC command\n" +
+ " * @param msgId of the RPC message to be executed\n" +
+ " */";
+ }
+
+ /**
+ * Returns javadoc for execute method.
+ *
+ * @return javadoc for execute method
+ */
+ public static String getJavaDocForExecuteMethod() {
+ return " /**\n" +
+ " * Executes the RPC command.\n" +
+ " *\n" +
+ " * @param rpcInput input data to the RPC command\n" +
+ " * @param msgId msgId of the RPC message to be executed\n" +
+ " */";
+ }
+
+ /**
+ * Returns javadoc for register RPC constructor.
+ *
+ * @return javadoc for register RPC constructor
+ */
+ public static String getJavadocForRegisterRpcConstructor() {
+ return " /**\n" +
+ " * Constructs a register rpc for the given store service, mode converter and\n" +
+ " * application service.\n" +
+ " *\n" +
+ " * @param store dynamic config service\n" +
+ " * @param modelConverter model converter for convertion\n" +
+ " * @param allService application service\n" +
+ " */";
+ }
/**
* JavaDocs types.
@@ -775,5 +908,30 @@
* For add to list.
*/
ADD_TO_LIST,
+
+ /**
+ * For RPC handler.
+ */
+ RPC_HANDLER,
+
+ /**
+ * For RPC command.
+ */
+ RPC_COMMAND,
+
+ /**
+ * For register RPC.
+ */
+ REGISTER_RPC,
+
+ /**
+ * For RPC executer.
+ */
+ RPC_EXECUTER,
+
+ /**
+ * For RPC extended command.
+ */
+ RPC_EXTENDED_CMD
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
index f188058..83969a2 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
@@ -123,7 +123,6 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
- YangPluginConfig.compileCode(COMP);
deleteDirectory(DIR);
}
@@ -151,7 +150,6 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
- YangPluginConfig.compileCode(COMP);
deleteDirectory(DIR);
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java
deleted file mode 100644
index 2ad4cc8..0000000
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2016-present 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.yang.compiler.plugin.maven;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.junit.Test;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
-
-/**
- * Unit test case for process sub tree code generation test.
- */
-public class ProcessSubTreeCodeGenTest {
-
- private final YangCompilerManager utilManager =
- new YangCompilerManager();
- private static final String DIR = "target/pstf/";
- private static final String COMP = System.getProperty("user.dir") + File
- .separator + DIR;
-
- /**
- * Checks pst translation should not result in any exception.
- *
- * @throws MojoExecutionException
- */
- @Test
- public void processTranslator() throws IOException, ParserException, MojoExecutionException {
-
- YangIoUtils.deleteDirectory(DIR);
- String searchDir = "src/test/resources/pstcodegen";
-
- Set<Path> paths = new HashSet<>();
- for (String file : getYangFiles(searchDir)) {
- paths.add(Paths.get(file));
- }
-
- utilManager.createYangFileInfoSet(paths);
- utilManager.parseYangFileInfoSet();
- utilManager.createYangNodeSet();
- utilManager.resolveDependenciesUsingLinker();
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir(DIR);
- utilManager.translateToJava(yangPluginConfig);
- YangPluginConfig.compileCode(COMP);
- YangIoUtils.deleteDirectory(DIR);
- }
-}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RpcTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RpcTranslatorTest.java
index f4b35bb..ea2320c 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RpcTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RpcTranslatorTest.java
@@ -18,11 +18,11 @@
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
import java.io.File;
import java.io.IOException;
@@ -50,7 +50,6 @@
JavaCodeGeneratorUtil.generateJavaCode(node, yangPluginConfig);
String dir1 = System.getProperty("user.dir") + File.separator + dir;
- YangPluginConfig.compileCode(dir1);
YangIoUtils.deleteDirectory(dir);
}
// TODO enhance the test cases, after having a framework of translator test.
diff --git a/compiler/plugin/maven/src/test/resources/augmentTranslator/test.yang b/compiler/plugin/maven/src/test/resources/augmentTranslator/test.yang
index a5a0daf..608482d 100644
--- a/compiler/plugin/maven/src/test/resources/augmentTranslator/test.yang
+++ b/compiler/plugin/maven/src/test/resources/augmentTranslator/test.yang
@@ -138,7 +138,7 @@
}
}
- augment /test1:rpc-input/test1:input {
+ /* augment /test1:rpc-input/test1:input {
leaf leaf2 {
type int32;
}
@@ -160,7 +160,7 @@
leaf leaf2 {
type int32;
}
- }
+ }*/
}
diff --git a/compiler/plugin/maven/src/test/resources/augmentTranslator/test2.yang b/compiler/plugin/maven/src/test/resources/augmentTranslator/test2.yang
index 1eae21b..5d19838 100644
--- a/compiler/plugin/maven/src/test/resources/augmentTranslator/test2.yang
+++ b/compiler/plugin/maven/src/test/resources/augmentTranslator/test2.yang
@@ -27,7 +27,7 @@
}
}
- rpc rpc-input {
+ /* rpc rpc-input {
input {
leaf leaf1 {
type int32;
@@ -54,7 +54,7 @@
type int32;
}
}
- }
+ }*/
}
diff --git a/compiler/plugin/maven/src/test/resources/choiceAugment/test2.yang b/compiler/plugin/maven/src/test/resources/choiceAugment/test2.yang
index 4caa38b..8862396 100644
--- a/compiler/plugin/maven/src/test/resources/choiceAugment/test2.yang
+++ b/compiler/plugin/maven/src/test/resources/choiceAugment/test2.yang
@@ -11,7 +11,7 @@
reference "";
}
- rpc rpc-input-output {
+ rpc rpc-input-output {
input {
leaf leaf1 {
type int32;
diff --git a/compiler/plugin/maven/src/test/resources/choiceTranslator/all.yang b/compiler/plugin/maven/src/test/resources/choiceTranslator/all.yang
index be2fd07..e124d43 100644
--- a/compiler/plugin/maven/src/test/resources/choiceTranslator/all.yang
+++ b/compiler/plugin/maven/src/test/resources/choiceTranslator/all.yang
@@ -64,7 +64,8 @@
}
}
}
- rpc r {
+
+ /* rpc r {
input {
choice name {
case a {
@@ -93,9 +94,9 @@
}
}
}
- }
+ }*/
- augment /name {
+ /*augment /name {
choice name {
case a {
leaf udp {
@@ -152,6 +153,6 @@
}
}
}
- }
+ } */
}
\ No newline at end of file
diff --git a/compiler/plugin/maven/src/test/resources/groupingNodeSameAsModule/portpair.yang b/compiler/plugin/maven/src/test/resources/groupingNodeSameAsModule/portpair.yang
index 3497f04..65f9009 100644
--- a/compiler/plugin/maven/src/test/resources/groupingNodeSameAsModule/portpair.yang
+++ b/compiler/plugin/maven/src/test/resources/groupingNodeSameAsModule/portpair.yang
@@ -9,21 +9,19 @@
grouping port-pair {
container port-pair {
- leaf name {
- type string;
- }
+ leaf name {
+ type string;
+ }
-
- leaf description {
- type string;
- }
-
- }
+ leaf description {
+ type string;
+ }
+ }
}
- rpc get-port-pair {
+ /* rpc get-port-pair {
output {
uses port-pair;
}
- }
+ } */
}
diff --git a/compiler/plugin/maven/src/test/resources/ietfyang/l3vpnservice/ietf-sd-onos-service-l3vpn.yang b/compiler/plugin/maven/src/test/resources/ietfyang/l3vpnservice/ietf-sd-onos-service-l3vpn.yang
index 7b55f71..8721af1 100644
--- a/compiler/plugin/maven/src/test/resources/ietfyang/l3vpnservice/ietf-sd-onos-service-l3vpn.yang
+++ b/compiler/plugin/maven/src/test/resources/ietfyang/l3vpnservice/ietf-sd-onos-service-l3vpn.yang
@@ -112,7 +112,7 @@
- rpc create-l3vpn-instance {
+ /*rpc create-l3vpn-instance {
description "Create l3vpn instance." ;
input {
container l3vpn-instance {
@@ -312,5 +312,5 @@
}
}
}
- }
+ } */
}
diff --git a/compiler/plugin/maven/src/test/resources/pstcodegen/test.yang b/compiler/plugin/maven/src/test/resources/pstcodegen/test.yang
deleted file mode 100644
index 93e1476..0000000
--- a/compiler/plugin/maven/src/test/resources/pstcodegen/test.yang
+++ /dev/null
@@ -1,83 +0,0 @@
-module test {
- namespace "test:test";
- prefix test;
-
- container cont1 {
- leaf leaf1 {
- type int32;
- }
- leaf-list leaf-list1 {
- type int32;
- }
- list list1 {
- key "name";
- leaf name {
- type string;
- }
- }
- container cont2 {
- leaf leaf2 {
- type int32;
- }
- }
- }
- leaf leaf2 {
- type int32;
- }
- leaf-list leaf-list2 {
- type int32;
- }
- list list2 {
- key "name";
- leaf name {
- type string;
- }
- }
- choice choice1 {
- case case1 {
- leaf leaf3 {
- type int32;
- }
- leaf-list leaf-list3 {
- type int32;
- }
- list list3 {
- key "name";
- leaf name {
- type string;
- }
- }
- }
- }
- grouping group1 {
- container cont1 {
- leaf leaf1 {
- type int32;
- }
- leaf-list leaf-list1 {
- type int32;
- }
- list list1 {
- key "name";
- leaf name {
- type string;
- }
- }
- container cont2 {
- leaf leaf2 {
- type int32;
- }
- }
- }
- }
- rpc rpc1 {
- input {
- uses group1;
- }
- }
- augment /cont1/list1 {
- leaf leaf2 {
- type int64;
- }
- }
-}
\ No newline at end of file