[ONOS-4303, ONOS-4508, ONOS-4509, ONOS-4510, ONOS-4351]notification,rpc,union,sub-module,augment
Change-Id: Ibeed9ff965c13fd66743c1080cb1350d93a3a435
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
index 7a7c96a..b743773 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -24,15 +24,19 @@
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
-import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInParent;
+import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
@@ -59,12 +63,6 @@
public YangJavaRpc() {
super();
setJavaFileInfo(new JavaFileInfo());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_RPC_INTERFACE);
- try {
- setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(getJavaFileInfo()));
- } catch (IOException e) {
- throw new RuntimeException("Failed to create temporary RPC file handle");
- }
}
/**
@@ -115,9 +113,9 @@
YangNode yangNode = this.getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
- javaAttributeInfoOfInput = getCurNodeAsAttributeInParent(yangNode, this, false);
+ javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this);
} else if (yangNode instanceof YangOutput) {
- javaAttributeInfoOfOutput = getCurNodeAsAttributeInParent(yangNode, this, false);
+ javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this);
} else {
// TODO throw exception
}
@@ -139,6 +137,46 @@
}
/**
+ * Creates an attribute info object corresponding to a data model node and
+ * return it.
+ *
+ * @param childNode child data model node(input / output) for which the java code generation
+ * is being handled
+ * @param currentNode parent node (module / sub-module) in which the child node is an attribute
+ * @return AttributeInfo attribute details required to add in temporary
+ * files
+ */
+ public static JavaAttributeInfo getChildNodeAsAttributeInParentService(
+ YangNode childNode, YangNode currentNode) {
+
+ YangNode parentNode = getParentNodeInGenCode(currentNode);
+
+ String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(currentNode,
+ childNodeName);
+ if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("Parent node does not have file info");
+ }
+
+ TempJavaFragmentFiles tempJavaFragmentFiles;
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+
+ if (tempJavaFragmentFiles == null) {
+ throw new TranslatorException("Parent node does not have service file info");
+ }
+
+ JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
+ boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
+ return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
+ }
+
+ /**
* Returns the generated java file information.
*
* @return generated java file information