[ONOS-4527,ONOS-4524,ONOS-4536,ONOS-4541,ONOS-4549,ONOS-4550,ONOS-4557
,ONOS-4558,ONOS-4545,ONOS-4543,ONOS-4546]
Checkstyle error in generated code handled and defect fixed.
Change-Id: Ifef5a22f91d4ee21767f1e2c6d0dd5b5b0b8cfcc
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 93eb417..ea17891 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -65,8 +65,8 @@
while (node != null) {
Parsable parsable = (Parsable) node;
if (node instanceof CollisionDetector
- && (parsable.getYangConstructType() != YangConstructType.USES_DATA)
- && (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) {
+ && parsable.getYangConstructType() != YangConstructType.USES_DATA
+ && parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
@@ -90,7 +90,7 @@
while (node != null) {
Parsable parsable = (Parsable) node;
if (node instanceof CollisionDetector
- && (parsable.getYangConstructType() == dataType)) {
+ && parsable.getYangConstructType() == dataType) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
index 97efebb..91adfbf 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
@@ -138,8 +138,8 @@
* integer number, this is done because under union there
* could be multiple child union types.
*/
- enumerationNode.setName(yangUnion.getName() + yangUnion.getChildUnionNumber()
- + ENUMERATION_CLASS_SUFFIX);
+ enumerationNode.setName(yangUnion.getName() + ENUMERATION_CLASS_SUFFIX
+ + yangUnion.getChildUnionNumber());
// Increment the running number.
yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1);
// Add union as a child to parent union.
diff --git a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index bcbe5af..fbde352 100644
--- a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -21,6 +21,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -35,7 +36,6 @@
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
@@ -69,6 +69,7 @@
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangLinker yangLinker = new YangLinkerManager();
+ private YangFileInfo curYangFileInfo = new YangFileInfo();
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
@@ -161,7 +162,7 @@
return;
}
- //Carry out the parsing for all the YANG files.
+ // Carry out the parsing for all the YANG files.
parseYangFileInfoSet();
// Resolve dependencies using linker.
@@ -170,13 +171,13 @@
// Perform translation to JAVA.
translateToJava(getYangFileInfoSet(), yangPlugin);
- addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
+ addToSource(getDirectory(baseDir, genFilesDir), project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
String fileName = "";
- if (e instanceof TranslatorException) {
- fileName = ((TranslatorException) e).getFileName();
+ if (getCurYangFileInfo() != null) {
+ fileName = getCurYangFileInfo().getYangFileName();
}
try {
translatorErrorHandler(getRootNode());
@@ -198,6 +199,7 @@
*/
public void resolveDependenciesUsingLinker() throws MojoExecutionException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
+ setCurYangFileInfo(yangFileInfo);
try {
yangLinker.resolveDependencies(getYangFileInfoSet());
} catch (LinkerException e) {
@@ -213,6 +215,7 @@
*/
public void parseYangFileInfoSet() throws IOException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
+ setCurYangFileInfo(yangFileInfo);
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
yangFileInfo.setRootNode(yangNode);
@@ -264,7 +267,8 @@
Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFileInfo = yangFileIterator.next();
- generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName());
+ setCurYangFileInfo(yangFileInfo);
+ generateJavaCode(yangFileInfo.getRootNode(), yangPlugin);
}
}
@@ -298,4 +302,22 @@
public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
this.yangFileInfoSet = yangFileInfoSet;
}
+
+ /**
+ * Returns current YANG file's info.
+ *
+ * @return the yangFileInfo
+ */
+ public YangFileInfo getCurYangFileInfo() {
+ return curYangFileInfo;
+ }
+
+ /**
+ * Sets current YANG file's info.
+ *
+ * @param yangFileInfo the yangFileInfo to set
+ */
+ public void setCurYangFileInfo(YangFileInfo yangFileInfo) {
+ this.curYangFileInfo = yangFileInfo;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
index 420520f..d4666c0 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
@@ -84,6 +84,11 @@
public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
/**
+ * Event listener class.
+ */
+ public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
+
+ /**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
index 8352ddc..2ffd282 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
@@ -97,6 +97,31 @@
public static final int RPC_IMPL_MASK = 16384;
/**
+ * Event enum implementation of class.
+ */
+ public static final int EVENT_ENUM_MASK = 32768;
+
+ /**
+ * Event method implementation of class.
+ */
+ public static final int EVENT_METHOD_MASK = 65536;
+
+ /**
+ * Event subject attribute implementation of class.
+ */
+ public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 131072;
+
+ /**
+ * Event subject getter implementation of class.
+ */
+ public static final int EVENT_SUBJECT_GETTER_MASK = 262144;
+
+ /**
+ * Event subject setter implementation of class.
+ */
+ public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
+
+ /**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 6ec67e4..5c06f42 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -66,11 +66,10 @@
*
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
- * @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
- public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName)
+ public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
throws TranslatorException {
YangNode codeGenNode = rootNode;
@@ -80,7 +79,7 @@
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
- generateCodeEntry(codeGenNode, yangPlugin, fileName);
+ generateCodeEntry(codeGenNode, yangPlugin);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
@@ -100,11 +99,11 @@
curTraversal = CHILD;
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
- generateCodeExit(codeGenNode, fileName);
+ generateCodeExit(codeGenNode);
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
- generateCodeExit(codeGenNode, fileName);
+ generateCodeExit(codeGenNode);
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
@@ -117,20 +116,17 @@
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param yangPlugin YANG plugin config
- * @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
- private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName)
+ private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
} else {
- TranslatorException ex = new TranslatorException(
+ throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
- ex.setFileName(fileName);
- throw ex;
}
}
@@ -139,19 +135,16 @@
*
* @param codeGenNode current data model node for which the code needs to be
* generated
- * @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
- private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException {
+ private static void generateCodeExit(YangNode codeGenNode) throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
} else {
- TranslatorException ex = new TranslatorException(
+ throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
- ex.setFileName(fileName);
- throw ex;
}
}
@@ -162,26 +155,28 @@
private static void freeRestResources() {
YangNode freedNode = getCurNode();
- YangNode tempNode = freedNode;
- TraversalType curTraversal = ROOT;
+ if (getCurNode() != null) {
+ YangNode tempNode = freedNode;
+ TraversalType curTraversal = ROOT;
- while (freedNode != tempNode.getParent()) {
+ while (freedNode != tempNode.getParent()) {
- if (curTraversal != PARENT && freedNode.getChild() != null) {
- curTraversal = CHILD;
- freedNode = freedNode.getChild();
- } else if (freedNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- if (freedNode != tempNode) {
- free(freedNode);
+ if (curTraversal != PARENT && freedNode.getChild() != null) {
+ curTraversal = CHILD;
+ freedNode = freedNode.getChild();
+ } else if (freedNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ if (freedNode != tempNode) {
+ free(freedNode);
+ }
+ freedNode = freedNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ if (freedNode != tempNode) {
+ free(freedNode);
+ }
+ freedNode = freedNode.getParent();
}
- freedNode = freedNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- if (freedNode != tempNode) {
- free(freedNode);
- }
- freedNode = freedNode.getParent();
}
}
}
@@ -213,36 +208,38 @@
public static void translatorErrorHandler(YangNode rootNode)
throws IOException {
- /**
- * Free other resources where translator has failed.
- */
- freeRestResources();
+ if (rootNode != null) {
+ /**
+ * Free other resources where translator has failed.
+ */
+ freeRestResources();
- /**
- * Start removing all open files.
- */
- YangNode tempNode = rootNode;
- setCurNode(tempNode.getChild());
- TraversalType curTraversal = ROOT;
+ /**
+ * Start removing all open files.
+ */
+ YangNode tempNode = rootNode;
+ setCurNode(tempNode.getChild());
+ TraversalType curTraversal = ROOT;
- while (tempNode != null) {
+ while (tempNode != null) {
- if (curTraversal != PARENT) {
- close(tempNode);
+ if (curTraversal != PARENT) {
+ close(tempNode);
+ }
+ if (curTraversal != PARENT && tempNode.getChild() != null) {
+ curTraversal = CHILD;
+ tempNode = tempNode.getChild();
+ } else if (tempNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ tempNode = tempNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ tempNode = tempNode.getParent();
+ }
}
- if (curTraversal != PARENT && tempNode.getChild() != null) {
- curTraversal = CHILD;
- tempNode = tempNode.getChild();
- } else if (tempNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- tempNode = tempNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- tempNode = tempNode.getParent();
- }
+
+ freeRestResources();
}
-
- freeRestResources();
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
index 3a53884..03414c0 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
@@ -16,6 +16,8 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
/**
* Represents cached java file handle, which supports the addition of member attributes and
* methods.
@@ -49,6 +51,11 @@
private String codeGenDirFilePath;
/**
+ * Plugin configuration for naming convention.
+ */
+ private YangPluginConfig pluginConfig;
+
+ /**
* Returns the types of files being generated corresponding to the YANG
* definition.
*
@@ -152,4 +159,22 @@
public void setBaseCodeGenPath(String path) {
codeGenDirFilePath = path;
}
+
+ /**
+ * Returns plugin configurations.
+ *
+ * @return the pluginConfig
+ */
+ public YangPluginConfig getPluginConfig() {
+ return pluginConfig;
+ }
+
+ /**
+ * Sets plugin configurations.
+ *
+ * @param pluginConfig the pluginConfig to set
+ */
+ public void setPluginConfig(YangPluginConfig pluginConfig) {
+ this.pluginConfig = pluginConfig;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 7661172..5ccf0b3 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -22,12 +22,14 @@
import static java.util.Collections.sort;
+import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
@@ -35,10 +37,10 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
@@ -218,7 +220,7 @@
* @return import string for ListenerService class
*/
public String getListenerServiceImport() {
- return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
+ return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
}
/**
@@ -227,6 +229,24 @@
* @return import string for ListenerRegistry class
*/
public String getListenerRegistryImport() {
- return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
+ return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for AbstractEvent class.
+ *
+ * @return import string for AbstractEvent class
+ */
+ public String getAbstractEventsImport() {
+ return IMPORT + ONOS_EVENT_PKG + PERIOD + ABSTRACT_EVENT + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for EventListener class.
+ *
+ * @return import string for EventListener class
+ */
+ public String getEventListenerImport() {
+ return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
index 6050f94..52df259 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import com.google.common.base.MoreObjects;
@@ -88,7 +89,7 @@
/**
* Updates the leaf's java information.
*
- * @param leaf leaf whose jave information is being updated
+ * @param leaf leaf whose java information is being updated
*/
public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) {
@@ -102,7 +103,9 @@
* Current leaves holder is adding a leaf info as a attribute to the
* current class.
*/
- String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList());
+ String className =
+ AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
+ leaf.getConflictResolveConfig());
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
@@ -163,17 +166,20 @@
* Returns the java qualified type information for the wrapper classes.
*
* @param referredTypesAttrInfo attribute of referred type
+ * @param confilictResolver plugin configurations
* @return return the import info for this attribute
*/
- public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) {
+ public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo,
+ YangToJavaNamingConflictUtil confilictResolver) {
/*
* Get the java qualified type information for the wrapper classes and
* set it in new java attribute information.
*/
JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo();
+
qualifiedInfoOfFromString.setClassInfo(
- getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true));
+ getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, confilictResolver));
qualifiedInfoOfFromString.setPkgInfo(
getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null));
return qualifiedInfoOfFromString;
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
index 1620bc9..14f4cd2 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
@@ -19,6 +19,8 @@
import java.io.File;
import java.io.IOException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
@@ -84,10 +86,10 @@
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addConstructor(JavaAttributeInfo attr)
+ private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
- getGeneratedJavaFiles()));
+ getGeneratedJavaFiles(), pluginConfig));
}
/**
@@ -98,10 +100,10 @@
* @throws IOException IO operation fail
*/
@Override
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
+ void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
throws IOException {
- super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
- addConstructor(newAttrInfo);
+ super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
+ addConstructor(newAttrInfo, pluginConfig);
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index b7e7d4a..309ee66 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -21,10 +21,9 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
@@ -57,16 +56,6 @@
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
- * Has the temporary files required for generated event classes.
- */
- private TempJavaEventFragmentFiles eventTempFiles;
-
- /**
- * Has the temporary files required for generated event listenerclasses.
- */
- private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
-
- /**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
@@ -79,16 +68,10 @@
setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo));
}
- /**
- * Creates user defined data type class file.
- */
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) {
setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo));
}
- /**
- * Creates enumeration class file.
- */
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) {
setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
}
@@ -97,13 +80,6 @@
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) {
- setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo));
- }
-
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
- setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo));
- }
}
/**
@@ -180,43 +156,6 @@
}
/**
- * Retrieves the temp file handle for event file generation.
- *
- * @return temp file handle for event file generation
- */
- public TempJavaEventFragmentFiles getEventTempFiles() {
- return eventTempFiles;
- }
-
- /**
- * Sets temp file handle for event file generation.
- *
- * @param eventTempFiles temp file handle for event file generation
- */
- public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) {
- this.eventTempFiles = eventTempFiles;
- }
-
- /**
- * Retrieves the temp file handle for event listener file generation.
- *
- * @return temp file handle for event listener file generation
- */
- public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() {
- return eventListenerTempFiles;
- }
-
- /**
- * Sets temp file handle for event listener file generation.
- *
- * @param eventListenerTempFiles temp file handle for event listener file generation
- */
- public void setEventListenerTempFiles(
- TempJavaEventListenerFragmentFiles eventListenerTempFiles) {
- this.eventListenerTempFiles = eventListenerTempFiles;
- }
-
- /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -238,7 +177,7 @@
}
/*
- * Creats service and manager class file.
+ * Creates service and manager class file.
*/
if (fileType == GENERATE_SERVICE_AND_MANAGER) {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
@@ -251,22 +190,6 @@
getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
- if ((fileType & GENERATE_EVENT_CLASS) != 0) {
- /*
- * Creates event class file.
- */
- if (getEventTempFiles() != null) {
- getEventTempFiles().generateJavaFile(fileType, curNode);
- }
- }
-
- if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
- /**
- * Creates event listener class file.
- */
- getEventListenerTempFiles().generateJavaFile(fileType, curNode);
- }
-
freeTemporaryResources(false);
}
@@ -275,14 +198,16 @@
*
* @param newAttrInfo the attribute info that needs to be added to temporary
* files
+ * @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
- public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
+ public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
+ YangPluginConfig pluginConfig)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles()
- .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
+ .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
}
/**
@@ -290,7 +215,7 @@
*/
if (getTypeTempFiles() != null) {
getTypeTempFiles()
- .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
+ .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
}
}
@@ -299,24 +224,26 @@
* generated temporary file.
*
* @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
+ * @param pluginConfig plugin configurations for naming convention
* @throws IOException IO operation fail
*/
- public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
+ public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
throws IOException {
getTypeTempFiles()
- .addTypeInfoToTempFiles(yangTypeHolder);
+ .addTypeInfoToTempFiles(yangTypeHolder, pluginConfig);
}
/**
* Adds build method for interface.
*
+ * @param pluginConfig plugin configurations
* @return build method for interface
* @throws IOException when fails to append to temporary file
*/
- public String addBuildMethodForInterface()
+ public String addBuildMethodForInterface(YangPluginConfig pluginConfig)
throws IOException {
if (getBeanTempFiles() != null) {
- return getBeanTempFiles().addBuildMethodForInterface();
+ return getBeanTempFiles().addBuildMethodForInterface(pluginConfig);
}
throw new TranslatorException("build method only supported for bean class");
}
@@ -326,18 +253,19 @@
*
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
+ * @param pluginConfig plugin configurations
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- public String addDefaultConstructor(String modifier, String toAppend)
+ public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
throws IOException {
if (getTypeTempFiles() != null) {
return getTypeTempFiles()
- .addDefaultConstructor(modifier, toAppend);
+ .addDefaultConstructor(modifier, toAppend, pluginConfig);
}
if (getBeanTempFiles() != null) {
- return getBeanTempFiles().addDefaultConstructor(modifier, toAppend);
+ return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
}
throw new TranslatorException("default constructor should not be added");
@@ -380,13 +308,10 @@
getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
}
- if (getEventTempFiles() != null) {
- getEventTempFiles().freeTemporaryResources(isErrorOccurred);
+ if (getServiceTempFiles() != null) {
+ getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
}
- if (getEventListenerTempFiles() != null) {
- getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred);
- }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
index 1719886..001807a 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
@@ -28,6 +28,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
@@ -175,26 +176,28 @@
* @param curEnumInfo current YANG enum
* @throws IOException when fails to do IO operations.
*/
- private void addAttributesForEnumClass(String curEnumName) throws IOException {
- appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue()));
+ private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException {
+ appendToFile(getEnumClassTempFileHandle(),
+ generateEnumAttributeString(curEnumName, getEnumValue(), pluginConfig));
}
/**
* Adds enum attributes to temporary files.
*
* @param curNode current YANG node
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
- public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
+ public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
- super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum());
+ super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
if (curNode instanceof YangEnumeration) {
YangEnumeration enumeration = (YangEnumeration) curNode;
for (YangEnum curEnum : enumeration.getEnumSet()) {
setEnumValue(curEnum.getValue());
addToEnumStringList(curEnum.getNamedValue());
addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue());
- addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue());
+ addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue(), pluginConfig);
}
} else {
throw new TranslatorException("current node should be of enumeration type.");
@@ -204,13 +207,14 @@
/**
* Returns java attribute for enum class.
*
+ * @param pluginConfig plugin configurations
* @return java attribute
*/
- public JavaAttributeInfo getJavaAttributeForEnum() {
+ public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
YangJavaType<?> javaType = new YangJavaType<>();
javaType.setDataType(YangDataTypes.INT32);
javaType.setDataTypeName("int");
- javaType.updateJavaQualifiedInfo();
+ javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
return getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
javaType.getDataTypeName(), javaType,
@@ -234,8 +238,9 @@
* files
* @throws IOException IO operation fail
*/
- void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException {
- addAttributesForEnumClass(curEnumName);
+ void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
+ throws IOException {
+ addAttributesForEnumClass(curEnumName, pluginConfig);
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
deleted file mode 100644
index bd2742f..0000000
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
+++ /dev/null
@@ -1,131 +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.yangutils.translator.tojava;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-
-/**
- * Represents implementation of java bean code fragments temporary implementations.
- * Maintains the temp files required specific for event java snippet generation.
- */
-public class TempJavaEventFragmentFiles
- extends TempJavaFragmentFiles {
-
- /**
- * File name for generated class file for special type like union, typedef
- * suffix.
- */
- private static final String EVENT_FILE_NAME_SUFFIX = "Event";
-
- /**
- * Java file handle for event file.
- */
- private File eventJavaFileHandle;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
- throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
-
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
-
- }
-
- /**
- * Returns event's java file handle.
- *
- * @return java file handle
- */
- private File getEventJavaFileHandle() {
- return eventJavaFileHandle;
- }
-
- /**
- * Sets event's java file handle.
- *
- * @param eventJavaFileHandle file handle for event
- */
- private void setEventJavaFileHandle(File eventJavaFileHandle) {
- this.eventJavaFileHandle = eventJavaFileHandle;
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- @Override
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
-
- createPackage(curNode);
- String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
- .getJavaFileInfo().getJavaName());
-
- /**
- * Creates event interface file.
- */
- setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX));
- generateEventFile(getEventJavaFileHandle(), curNode, null);
-
- /**
- * Close all the file handles.
- */
- freeTemporaryResources(false);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred when translator fails to generate java files we
- * need to close all open file handles include temporary files
- * and java files.
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
- boolean isError = isErrorOccurred;
- /**
- * Close all java file handles and when error occurs delete the files.
- */
- closeFile(getEventJavaFileHandle(), isError);
-
- super.freeTemporaryResources(isErrorOccurred);
-
- }
-}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java
deleted file mode 100644
index 8009e45..0000000
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java
+++ /dev/null
@@ -1,128 +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.yangutils.translator.tojava;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-
-/**
- * Represents implementation of java bean code fragments temporary implementations.
- * Maintains the temp files required specific for event listener java snippet generation.
- */
-public class TempJavaEventListenerFragmentFiles
- extends TempJavaFragmentFiles {
-
- /**
- * File name for generated class file for special type like union, typedef
- * suffix.
- */
- private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
-
- /**
- * Java file handle for event listener file.
- */
- private File eventListenerJavaFileHandle;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
- throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
- }
-
- /**
- * Returns event listeners's java file handle.
- *
- * @return java file handle
- */
- private File getEventListenerJavaFileHandle() {
- return eventListenerJavaFileHandle;
- }
-
- /**
- * Sets event's java file handle.
- *
- * @param eventListenerJavaFileHandle file handle for event
- */
- private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
- this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- @Override
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
-
- createPackage(curNode);
- String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
- .getJavaFileInfo().getJavaName());
- /**
- * Creates event listener interface file.
- */
- setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
- generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
-
- /**
- * Close all the file handles.
- */
- freeTemporaryResources(false);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred when translator fails to generate java files we
- * need to close all open file handles include temporary files
- * and java files.
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
- boolean isError = isErrorOccurred;
- /**
- * Close all java file handles and when error occurs delete the files.
- */
- closeFile(getEventListenerJavaFileHandle(), isError);
-
- super.freeTemporaryResources(isErrorOccurred);
- }
-
-}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index 59cd01b..c35b744 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -795,35 +795,40 @@
* Adds attribute for class.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addAttribute(JavaAttributeInfo attr)
+ private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
throws IOException {
- appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION);
+ appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
+ + FOUR_SPACE_INDENTATION);
}
/**
* Adds getter for interface.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addGetterForInterface(JavaAttributeInfo attr)
+ private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getGetterInterfaceTempFileHandle(),
- getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
}
/**
* Adds setter for interface.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addSetterForInterface(JavaAttributeInfo attr)
+ private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getSetterInterfaceTempFileHandle(),
- getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE);
+ getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
+ + NEW_LINE);
}
/**
@@ -844,9 +849,10 @@
* Adds getter method's impl for class.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addGetterImpl(JavaAttributeInfo attr)
+ private void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
|| (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
@@ -854,7 +860,7 @@
getGeneratedJavaFiles()) + NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false)
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
@@ -863,11 +869,12 @@
* Adds build method for interface.
*
* @return build method for interface
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- String addBuildMethodForInterface()
+ String addBuildMethodForInterface(YangPluginConfig pluginConfig)
throws IOException {
- return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName());
+ return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
}
/**
@@ -886,23 +893,26 @@
*
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
+ * @param pluginConfig plugin configurations
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- String addDefaultConstructor(String modifier, String toAppend)
+ String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
throws IOException {
- return NEW_LINE + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier);
+ return NEW_LINE
+ + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig);
}
/**
* Adds default constructor for class.
*
+ * @param pluginCnfig plugin configurations
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- public String addOfMethod()
+ public String addOfMethod(YangPluginConfig pluginCnfig)
throws IOException {
- return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false)
+ return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig)
+ getOfMethod(getGeneratedJavaClassName(), null);
}
@@ -994,6 +1004,7 @@
*/
public String getTemporaryDataFromFileHandle(File file)
throws IOException {
+
String path = getTempDirPath();
if (new File(path + file.getName()).exists()) {
return readAppendFile(path + file.getName(), EMPTY_STRING);
@@ -1017,13 +1028,14 @@
* Parses attribute to get the attribute string.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @return attribute string
*/
- private String parseAttribute(JavaAttributeInfo attr) {
+ public String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
/*
* TODO: check if this utility needs to be called or move to the caller
*/
- String attributeName = getCamelCase(attr.getAttributeName(), null);
+ String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
@@ -1056,10 +1068,11 @@
* @param curNode current node which needs to be added as an attribute in
* the parent generated code
* @param isList is list construct
+ * @param pluginConfig plugin configurations
* @throws IOException IO operation exception
*/
public static void addCurNodeInfoInParentTempFile(YangNode curNode,
- boolean isList)
+ boolean isList, YangPluginConfig pluginConfig)
throws IOException {
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
@@ -1071,7 +1084,7 @@
throw new TranslatorException("missing parent temp file handle");
}
getNodesInterfaceFragmentFiles(parent)
- .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
+ .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
}
/**
@@ -1134,8 +1147,9 @@
* Adds parent's info to current node import list.
*
* @param curNode current node for which import list needs to be updated
+ * @param pluginConfig plugin configurations
*/
- public void addParentInfoInCurNodeTempFile(YangNode curNode) {
+ public void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
caseImportInfo = new JavaQualifiedTypeInfo();
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
@@ -1145,7 +1159,8 @@
throw new TranslatorException("missing java file information to get the package details "
+ "of attribute corresponding to child node");
}
- caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), null)));
+ caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
+ pluginConfig.getConflictResolver())));
caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo);
@@ -1167,6 +1182,7 @@
throw new TranslatorException("Leaf does not have java information");
}
JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
+ javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
javaLeaf.updateJavaQualifiedInfo();
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaLeaf.getJavaQualifiedInfo(),
@@ -1174,7 +1190,7 @@
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
false);
- addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
+ addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
}
}
}
@@ -1194,6 +1210,7 @@
throw new TranslatorException("Leaf-list does not have java information");
}
JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
+ javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
javaLeaf.updateJavaQualifiedInfo();
getJavaImportData().setIfListImported(true);
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
@@ -1202,7 +1219,7 @@
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
true);
- addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
+ addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
}
}
}
@@ -1231,21 +1248,22 @@
*
* @param newAttrInfo the attribute info that needs to be added to temporary
* files
+ * @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
+ void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
throws IOException {
setAttributePresent(true);
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
- addAttribute(newAttrInfo);
+ addAttribute(newAttrInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
- addGetterForInterface(newAttrInfo);
+ addGetterForInterface(newAttrInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
- addSetterForInterface(newAttrInfo);
+ addSetterForInterface(newAttrInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
@@ -1253,7 +1271,7 @@
}
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
- addGetterImpl(newAttrInfo);
+ addGetterImpl(newAttrInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
addHashCodeMethod(newAttrInfo);
@@ -1266,7 +1284,8 @@
}
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo);
+ JavaQualifiedTypeInfo qualifiedInfoOfFromString =
+ getQualifiedInfoOfFromString(newAttrInfo, pluginConfig.getConflictResolver());
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
@@ -1309,9 +1328,8 @@
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
- if (isAttributePresent()) {
- imports = getJavaImportData().getImports();
- }
+ imports = getJavaImportData().getImports();
+
createPackage(curNode);
/*
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
index d26d07e..5a5e27f 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -22,26 +22,56 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
+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.JavaCodeSnippetGen.getJavaClassDefClose;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
@@ -62,6 +92,30 @@
private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
/**
+ * File name for event enum temp file.
+ */
+ private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
+
+ /**
+ * File name for event method temp file.
+ */
+ private static final String EVENT_METHOD_FILE_NAME = "EventMethod";
+
+ /**
+ * File name for event subject attribute temp file.
+ */
+ private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute";
+
+ /**
+ * File name for event subject getter temp file.
+ */
+ private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter";
+
+ /**
+ * File name for event subject setter temp file.
+ */
+ private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
+ /**
* File name for generated class file for service
* suffix.
*/
@@ -74,6 +128,41 @@
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
+ * File name for generated class file for special type like union, typedef
+ * suffix.
+ */
+ private static final String EVENT_FILE_NAME_SUFFIX = "Event";
+
+ /**
+ * File name for generated class file for special type like union, typedef
+ * suffix.
+ */
+ private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
+
+ /**
+ * File name for generated class file for special type like union, typedef
+ * suffix.
+ */
+ public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
+
+ private static final String JAVA_FILE_EXTENSION = ".java";
+
+ /**
+ * Java file handle for event subject file.
+ */
+ private File eventSubjectJavaFileHandle;
+
+ /**
+ * Java file handle for event listener file.
+ */
+ private File eventListenerJavaFileHandle;
+
+ /**
+ * Java file handle for event file.
+ */
+ private File eventJavaFileHandle;
+
+ /**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceTempFileHandle;
@@ -94,6 +183,31 @@
private File managerJavaFileHandle;
/**
+ * Java file handle for event enum impl file.
+ */
+ private File eventEnumTempFileHandle;
+
+ /**
+ * Java file handle for event method impl file.
+ */
+ private File eventMethodTempFileHandle;
+
+ /**
+ * Java file handle for event subject attribute file.
+ */
+ private File eventSubjectAttributeTempFileHandle;
+
+ /**
+ * Java file handle for event subject getter impl file.
+ */
+ private File eventSubjectGetterTempFileHandle;
+
+ /**
+ * Java file handle for event subject setter impl file.
+ */
+ private File eventSubjectSetterTempFileHandle;
+
+ /**
* Returns rpc method's java file handle.
*
* @return java file handle
@@ -166,6 +280,60 @@
}
/**
+ * Returns event's java file handle.
+ *
+ * @return java file handle
+ */
+ private File getEventJavaFileHandle() {
+ return eventJavaFileHandle;
+ }
+
+ /**
+ * Sets event's java file handle.
+ *
+ * @param eventJavaFileHandle file handle for event
+ */
+ private void setEventJavaFileHandle(File eventJavaFileHandle) {
+ this.eventJavaFileHandle = eventJavaFileHandle;
+ }
+
+ /**
+ * Returns event listeners's java file handle.
+ *
+ * @return java file handle
+ */
+ private File getEventListenerJavaFileHandle() {
+ return eventListenerJavaFileHandle;
+ }
+
+ /**
+ * Sets event's java file handle.
+ *
+ * @param eventListenerJavaFileHandle file handle for event
+ */
+ private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
+ this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
+ }
+
+ /**
+ * Returns event subject's java file handle.
+ *
+ * @return java file handle
+ */
+ private File getEventSubjectJavaFileHandle() {
+ return eventSubjectJavaFileHandle;
+ }
+
+ /**
+ * Sets event's subject java file handle.
+ *
+ * @param eventSubjectJavaFileHandle file handle for event's subject
+ */
+ private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) {
+ this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle;
+ }
+
+ /**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
@@ -176,11 +344,22 @@
super(javaFileInfo);
addGeneratedTempFile(RPC_INTERFACE_MASK);
-
addGeneratedTempFile(RPC_IMPL_MASK);
+ addGeneratedTempFile(EVENT_ENUM_MASK);
+ addGeneratedTempFile(EVENT_METHOD_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
+
setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
+
+ setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
+ setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
+ setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
+ setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
+ setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
}
/**
@@ -199,13 +378,14 @@
createPackage(curNode);
boolean isNotification = false;
- YangNode tempNode = curNode.getChild();
- while (tempNode != null) {
- if (tempNode instanceof YangJavaNotification) {
+ if (curNode instanceof YangJavaModule) {
+ if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) {
isNotification = true;
- break;
}
- tempNode = tempNode.getNextSibling();
+ } else if (curNode instanceof YangJavaSubModule) {
+ if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) {
+ isNotification = true;
+ }
}
if (isNotification) {
@@ -221,6 +401,7 @@
addListnersImport(curNode, imports, false, LISTENER_SERVICE);
addListnersImport(curNode, imports, true, LISTENER_REG);
}
+ addAnnotationsImports(imports, true);
/**
* Create builder class file.
*/
@@ -231,6 +412,14 @@
if (isNotification) {
addListnersImport(curNode, imports, false, LISTENER_REG);
}
+ addAnnotationsImports(imports, false);
+
+ if (isNotification) {
+ generateEventJavaFile(GENERATE_EVENT_CLASS, curNode);
+ generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode);
+ generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode);
+ }
+
/**
* Close all the file handles.
*/
@@ -243,10 +432,11 @@
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
+ * @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput,
+ JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
String rpcName) throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
@@ -256,9 +446,11 @@
if (javaAttributeInfoOfOutput != null) {
rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName());
}
- appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput)
- + getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
- appendToFile(getRpcImplTempFileHandle(), getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
+ appendToFile(getRpcInterfaceTempFileHandle(),
+ generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput, pluginConfig)
+ + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
+ appendToFile(getRpcImplTempFileHandle(),
+ getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
}
/**
@@ -266,14 +458,99 @@
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
+ * @param pluginConfig plugin configurations
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput,
+ JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
String rpcName)
throws IOException {
- addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
+ addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName);
+ }
+
+ /**
+ * Constructs java code exit.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateEventJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+
+ List<String> imports = new ArrayList<>();
+
+ imports.add(getJavaImportData().getAbstractEventsImport());
+ String curNodeInfo =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName());
+ String nodeName = curNodeInfo + EVENT_STRING;
+
+ addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
+
+ /**
+ * Creates event interface file.
+ */
+ setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
+ generateEventFile(getEventJavaFileHandle(), curNode, imports);
+
+ /**
+ * Close all the file handles.
+ */
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Constructs java code exit.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateEventListenerJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+
+ List<String> imports = new ArrayList<>();
+
+ imports.add(getJavaImportData().getEventListenerImport());
+ String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo().getJavaName());
+ /**
+ * Creates event listener interface file.
+ */
+ setEventListenerJavaFileHandle(
+ getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
+ generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
+
+ /**
+ * Close all the file handles.
+ */
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Constructs java code exit.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateEventSubjectJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+
+ String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo().getJavaName());
+ /**
+ * Creates event interface file.
+ */
+ setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
+ EVENT_SUBJECT_NAME_SUFFIX));
+ generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
+
+ /**
+ * Close all the file handles.
+ */
+ freeTemporaryResources(false);
}
/**
@@ -290,6 +567,18 @@
boolean isError = isErrorOccurred;
closeFile(getServiceInterfaceJavaFileHandle(), isError);
+ closeFile(getManagerJavaFileHandle(), isError);
+
+ if (getEventJavaFileHandle() != null) {
+ closeFile(getEventJavaFileHandle(), isError);
+ }
+ if (getEventListenerJavaFileHandle() != null) {
+ closeFile(getEventListenerJavaFileHandle(), isError);
+ }
+ if (getEventSubjectJavaFileHandle() != null) {
+ closeFile(getEventSubjectJavaFileHandle(), isError);
+ }
+
closeFile(getRpcInterfaceTempFileHandle(), true);
closeFile(getRpcImplTempFileHandle(), true);
closeFile(getGetterInterfaceTempFileHandle(), true);
@@ -299,4 +588,206 @@
super.freeTemporaryResources(isErrorOccurred);
}
+
+ /**
+ * Returns event enum temp file.
+ *
+ * @return event enum temp file
+ */
+ public File getEventEnumTempFileHandle() {
+ return eventEnumTempFileHandle;
+ }
+
+ /**
+ * Sets event enum temp file.
+ *
+ * @param eventEnumTempFileHandle event enum temp file
+ */
+ public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
+ this.eventEnumTempFileHandle = eventEnumTempFileHandle;
+ }
+
+ /**
+ * Returns event method temp file.
+ *
+ * @return event method temp file
+ */
+ public File getEventMethodTempFileHandle() {
+ return eventMethodTempFileHandle;
+ }
+
+ /**
+ * Sets event method temp file.
+ *
+ * @param eventMethodTempFileHandle event method temp file
+ */
+ public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
+ this.eventMethodTempFileHandle = eventMethodTempFileHandle;
+ }
+
+ /**
+ * Returns event subject attribute temp file.
+ *
+ * @return event subject attribute temp file
+ */
+ public File getEventSubjectAttributeTempFileHandle() {
+ return eventSubjectAttributeTempFileHandle;
+ }
+
+ /**
+ * Sets event subject attribute temp file.
+ *
+ * @param eventSubjectAttributeTempFileHandle event subject attribute temp file
+ */
+ public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
+ this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
+ }
+
+ /**
+ * Returns event subject getter temp file.
+ *
+ * @return event subject getter temp file
+ */
+ public File getEventSubjectGetterTempFileHandle() {
+ return eventSubjectGetterTempFileHandle;
+ }
+
+ /**
+ * Sets event subject getter temp file.
+ *
+ * @param eventSubjectGetterTempFileHandle event subject getter temp file
+ */
+ public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
+ this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
+ }
+
+ /**
+ * Returns event subject setter temp file.
+ *
+ * @return event subject setter temp file
+ */
+ public File getEventSubjectSetterTempFileHandle() {
+ return eventSubjectSetterTempFileHandle;
+ }
+
+ /**
+ * Sets event subject setter temp file.
+ *
+ * @param eventSubjectSetterTempFileHandle event subject setter temp file
+ */
+ public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
+ this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
+ }
+
+ /**
+ * Adds java snippet for events to event subject file.
+ *
+ * @param curNode current node
+ * @param pluginConfig plugin configurations
+ * @throws IOException when fails to do IO operations
+ */
+ public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
+
+ String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(),
+ pluginConfig.getConflictResolver()));
+
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(),
+ getCapitalCase(currentInfo));
+
+ JavaAttributeInfo javaAttributeInfo =
+ getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
+ null, false, false);
+
+ /*Adds java info for event in respective temp files.*/
+ addEventEnum(currentInfo, pluginConfig);
+ addEventSubjectAttribute(javaAttributeInfo, pluginConfig);
+ addEventSubjectGetter(javaAttributeInfo, pluginConfig);
+ addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo);
+ }
+
+ /*Adds event to enum temp file.*/
+ private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException {
+ appendToFile(getEventEnumTempFileHandle(),
+ getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ + notificationName.toUpperCase() + COMMA + NEW_LINE);
+ }
+
+ /*Adds event method in event class*/
+ private void addEnumMethod(String eventClassname, String className) throws IOException {
+ appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
+ }
+
+ /*Adds event method contents to event file.*/
+ private static String getEventFileContents(String eventClassname, String classname) {
+ return "\n" +
+ " /**\n" +
+ " * Creates " + classname + " event with type and subject.\n" +
+ " *\n" +
+ " * @param type event type\n" +
+ " * @param subject subject " + classname + "\n" +
+ " */\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
+ " super(type, subject);\n" +
+ " }\n" +
+ "\n" +
+ " /**\n" +
+ " * Creates " + classname + " event with type, subject and time.\n" +
+ " *\n" +
+ " * @param type event type\n" +
+ " * @param subject subject " + classname + "\n" +
+ " * @param time time of event\n" +
+ " */\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ + " subject, long time) {\n" +
+ " super(type, subject, time);\n" +
+ " }\n" +
+ "\n";
+ }
+
+ /*Adds events to event subject file.*/
+ private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getEventSubjectAttributeTempFileHandle(),
+ FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig));
+ }
+
+ /*Adds getter method for event in event subject class.*/
+ private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
+ appendToFile(getEventSubjectGetterTempFileHandle(),
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ }
+
+ /*Adds setter method for event in event subject class.*/
+ private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
+ throws IOException {
+ appendToFile(getEventSubjectSetterTempFileHandle(),
+ getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ }
+
+ /**
+ * Returns a temporary file handle for the event's file type.
+ *
+ * @param fileName file name
+ * @return temporary file handle
+ * @throws IOException when fails to create new file handle
+ */
+ private File getJavaFileHandle(YangNode curNode, String name)
+ throws IOException {
+
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
+ parentInfo);
+ }
+
+ /**
+ * Returns the directory path.
+ *
+ * @return directory path
+ */
+ private String getDirPath(JavaFileInfo parentInfo) {
+ return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
index 3261e08..326cf55 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -26,6 +26,7 @@
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
@@ -196,9 +197,10 @@
*
* @param yangTypeHolder YANG java data model node which has type info, eg union /
* typedef
+ * @param pluginConfig plugin configurations for naming conventions
* @throws IOException IO operation fail
*/
- public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
+ public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
throws IOException {
List<YangType<?>> typeList = yangTypeHolder.getTypeList();
@@ -208,18 +210,19 @@
throw new TranslatorException("Type does not have Java info");
}
YangJavaType<?> javaType = (YangJavaType<?>) yangType;
- javaType.updateJavaQualifiedInfo();
+ javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
String typeName = javaType.getDataTypeName();
if (javaType.getDataType().equals(DERIVED)) {
- typeName = getCamelCase(typeName, null);
+ typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
}
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
typeName, javaType,
getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
false);
- addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo);
+ addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo,
+ pluginConfig);
}
}
}
@@ -231,18 +234,20 @@
* @param hasType the node for which the type is being added as an attribute
* @param javaAttributeInfo the attribute info that needs to be added to
* temporary files
+ * @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
- private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
+ private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo,
+ YangPluginConfig pluginConfig)
throws IOException {
- super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
+ super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
- addOfStringMethod(javaAttributeInfo);
+ addOfStringMethod(javaAttributeInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
- addTypeConstructor(javaAttributeInfo);
+ addTypeConstructor(javaAttributeInfo, pluginConfig);
}
}
@@ -250,24 +255,26 @@
* Adds type constructor.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addTypeConstructor(JavaAttributeInfo attr)
+ private void addTypeConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
- getGeneratedJavaClassName()) + NEW_LINE);
+ getGeneratedJavaClassName(), pluginConfig) + NEW_LINE);
}
/**
* Adds of string for type.
*
* @param attr attribute info
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addOfStringMethod(JavaAttributeInfo attr)
+ private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
- getGeneratedJavaClassName())
+ getGeneratedJavaClassName(), pluginConfig)
+ NEW_LINE);
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
index f393a56..3722ad3 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
@@ -57,4 +57,19 @@
* updates the qualified info.
*/
void updateJavaQualifiedInfo();
+
+ /**
+ * Returns java naming conflict resolver.
+ *
+ * @return java naming conflict resolver
+ */
+ YangToJavaNamingConflictUtil getConflictResolveConfig();
+
+ /**
+ * Sets java naming conflict resolver.
+ *
+ * @param conflictResolveConfig java naming conflict resolver
+ */
+ void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig);
+
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
index 22970a9..5b1e7c5 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
-
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
/**
* Represent java based identification of the YANG leaves.
@@ -26,6 +26,8 @@
/**
* updates the qualified access details of the type.
+ *
+ * @param confilictResolver plugin configurations
*/
- void updateJavaQualifiedInfo();
+ void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver);
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
index 61e8e9c..10df251 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
@@ -30,6 +30,7 @@
implements JavaLeafInfoContainer {
private JavaQualifiedTypeInfo javaQualifiedAccess;
+ private YangToJavaNamingConflictUtil conflictResolveConfig;
/**
* Returns a new YANG leaf object with java qualified access details.
@@ -50,6 +51,7 @@
}
+ @Override
public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
return getCamelCase(getName(), conflictResolveConfig);
}
@@ -63,4 +65,23 @@
public void updateJavaQualifiedInfo() {
updateLeavesJavaQualifiedInfo(this);
}
+
+ /**
+ * Returns java naming conflict resolve configurations.
+ *
+ * @return java naming conflict resolve configurations
+ */
+ public YangToJavaNamingConflictUtil getConflictResolveConfig() {
+ return conflictResolveConfig;
+ }
+
+ /**
+ * Sets java naming conflict resolve configurations.
+ *
+ * @param conflictResolveConfig java naming conflict resolve configurations
+ */
+ public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
+ this.conflictResolveConfig = conflictResolveConfig;
+ }
+
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java
index 2d7e5bb..463656d 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java
@@ -29,6 +29,7 @@
extends YangLeafList
implements JavaLeafInfoContainer {
private JavaQualifiedTypeInfo javaQualifiedAccess;
+ private YangToJavaNamingConflictUtil conflictResolveConfig;
/**
* Returns a new YANG leaf object with java qualified access details.
@@ -62,4 +63,24 @@
public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
javaQualifiedAccess = typeInfo;
}
+
+ /**
+ * Returns java naming conflict resolve configurations.
+ *
+ * @return java naming conflict resolve configurations
+ */
+ @Override
+ public YangToJavaNamingConflictUtil getConflictResolveConfig() {
+ return conflictResolveConfig;
+ }
+
+ /**
+ * Sets java naming conflict resolve configurations.
+ *
+ * @param conflictResolveConfig java naming conflict resolve configurations
+ */
+ @Override
+ public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
+ this.conflictResolveConfig = conflictResolveConfig;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index fc2d9df..5bbe81b 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -16,14 +16,21 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
@@ -48,12 +55,24 @@
private TempJavaCodeFragmentFiles tempFileHandle;
/**
+ * List of notifications nodes.
+ */
+ private List<YangNode> notificationNodes;
+
+ /**
* Creates a YANG node of module type.
*/
public YangJavaModule() {
super();
setJavaFileInfo(new JavaFileInfo());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
+ setNotificationNodes(new ArrayList<>());
+ int gentype = GENERATE_SERVICE_AND_MANAGER;
+ if (isNotificationChildNodePresent(this)) {
+ gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
+ | GENERATE_EVENT_LISTENER_INTERFACE;
+ }
+ getJavaFileInfo().setGeneratedFileTypes(gentype);
+
}
/**
@@ -121,6 +140,15 @@
*/
@Override
public void generateCodeExit() throws TranslatorException {
+ /**
+ * As part of the notification support the following files needs to be generated.
+ * 1) Subject of the notification(event), this is simple interface with builder class.
+ * 2) Event class extending "AbstractEvent" and defining event type enum.
+ * 3) Event listener interface extending "EventListener".
+ * 4) Event subject class.
+ *
+ * The manager class needs to extend the "ListenerRegistry".
+ */
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
@@ -129,4 +157,53 @@
throw new TranslatorException("Failed to generate code for module node " + this.getName());
}
}
+
+ /**
+ * Returns notifications node list.
+ *
+ * @return notification nodes
+ */
+ public List<YangNode> getNotificationNodes() {
+ return notificationNodes;
+ }
+
+ /**
+ * Sets notifications list.
+ *
+ * @param notificationNodes notification list
+ */
+ private void setNotificationNodes(List<YangNode> notificationNodes) {
+ this.notificationNodes = notificationNodes;
+ }
+
+ /**
+ * Adds to notification node list.
+ *
+ * @param curNode notification node
+ */
+ private void addToNotificaitonList(YangNode curNode) {
+ getNotificationNodes().add(curNode);
+ }
+
+ /**
+ * Checks if there is any rpc defined in the module or sub-module.
+ *
+ * @param rootNode root node of the data model
+ * @return status of rpc's existence
+ */
+ public boolean isNotificationChildNodePresent(YangNode rootNode) {
+ YangNode childNode = rootNode.getChild();
+
+ while (childNode != null) {
+ if (childNode instanceof YangNotification) {
+ addToNotificaitonList(childNode);
+ }
+ childNode = childNode.getNextSibling();
+ }
+
+ if (!getNotificationNodes().isEmpty()) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
index 8624a44..d40073a 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -30,8 +30,6 @@
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
@@ -62,8 +60,7 @@
public YangJavaNotification() {
super();
setJavaFileInfo(new JavaFileInfo());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER
- | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE);
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
/**
@@ -167,17 +164,8 @@
*/
@Override
public void generateCodeExit() throws TranslatorException {
- /**
- * As part of the notification support the following files needs to be generated.
- * 1) Subject of the notification(event), this is simple interface with builder class.
- * 2) Event class extending "AbstractEvent" and defining event type enum.
- * 3) Event listener interface extending "EventListener".
- *
- * The manager class needs to extend the "ListenerRegistry".
- */
try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
- | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for notification node " + this.getName());
}
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 d63b887..e721fa7 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
@@ -135,6 +135,7 @@
try {
((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
+ ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(),
((YangNode) this).getName());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index 59d4912..8696495 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -16,8 +16,13 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
@@ -25,6 +30,9 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
@@ -49,12 +57,22 @@
private TempJavaCodeFragmentFiles tempFileHandle;
/**
+ * List of notifications nodes.
+ */
+ private List<YangNode> notificationNodes = new ArrayList<>();
+
+ /**
* Creates YANG java sub module object.
*/
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
+ int gentype = GENERATE_SERVICE_AND_MANAGER;
+ if (isNotificationChildNodePresent(this)) {
+ gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
+ | GENERATE_EVENT_LISTENER_INTERFACE;
+ }
+ getJavaFileInfo().setGeneratedFileTypes(gentype);
}
/**
@@ -136,6 +154,15 @@
*/
@Override
public void generateCodeExit() throws TranslatorException {
+ /**
+ * As part of the notification support the following files needs to be generated.
+ * 1) Subject of the notification(event), this is simple interface with builder class.
+ * 2) Event class extending "AbstractEvent" and defining event type enum.
+ * 3) Event listener interface extending "EventListener".
+ * 4) Event subject class.
+ *
+ * The manager class needs to extend the "ListenerRegistry".
+ */
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
@@ -144,4 +171,44 @@
throw new TranslatorException("Failed to generate code for submodule node " + this.getName());
}
}
+
+ /**
+ * Returns notifications node list.
+ *
+ * @return notification nodes
+ */
+ public List<YangNode> getNotificationNodes() {
+ return notificationNodes;
+ }
+
+ /**
+ * Adds to notification node list.
+ *
+ * @param curNode notification node
+ */
+ private void addToNotificaitonList(YangNode curNode) {
+ getNotificationNodes().add(curNode);
+ }
+
+ /**
+ * Checks if there is any rpc defined in the module or sub-module.
+ *
+ * @param rootNode root node of the data model
+ * @return status of rpc's existence
+ */
+ public boolean isNotificationChildNodePresent(YangNode rootNode) {
+ YangNode childNode = rootNode.getChild();
+
+ while (childNode != null) {
+ if (childNode instanceof YangNotification) {
+ addToNotificaitonList(childNode);
+ }
+ childNode = childNode.getNextSibling();
+ }
+
+ if (!getNotificationNodes().isEmpty()) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
index 82771d3..4ba4858 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
@@ -19,6 +19,7 @@
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
/**
* Represents java information corresponding to the YANG type.
@@ -40,13 +41,13 @@
}
@Override
- public void updateJavaQualifiedInfo() {
+ public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver) {
JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
/*
* Type is added as an attribute in the class.
*/
- String className = AttributesJavaDataType.getJavaImportClass(this, false);
+ String className = AttributesJavaDataType.getJavaImportClass(this, false, confilictResolver);
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
index cc5cc6c..ebcdc99 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
@@ -49,6 +49,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
@@ -58,6 +59,10 @@
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
/**
* Represents java data types info corresponding to YANG type.
@@ -97,8 +102,10 @@
return LONG;
case UINT64:
return BIG_INTEGER;
+ case BINARY:
+ return YANG_BINARY_CLASS;
case DECIMAL64:
- //TODO: DECIMAL64.
+ return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
@@ -112,7 +119,7 @@
* Returns from string method parsed string.
*
* @param targetDataType target data type
- * @param yangType YANG type
+ * @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
@@ -136,18 +143,16 @@
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
- case DECIMAL64:
- //TODO: DECIMAL64.
case STRING:
return EMPTY_STRING;
+ case EMPTY:
case BOOLEAN:
- return BOOLEAN_DATA_TYPE;
- case ENUMERATION:
- //TODO:ENUMERATION.
+ return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
+ case DECIMAL64:
case BITS:
- //TODO:BITS
case BINARY:
- //TODO:BINARY
+ case UNION:
+ case ENUMERATION:
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
@@ -158,11 +163,13 @@
/**
* Returns java import class.
*
- * @param yangType YANG type
+ * @param yangType YANG type
* @param isListAttr if the attribute need to be a list
+ * @param pluginConfig plugin configurations
* @return java import class
*/
- public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) {
+ public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr,
+ YangToJavaNamingConflictUtil pluginConfig) {
YangDataTypes type = yangType.getDataType();
@@ -185,21 +192,19 @@
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
- //TODO: DECIMAL64.
- break;
+ return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
return BOOLEAN_WRAPPER;
case ENUMERATION:
return getCapitalCase(
- getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
+ getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
case BITS:
- //TODO:BITS
- break;
+ return YANG_BITS_CLASS;
case BINARY:
- //TODO:BINARY
- break;
+ return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
@@ -210,11 +215,13 @@
return BOOLEAN_WRAPPER;
case UNION:
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
- null));
+ pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
+ break;
case DERIVED:
- return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
+ return getCapitalCase(
+ getCamelCase(yangType.getDataTypeName(), pluginConfig));
default:
throw new TranslatorException("given data type is not supported.");
}
@@ -223,19 +230,17 @@
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
- //TODO: DECIMAL64.
- break;
+ return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case ENUMERATION:
return getCapitalCase(
- getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
+ getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
case BITS:
- //TODO:BITS
- break;
+ return YANG_BITS_CLASS;
case BINARY:
- //TODO:BINARY
- break;
+ return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
@@ -243,16 +248,16 @@
//TODO:IDENTITYREF
break;
case EMPTY:
- //TODO:EMPTY
- break;
+ return BOOLEAN_DATA_TYPE;
case UNION:
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
- null));
+ pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
case DERIVED:
- return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
+ return getCapitalCase(
+ getCamelCase(yangType.getDataTypeName(), pluginConfig));
default:
return null;
}
@@ -263,9 +268,9 @@
/**
* Returns java import package.
*
- * @param yangType YANG type
+ * @param yangType YANG type
* @param isListAttr if the attribute is of list type
- * @param classInfo java import class info
+ * @param classInfo java import class info
* @return java import package
*/
public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
@@ -283,29 +288,22 @@
case UINT32:
case STRING:
case BOOLEAN:
+ case EMPTY:
return JAVA_LANG;
case UINT64:
return JAVA_MATH;
- case DECIMAL64:
- //TODO: DECIMAL64.
- break;
case ENUMERATION:
return getEnumsPackage(yangType);
+ case DECIMAL64:
case BITS:
- //TODO:BITS
- break;
case BINARY:
- //TODO:BINARY
- break;
+ return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
case IDENTITYREF:
//TODO:IDENTITYREF
break;
- case EMPTY:
- //TODO:EMPTY
- break;
case UNION:
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
@@ -320,19 +318,14 @@
switch (type) {
case UINT64:
return JAVA_MATH;
- case DECIMAL64:
- //TODO: DECIMAL64
- break;
case STRING:
return JAVA_LANG;
case ENUMERATION:
return getEnumsPackage(yangType);
+ case DECIMAL64:
case BITS:
- //TODO:BITS
- break;
case BINARY:
- //TODO:BINARY
- break;
+ return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
@@ -340,8 +333,7 @@
//TODO:IDENTITYREF
break;
case EMPTY:
- //TODO:EMPTY
- break;
+ return JAVA_LANG;
case UNION:
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 89e0667..f0a16f6 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -17,7 +17,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
@@ -27,12 +26,12 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
@@ -56,6 +55,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
@@ -95,8 +95,6 @@
return getTypeClassDefinition(yangName);
case GENERATE_ENUM_CLASS:
return getEnumClassDefinition(yangName);
- case GENERATE_EVENT_LISTENER_INTERFACE:
- return getEventListenerDefinition(yangName);
default:
return null;
}
@@ -123,9 +121,12 @@
case GENERATE_SERVICE_AND_MANAGER:
return getRpcInterfaceDefinition(yangName, curNode);
case GENERATE_EVENT_CLASS:
- String eventName = getCapitalCase(((JavaFileInfoContainer) curNode)
- .getJavaFileInfo().getJavaName());
+ String eventName = yangName + SUBJECT;
return getEventDefinition(yangName, eventName);
+ case GENERATE_EVENT_LISTENER_INTERFACE:
+ return getEventListenerDefinition(yangName);
+ case GENERATE_EVENT_SUBJECT_CLASS:
+ return getClassDefinition(yangName);
default:
return null;
}
@@ -183,7 +184,6 @@
* Returns builder file class definition.
*
* @param yangName file name
- * @param genFileTypes
* @return definition
*/
private static String getBuilderClassDefinition(String yangName) {
@@ -198,8 +198,18 @@
* @return definition
*/
private static String getImplClassDefinition(String yangName) {
- return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName
- + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE
+ + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns impl file class definition.
+ *
+ * @param yangName file name
+ * @return definition
+ */
+ private static String getClassDefinition(String yangName) {
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -244,14 +254,14 @@
if (yangName.contains(SERVICE)) {
String[] strArray = yangName.split(SERVICE);
- return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
+ SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
- return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
- + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE
+ + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index a116dec..c84fe40 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -145,10 +145,11 @@
*
* @param name name of attribute
* @param value value of the enum
+ * @param pluginConfig plugin configurations
* @return string for enum's attribute
*/
- public static String generateEnumAttributeString(String name, int value) {
- return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION
+ public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
+ return getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
index 64e7fe6..3ee83fd 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
@@ -27,18 +27,7 @@
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
@@ -87,6 +76,7 @@
if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
importData.addImportInfo(info);
+
/*true means import should be added*/
getExtendedClassStore().put(info, true);
}
@@ -95,33 +85,6 @@
}
/**
- * Returns extends string for class.
- *
- * @param genFileType generated file type
- * @param className class name
- * @param isNotificationPresent if notification node is present
- * @return extends string
- */
- public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) {
- String extend = EXTEND + SPACE;
- if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) {
- extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE
- + className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE;
- } else {
- for (JavaQualifiedTypeInfo info : getExtendsList()) {
- if (info.getClassInfo().equals(className)) {
- if (!getExtendedClassStore().get(info)) {
- return extend + info.getClassInfo();
- } else {
- return extend + info.getPkgInfo() + PERIOD + info.getClassInfo();
- }
- }
- }
- }
- return null;
- }
-
- /**
* Returns extends list.
*
* @return the extendsList
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index ba06942..ee7ad23 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -27,6 +27,7 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
@@ -34,6 +35,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -44,6 +46,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
@@ -59,6 +66,8 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
@@ -75,6 +84,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getEventEnumTypeStart;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
@@ -82,20 +92,22 @@
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
/**
* Representation of java file generator.
@@ -141,7 +153,7 @@
+ " while interface file generation");
}
}
- return file;
+ return validateLineLength(file);
}
/**
@@ -157,11 +169,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path);
+ initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path, pluginConfig);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
try {
@@ -188,7 +201,7 @@
*/
methods.add(
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .addBuildMethodForInterface());
+ .addBuildMethodForInterface(pluginConfig));
/**
* Add getters and setters in builder interface.
@@ -198,7 +211,7 @@
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -216,11 +229,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path);
+ initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path, pluginConfig);
List<String> methods = new ArrayList<>();
@@ -265,7 +279,7 @@
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addBuildMethodImpl());
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PUBLIC, BUILDER));
+ .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig));
/**
* Add methods in builder class.
@@ -273,7 +287,7 @@
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
- return file;
+ return validateLineLength(file);
}
/**
@@ -298,6 +312,10 @@
List<String> methods = new ArrayList<>();
+ insertDataIntoJavaFile(file, LOGGER_STATEMENT);
+ methods.add(addActivateMethod());
+ methods.add(addDeActivateMethod());
+
try {
if (isAttrPresent) {
/**
@@ -338,7 +356,7 @@
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
- return file;
+ return validateLineLength(file);
}
/**
@@ -354,11 +372,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
+ initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path, pluginConfig);
List<String> methods = new ArrayList<>();
@@ -398,10 +417,10 @@
/**
* Hash code method.
*/
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString(
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING))));
+ .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
*/
@@ -429,9 +448,10 @@
/**
* Constructor.
*/
- String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles());
+ String constructor =
+ getConstructorStart(className, pluginConfig) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles());
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
} catch (IOException e) {
@@ -456,7 +476,7 @@
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -472,11 +492,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path);
+ initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig);
List<String> methods = new ArrayList<>();
@@ -497,7 +518,7 @@
* Default constructor.
*/
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PRIVATE, EMPTY_STRING));
+ .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
try {
@@ -522,11 +543,11 @@
/**
* Hash code method.
*/
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString(
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getTypeTempFiles())
- .replace(NEW_LINE, EMPTY_STRING))));
+ .replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
@@ -546,7 +567,7 @@
/**
* From string method.
*/
- methods.add(getFromStringMethodSignature(className)
+ methods.add(getFromStringMethodSignature(className, pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
.getTypeTempFiles()) + getFromStringMethodClose());
@@ -560,7 +581,7 @@
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -576,11 +597,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path);
+ initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path, pluginConfig);
List<String> methods = new ArrayList<>();
@@ -601,7 +623,7 @@
* Default constructor.
*/
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PRIVATE, EMPTY_STRING));
+ .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
try {
@@ -626,11 +648,11 @@
/**
* Hash code method.
*/
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString(
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getTypeTempFiles())
- .replace(NEW_LINE, EMPTY_STRING))));
+ .replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
@@ -650,7 +672,7 @@
/**
* From string method.
*/
- methods.add(getFromStringMethodSignature(className)
+ methods.add(getFromStringMethodSignature(className, pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
+ getFromStringMethodClose());
@@ -665,7 +687,7 @@
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -680,11 +702,12 @@
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = javaFileInfo.getJavaName();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path);
+ initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path, pluginConfig);
/**
* Add attribute strings.
*/
@@ -708,26 +731,26 @@
/**
* Add a constructor for enum.
*/
- insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false)
+ insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig)
+ getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE);
TempJavaEnumerationFragmentFiles enumFragFiles =
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getEnumerationTempFiles();
insertDataIntoJavaFile(file, getEnumsOfMethod(className,
- enumFragFiles.getJavaAttributeForEnum(),
+ enumFragFiles.getJavaAttributeForEnum(pluginConfig),
enumFragFiles.getEnumSetJavaMap(),
- enumFragFiles.getEnumStringList())
+ enumFragFiles.getEnumStringList(), pluginConfig)
+ NEW_LINE);
/**
* Add a getter method for enum.
*/
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false)
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig)
+ getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
try {
- insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className))
+ insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getEnumerationTempFiles())
@@ -739,7 +762,7 @@
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -797,7 +820,7 @@
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
+ return validateLineLength(file);
}
/**
@@ -810,49 +833,28 @@
*/
public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
- YangNode parent = curNode.getParent();
- JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
String className =
- getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ EVENT_STRING;
- initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
- insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName()));
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- }
+ TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
- private static String getEventFileContents(String eventClassname, String classname) {
- return "\n" +
- " public enum Type {\n" +
- " /**\n" +
- " * " + getCapitalCase(classname) + " notification.\n" +
- " */\n" +
- " " + classname.toUpperCase() + "_EVENT\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type and subject.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
- " super(type, subject);\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type, subject and time.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " * @param time time of event\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
- + " subject, long time) {\n" +
- " super(type, subject, time);\n" +
- " }\n" +
- "\n";
+ initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
+ try {
+ insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() +
+ trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles), COMMA)
+ + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles));
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while event class file generation");
+ }
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+ validateLineLength(file);
}
/**
@@ -865,15 +867,48 @@
*/
public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
throws IOException {
- YangNode parent = curNode.getParent();
- JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className =
- getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ EVENT_LISTENER_STRING;
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path);
+ initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+ validateLineLength(file);
+ }
+
+ /**
+ * Generates event subject's file.
+ *
+ * @param file file handle
+ * @param curNode current YANG node
+ * @throws IOException when fails to do IO exceptions
+ */
+ public static void generateEventSubjectFile(File file, YangNode curNode)
+ throws IOException {
+
+ String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ + EVENT_SUBJECT_NAME_SUFFIX;
+
+ initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className);
+
+ TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
+
+ insertDataIntoJavaFile(file, NEW_LINE);
+ try {
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles));
+
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles));
+
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles));
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while event class file generation");
+ }
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+ validateLineLength(file);
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index 6ebc453..7e31b62 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -37,6 +37,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -47,6 +48,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
@@ -60,28 +66,37 @@
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.ORG;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg;
/**
* Represents utilities for java file generator.
@@ -136,6 +151,7 @@
if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
}
+
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
@@ -201,6 +217,36 @@
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle());
+ } else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle());
+ } else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle());
+ } else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle());
+ } else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle());
+ } else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle());
}
return null;
}
@@ -213,15 +259,16 @@
* @param type generated file type
* @param imports imports for the file
* @param pkg generated file package
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to generate a file
*/
public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports,
- String pkg)
+ String pkg, YangPluginConfig pluginConfig)
throws IOException {
try {
file.createNewFile();
- appendContents(file, className, type, imports, pkg);
+ appendContents(file, className, type, imports, pkg, pluginConfig);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
}
@@ -263,9 +310,17 @@
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ String name = javaFileInfo.getJavaName();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- String pkgString = parsePackageString(path, importsList);
+ String pkgString = null;
+ if (type == GENERATE_EVENT_CLASS
+ || type == GENERATE_EVENT_LISTENER_INTERFACE
+ || type == GENERATE_EVENT_SUBJECT_CLASS) {
+ pkgString = parsePackageString(path + PERIOD + name, importsList);
+ } else {
+ pkgString = parsePackageString(path, importsList);
+ }
switch (type) {
case INTERFACE_MASK:
appendHeaderContents(file, pkgString, importsList);
@@ -279,6 +334,14 @@
appendHeaderContents(file, pkgString, importsList);
write(file, type, EVENT, curNode, className);
break;
+ case GENERATE_EVENT_LISTENER_INTERFACE:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, type, EVENT_LISTENER, curNode, className);
+ break;
+ case GENERATE_EVENT_SUBJECT_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, type, EVENT_SUBJECT_CLASS, curNode, className);
+ break;
default:
break;
}
@@ -294,37 +357,34 @@
* @param importsList list of java imports.
* @throws IOException when fails to append contents
*/
- private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg)
+ private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg,
+ YangPluginConfig pluginConfig)
throws IOException {
String pkgString = parsePackageString(pkg, importsList);
switch (type) {
case IMPL_CLASS_MASK:
- write(file, fileName, type, IMPL_CLASS);
+ write(file, fileName, type, IMPL_CLASS, pluginConfig);
break;
case BUILDER_INTERFACE_MASK:
- write(file, fileName, type, BUILDER_INTERFACE);
+ write(file, fileName, type, BUILDER_INTERFACE, pluginConfig);
break;
case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, IMPL_CLASS);
+ write(file, fileName, type, IMPL_CLASS, pluginConfig);
break;
case BUILDER_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, BUILDER_CLASS);
+ write(file, fileName, type, BUILDER_CLASS, pluginConfig);
break;
case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, IMPL_CLASS);
+ write(file, fileName, type, IMPL_CLASS, pluginConfig);
break;
case GENERATE_ENUM_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, ENUM_CLASS);
- break;
- case GENERATE_EVENT_LISTENER_INTERFACE:
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, EVENT_LISTENER);
+ write(file, fileName, type, ENUM_CLASS, pluginConfig);
break;
default:
break;
@@ -340,10 +400,7 @@
*/
private static String parsePackageString(String javaPkg, List<String> importsList) {
- if (javaPkg.contains(ORG)) {
- String[] strArray = javaPkg.split(ORG);
- javaPkg = ORG + getJavaPackageFromPackagePath(strArray[1]);
- }
+ javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg));
if (importsList != null) {
if (!importsList.isEmpty()) {
return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE;
@@ -395,14 +452,16 @@
private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName)
throws IOException {
+ YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!fileName.contains(SERVICE)) {
- insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false));
+ insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false, pluginConfig));
+ insertDataIntoJavaFile(file, addComponentString());
} else {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
}
} else {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
}
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
}
@@ -416,9 +475,10 @@
* @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
- private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
+ private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
+ YangPluginConfig pluginConfig)
throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
@@ -433,4 +493,13 @@
+ SEMI_COLAN + NEW_LINE;
}
+ /**
+ * Returns component string.
+ *
+ * @return component string
+ */
+ public static String addComponentString() {
+ return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index cd0a98e..d9f22ed 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -26,11 +26,14 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE;
@@ -48,6 +51,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
@@ -93,7 +98,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
+import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
@@ -106,6 +113,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
@@ -115,7 +123,6 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
@@ -133,10 +140,11 @@
* Returns the methods strings for builder interface.
*
* @param name attribute name
+ * @param pluginConfig plugin configurations
* @return method string for builder interface
*/
- public static String parseBuilderInterfaceBuildMethodString(String name) {
- return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name);
+ public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
+ return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name);
}
/**
@@ -144,14 +152,16 @@
*
* @param attr attribute info
* @param generatedJavaFiles generated java files
+ * @param pluginConfig plugin configurations
* @return getter string
*/
- public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles) {
+ public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
+ YangPluginConfig pluginConfig) {
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
- return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr())
+ return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig)
+ getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
}
@@ -161,20 +171,22 @@
* @param attr attribute info
* @param className java class name
* @param generatedJavaFiles generated java files
+ * @param pluginConfig plugin configurations
* @return setter string
*/
- public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
+ public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
+ YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attributeName = attr.getAttributeName();
JavaDocGen.JavaDocType type;
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
type = MANAGER_SETTER_METHOD;
} else {
type = SETTER_METHOD;
}
- return getJavaDoc(type, attributeName, attr.isListAttr())
+ return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig)
+ getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
}
@@ -182,10 +194,11 @@
* Returns constructor method string.
*
* @param name class name
+ * @param pluginConfig plugin configurations
* @return constructor string
*/
- public static String getConstructorString(String name) {
- return getJavaDoc(CONSTRUCTOR, name, false);
+ public static String getConstructorString(String name, YangPluginConfig pluginConfig) {
+ return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
}
/**
@@ -193,10 +206,13 @@
*
* @param name class name
* @param modifierType modifier type
+ * @param pluginConfig plugin configurations
* @return default constructor string
*/
- public static String getDefaultConstructorString(String name, String modifierType) {
- return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType)
+ public static String getDefaultConstructorString(String name, String modifierType,
+ YangPluginConfig pluginConfig) {
+ return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig)
+ + getDefaultConstructor(name, modifierType)
+ NEW_LINE;
}
@@ -312,12 +328,17 @@
+ getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE
+ + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
+ + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL +
- SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS +
- SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE
+ + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
+ + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
}
@@ -474,14 +495,17 @@
* Returns constructor string for impl class.
*
* @param yangName class name
+ * @param pluginConfig plugin configurations
* @return constructor string
*/
- public static String getConstructorStart(String yangName) {
+ public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) {
- String javadoc = getConstructorString(yangName);
- String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName
- + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE;
+ String javadoc = getConstructorString(yangName, pluginConfig);
+ String constructor =
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName
+ + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET
+ + NEW_LINE;
return javadoc + constructor;
}
@@ -491,24 +515,29 @@
* @param yangName name of the class
* @param attr attribute info
* @param generatedJavaFiles generated java files
+ * @param pluginConfig plugin configurations
* @return constructor for class
*/
- public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles) {
+ public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles,
+ YangPluginConfig pluginConfig) {
String attributeName = attr.getAttributeName();
String constructor;
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
- constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
- + getCapitalCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- SEMI_COLAN
- + NEW_LINE;
+ constructor =
+ EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
+ + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
+ + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
} else {
- constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + getCamelCase(attributeName, null) +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
- + NEW_LINE;
+ constructor =
+ EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
+ + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
return constructor;
}
@@ -519,11 +548,13 @@
* @param rpcName name of the rpc
* @param inputName name of input
* @param outputName name of output
+ * @param pluginConfig plugin configurations
* @return rpc method string
*/
- public static String getRpcServiceMethod(String rpcName, String inputName, String outputName) {
+ public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
+ YangPluginConfig pluginConfig) {
- rpcName = getCamelCase(rpcName, null);
+ rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
inputName = getCapitalCase(inputName);
if (!outputName.equals(VOID)) {
outputName = getCapitalCase(outputName);
@@ -538,11 +569,13 @@
* @param rpcName name of the rpc
* @param inputName name of input
* @param outputName name of output
+ * @param pluginConfig plugin configurations
* @return rpc method string
*/
- public static String getRpcManagerMethod(String rpcName, String inputName, String outputName) {
+ public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
+ YangPluginConfig pluginConfig) {
- rpcName = getCamelCase(rpcName, null);
+ rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
inputName = getCapitalCase(inputName);
if (!outputName.equals(VOID)) {
outputName = getCapitalCase(outputName);
@@ -631,12 +664,14 @@
* Returns from string method's open string.
*
* @param className name of the class
+ * @param pluginConfig plugin configurations
* @return from string method's open string
*/
- public static String getFromStringMethodSignature(String className) {
- return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
- + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
- + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ public static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
+ return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
+ + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
+ + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -832,14 +867,16 @@
*
* @param attr attribute info
* @param generatedJavaClassName class name
+ * @param pluginConfig plugin configurations
* @return of method's string and java doc for special type
*/
- public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) {
+ public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
+ YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false)
+ return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ getOfMethodString(attrType, generatedJavaClassName);
}
@@ -863,14 +900,16 @@
*
* @param attr attribute info
* @param generatedJavaClassName class name
+ * @param pluginConfig plugin configurations
* @return string and java doc for constructor of type class
*/
- public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) {
+ public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
+ String generatedJavaClassName, YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false)
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ getTypeConstructorString(attrType, attrName, generatedJavaClassName);
}
@@ -986,10 +1025,11 @@
* @param attr java attribute
* @param enumMap enum's sets map
* @param enumList enum's sets list
+ * @param pluginConfig plugin configurations
* @return of method
*/
public static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
- Map<String, Integer> enumMap, List<String> enumList) {
+ Map<String, Integer> enumMap, List<String> enumList, YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
@@ -1010,6 +1050,37 @@
+ RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false) + method;
+ return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig)
+ + method;
}
+
+ /**
+ * Returns activate method string.
+ *
+ * @return activate method string
+ */
+ public static String addActivateMethod() {
+ return FOUR_SPACE_INDENTATION + ACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
+ + PUBLIC + SPACE + VOID + SPACE + ACTIVATE + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + YANG_UTILS_TODO
+ + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + STARTED_LOG_INFO + FOUR_SPACE_INDENTATION
+ + CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns deactivate method string.
+ *
+ * @return deactivate method string
+ */
+ public static String addDeActivateMethod() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + DEACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
+ + PUBLIC + SPACE + VOID + SPACE + DEACTIVATE + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
index 87ff739..1feeb51 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
@@ -35,24 +35,35 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
@@ -102,12 +113,6 @@
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
- if (container.getEventTempFiles() != null) {
- return container.getEventTempFiles();
- }
- if (container.getEventListenerTempFiles() != null) {
- return container.getEventListenerTempFiles();
- }
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
@@ -234,6 +239,31 @@
}
/**
+ * Adds annotations imports.
+ *
+ * @param imports list if imports
+ * @param operation to add or to delete
+ */
+ public static void addAnnotationsImports(List<String> imports, boolean operation) {
+ if (operation) {
+ imports.add(ACTIVATE_ANNOTATION_IMPORT);
+ imports.add(DEACTIVATE_ANNOTATION_IMPORT);
+ imports.add(COMPONENT_ANNOTATION_IMPORT);
+ imports.add(SERVICE_ANNOTATION_IMPORT);
+ imports.add(LOGGER_FACTORY_IMPORT);
+ imports.add(LOGGER_IMPORT);
+ } else {
+ imports.remove(ACTIVATE_ANNOTATION_IMPORT);
+ imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
+ imports.remove(COMPONENT_ANNOTATION_IMPORT);
+ imports.remove(SERVICE_ANNOTATION_IMPORT);
+ imports.remove(LOGGER_FACTORY_IMPORT);
+ imports.remove(LOGGER_IMPORT);
+ }
+ sortImports(imports);
+ }
+
+ /**
* Performs given operations on import list.
*
* @param imports list of imports
@@ -328,4 +358,13 @@
return imports;
}
+ /**
+ * Returns event enum start.
+ *
+ * @return event enum start
+ */
+ public static String getEventEnumTypeStart() {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
index 0a08db3..7bea5cd 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -32,8 +32,13 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
@@ -49,7 +54,7 @@
public final class YangJavaModelUtils {
/**
- * Creates YANG java model utility.
+ * Creates an instance of YANG java model utility.
*/
private YangJavaModelUtils() {
}
@@ -64,6 +69,7 @@
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
+
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver()));
@@ -71,6 +77,7 @@
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
+ javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
}
/**
@@ -90,6 +97,7 @@
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
+ javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
}
/**
@@ -120,6 +128,16 @@
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+ if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
+ updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
+ }
+ } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
+ updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
+ }
+ }
+
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/*
* Container
@@ -139,13 +157,14 @@
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
+ .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
/*
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
- .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
+ .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+
} else if (javaCodeGeneratorInfo instanceof YangChoice) {
/*Do nothing, only the interface needs to be generated*/
} else {
@@ -171,6 +190,32 @@
}
/**
+ * Updates notification node info in service temporary file.
+ *
+ * @param javaCodeGeneratorInfo java code generator info
+ * @param yangPluginConfig plugin configurations
+ * @throws IOException when fails to do IO operations
+ */
+ private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig) throws IOException {
+ if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles()
+ .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
+ }
+ }
+ if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
+ .getNotificationNodes()) {
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles()
+ .addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
+ }
+ }
+ }
+
+ /**
* Generates code for the current ata model node and adds itself as an attribute in the parent.
*
* @param javaCodeGeneratorInfo YANG java file info node
@@ -193,7 +238,7 @@
/*
* Update the current nodes info in its parent nodes generated files.
*/
- addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
+ addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
}
/**
@@ -242,7 +287,7 @@
.addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
- .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
+ .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
}
}
@@ -284,7 +329,26 @@
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
+ if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ if (!((YangJavaModule) javaCodeGeneratorInfo)
+ .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
+ updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
+ }
+ } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ if (!((YangJavaSubModule) javaCodeGeneratorInfo)
+ .isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
+ updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
+ }
+ }
+
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
+ /*Updates java code generator info with events info.*/
+ private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) {
+ javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS);
+ javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS);
+ javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
+ }
+
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 39e5148..ca214c7 100644
--- a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -197,6 +197,11 @@
public static final String PARSE_BYTE = "parseByte";
/**
+ * Static attribute for parse boolean.
+ */
+ public static final String PARSE_BOOLEAN = "parseBoolean";
+
+ /**
* Static attribute for parse short.
*/
public static final String PARSE_SHORT = "parseShort";
@@ -242,6 +247,11 @@
public static final String SPACE = " ";
/**
+ * Static attribute for subject.
+ */
+ public static final String SUBJECT = "Subject";
+
+ /**
* Static attribute for ListenerRegistry.
*/
public static final String LISTENER_REG = "ListenerRegistry";
@@ -254,7 +264,7 @@
/**
* Static attribute for listener package.
*/
- public static final String LISTENER_PKG = "org.onosproject.event";
+ public static final String ONOS_EVENT_PKG = "org.onosproject.event";
/**
* Static attribute for colon.
@@ -787,6 +797,11 @@
public static final String ENUM = "enum";
/**
+ * Static attribute for type syntax.
+ */
+ public static final String TYPE = "Type";
+
+ /**
* Static attribute for static syntax.
*/
public static final String STATIC = "static";
@@ -852,6 +867,11 @@
public static final String EVENT_LISTENER_STRING = "Listener";
/**
+ * For event subject file generation.
+ */
+ public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
+
+ /**
* Static attribute for impl syntax.
*/
public static final String IMPL = "Impl";
@@ -957,6 +977,130 @@
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
+ * Static attribute for activate annotation.
+ */
+ public static final String ACTIVATE_ANNOTATION = "@Activate\n";
+
+ /**
+ * Static attribute for activate.
+ */
+ public static final String ACTIVATE = "activate";
+
+ /**
+ * Static attribute for activate annotation import.
+ */
+ public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n";
+
+ /**
+ * Static attribute for deactivate annotation.
+ */
+ public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n";
+
+ /**
+ * Static attribute for deactivate.
+ */
+ public static final String DEACTIVATE = "deactivate";
+
+ /**
+ * Static attribute for deactivate annotation import.
+ */
+ public static final String DEACTIVATE_ANNOTATION_IMPORT =
+ "import org.apache.felix.scr.annotations.Deactivate;\n";
+
+ /**
+ * Static attribute for component annotation.
+ */
+ public static final String COMPONENT_ANNOTATION = "@Component";
+
+ /**
+ * Static attribute for immediate.
+ */
+ public static final String IMMEDIATE = "immediate";
+
+ /**
+ * Static attribute for component annotation import.
+ */
+ public static final String COMPONENT_ANNOTATION_IMPORT =
+ "import org.apache.felix.scr.annotations.Component;\n";
+
+ /**
+ * Static attribute for service annotation.
+ */
+ public static final String SERVICE_ANNOTATION = "@Service\n";
+
+ /**
+ * Static attribute for service annotation import.
+ */
+ public static final String SERVICE_ANNOTATION_IMPORT =
+ "import org.apache.felix.scr.annotations.Service;\n";
+
+ /**
+ * Static attribute for logger factory import.
+ */
+ public static final String LOGGER_FACTORY_IMPORT =
+ "import static org.slf4j.LoggerFactory.getLogger;\n";
+
+ /**
+ * Static attribute for logger import.
+ */
+ public static final String LOGGER_IMPORT =
+ "import org.slf4j.Logger;\n";
+
+ /**
+ * Static attribute for logger statement.
+ */
+ public static final String LOGGER_STATEMENT =
+ "\n private final Logger log = getLogger(getClass());\n";
+
+ /**
+ * Static attribute for logger statement for started.
+ */
+ public static final String STARTED_LOG_INFO =
+ "log.info(\"Started\");\n";
+
+ /**
+ * Static attribute for logger statement for stopped.
+ */
+ public static final String STOPPED_LOG_INFO =
+ "log.info(\"Stopped\");\n";
+
+ /**
+ * Static attribute for AbstractEvent.
+ */
+ public static final String ABSTRACT_EVENT = "AbstractEvent";
+
+ /**
+ * Static attribute for EventListener.
+ */
+ public static final String EVENT_LISTENER = "EventListener";
+
+ /**
+ * Static attribute for YangBinary class.
+ */
+ public static final String YANG_BINARY_CLASS = "YangBinary";
+
+ /**
+ * Static attribute for YangBinary class.
+ */
+ public static final String YANG_BITS_CLASS = "YangBits";
+
+ /**
+ * Static attribute for YANG types package.
+ */
+ public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.utils.builtindatatype";
+
+ /**
+ * Static attribute for MathContext class.
+ */
+ public static final String MATH_CONTEXT = "MathContext";
+
+ /**
+ * Static attribute for DECIMAL64 class.
+ */
+ public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
+
+
+ /**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBinary.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBinary.java
new file mode 100644
index 0000000..51747f3
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBinary.java
@@ -0,0 +1,104 @@
+/*
+ * 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.yangutils.utils.builtindatatype;
+
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents binary data type.
+ */
+public final class YangBinary {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG binary.
+ */
+ private YangBinary() {
+ }
+
+ /**
+ * Creates an instance of YANG binary.
+ *
+ * @param bytes byte array
+ */
+ public YangBinary(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG binary.
+ *
+ * @param bytes byte array
+ * @return object of YANG binary
+ */
+ public static YangBinary of(byte[] bytes) {
+ return new YangBinary(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBinary) {
+ YangBinary other = (YangBinary) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG binary fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG binary
+ */
+ public static YangBinary fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBits.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBits.java
new file mode 100644
index 0000000..60b0c32
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBits.java
@@ -0,0 +1,104 @@
+/*
+ * 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.yangutils.utils.builtindatatype;
+
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents bits data type.
+ */
+public class YangBits {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG bits.
+ */
+ private YangBits() {
+ }
+
+ /**
+ * Creates an instance of YANG bits.
+ *
+ * @param bytes byte array
+ */
+ public YangBits(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG bits.
+ *
+ * @param bytes byte array
+ * @return object of YANG bits
+ */
+ public static YangBits of(byte[] bytes) {
+ return new YangBits(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBits) {
+ YangBits other = (YangBits) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG bits fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG bits
+ */
+ public static YangBits fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangDecimal64.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangDecimal64.java
new file mode 100644
index 0000000..8b3a0eb
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangDecimal64.java
@@ -0,0 +1,112 @@
+/*
+ * 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.yangutils.utils.builtindatatype;
+
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents YANG decimal 64.
+ */
+public class YangDecimal64 {
+
+ private int fractionDigit;
+
+ /**
+ * Creates an instance of YANG decimal64.
+ */
+ public YangDecimal64() {
+ }
+
+ /**
+ * Creates an instance of of YANG decimal64.
+ *
+ * @param fractionDigit fraction digit
+ */
+ public YangDecimal64(int fractionDigit) {
+ this.setFractionDigit(fractionDigit);
+ }
+
+ /**
+ * Returns fraction digit.
+ *
+ * @return the fractionDigit
+ */
+ public int getFractionDigit() {
+ return fractionDigit;
+ }
+
+ /**
+ * Sets fraction digit.
+ *
+ * @param fractionDigit fraction digits.
+ */
+ public void setFractionDigit(int fractionDigit) {
+ this.fractionDigit = fractionDigit;
+ }
+
+ /**
+ * Returns object of YANG decimal64.
+ *
+ * @param value fraction digit
+ * @return YANG decimal64
+ */
+ public static YangDecimal64 of(int value) {
+ return new YangDecimal64(value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fractionDigit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangDecimal64) {
+ YangDecimal64 other = (YangDecimal64) obj;
+ return Objects.equals(fractionDigit, other.fractionDigit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("fractionDigit", fractionDigit)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG decimal64 fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG decimal64
+ */
+ public static YangDecimal64 fromString(String valInString) {
+ try {
+ int tmpVal = Integer.parseInt(valInString);
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index 7d8fd84..cef7706 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -22,6 +22,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -84,10 +86,12 @@
YangNode parent = getParentNodeInGenCode(yangNode);
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true);
+ addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
+ ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
} else {
pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false);
+ addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
+ ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
@@ -120,6 +124,7 @@
*/
public static String readAppendFile(String toAppend, String spaces)
throws IOException {
+
FileReader fileReader = new FileReader(toAppend);
BufferedReader bufferReader = new BufferedReader(fileReader);
try {
@@ -156,15 +161,22 @@
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
+
+ List<FileWriter> fileWriterStore = new ArrayList<>();
+
FileWriter fileWriter = new FileWriter(inputFile, true);
+ fileWriterStore.add(fileWriter);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
if (!isClose) {
outputPrintWriter.write(contentTobeAdded);
outputPrintWriter.flush();
outputPrintWriter.close();
} else {
- fileWriter.flush();
- fileWriter.close();
+ for (FileWriter curWriter : fileWriterStore) {
+ curWriter.flush();
+ curWriter.close();
+ curWriter = null;
+ }
}
}
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index 335de7f..218f56d 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.utils.io.impl;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
@@ -181,7 +182,12 @@
/**
* For manager setters.
*/
- MANAGER_SETTER_METHOD
+ MANAGER_SETTER_METHOD,
+
+ /**
+ * For event subject.
+ */
+ EVENT_SUBJECT_CLASS
}
/**
@@ -190,14 +196,15 @@
* @param type java doc type
* @param name name of the YangNode
* @param isList is list attribute
+ * @param pluginConfig plugin configurations
* @return javadocs.
*/
- public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
+ public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
- name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, null));
+ name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
switch (type) {
case IMPL_CLASS: {
- return generateForImplClass(name);
+ return generateForClass(name);
}
case BUILDER_CLASS: {
return generateForBuilderClass(name);
@@ -248,7 +255,7 @@
return generateForRpcService(name);
}
case RPC_MANAGER: {
- return generateForImplClass(name);
+ return generateForClass(name);
}
case EVENT: {
return generateForEvent(name);
@@ -256,6 +263,9 @@
case EVENT_LISTENER: {
return generateForEventListener(name);
}
+ case EVENT_SUBJECT_CLASS: {
+ return generateForClass(name);
+ }
default: {
return generateForConstructors(name);
}
@@ -279,14 +289,17 @@
* @param rpcName name of the rpc
* @param inputName name of input
* @param outputName name of output
+ * @param pluginConfig plugin configurations
* @return javaDocs of rpc method
*/
- public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) {
- rpcName = getCamelCase(rpcName, null);
+ public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName,
+ YangPluginConfig pluginConfig) {
+ rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
- String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
- + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + getInputString(inputName, rpcName);
+ String javadoc =
+ NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
+ + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ + getInputString(inputName, rpcName);
if (!outputName.equals(VOID)) {
javadoc = javadoc + getOutputString(outputName, rpcName);
}
@@ -470,7 +483,7 @@
* @param className class name
* @return javaDocs
*/
- private static String generateForImplClass(String className) {
+ 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;
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
index 4a3f847..ff2e3e7 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
@@ -60,8 +60,8 @@
* operations
*/
public static List<String> getYangFiles(String root) throws IOException {
- List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION);
- return yangFiles;
+
+ return getFiles(root, YANG_FILE_EXTENTION);
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index 835b675..b505111 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -16,32 +16,38 @@
package org.onosproject.yangutils.utils.io.impl;
+import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.LinkedList;
-import java.util.Stack;
+import java.util.List;
import java.util.Set;
+import java.util.Stack;
+import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
-
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
@@ -61,6 +67,9 @@
private static final Logger log = getLogger(YangIoUtils.class);
private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
+ private static final int LINE_SIZE = 116;
+ private static final int SUB_LINE_SIZE = 112;
+ private static final int ZERO = 0;
/**
* Creates an instance of YANG io utils.
@@ -83,19 +92,19 @@
/**
* Adds package info file for the created directory.
*
- * @param path directory path
- * @param classInfo class info for the package
- * @param pack package of the directory
+ * @param path directory path
+ * @param classInfo class info for the package
+ * @param pack package of the directory
* @param isChildNode is it a child node
+ * @param pluginConfig plugin configurations
* @throws IOException when fails to create package info file
*/
- public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode)
+ public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode,
+ YangPluginConfig pluginConfig)
throws IOException {
- if (pack.contains(ORG)) {
- String[] strArray = pack.split(ORG);
- pack = ORG + strArray[1];
- }
+ pack = parsePkg(pack);
+
try {
File packageInfo = new File(path + SLASH + "package-info.java");
@@ -105,9 +114,12 @@
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
- bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode));
- bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN);
-
+ bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig));
+ String pkg = PACKAGE + SPACE + pack + SEMI_COLAN;
+ if (pkg.length() > LINE_SIZE) {
+ pkg = whenDelimiterIsPersent(pkg, LINE_SIZE);
+ }
+ bufferedWriter.write(pkg);
bufferedWriter.close();
fileWriter.close();
} catch (IOException e) {
@@ -116,6 +128,32 @@
}
/**
+ * Parses package and returns updated package.
+ *
+ * @param pack package needs to be updated
+ * @return updated package
+ */
+ public static String parsePkg(String pack) {
+
+ if (pack.contains(ORG)) {
+ String[] strArray = pack.split(ORG);
+ if (strArray.length >= 3) {
+ for (int i = 1; i < strArray.length; i++) {
+ if (i == 1) {
+ pack = ORG + strArray[1];
+ } else {
+ pack = pack + ORG + strArray[i];
+ }
+ }
+ } else {
+ pack = ORG + strArray[1];
+ }
+ }
+
+ return pack;
+ }
+
+ /**
* Cleans the generated directory if already exist in source folder.
*
* @param dir generated directory in previous build
@@ -169,7 +207,7 @@
/**
* Adds generated source directory to the compilation root.
*
- * @param source directory
+ * @param source directory
* @param project current maven project
* @param context current build context
*/
@@ -182,7 +220,7 @@
/**
* Removes extra char from the string.
*
- * @param valueString string to be trimmed
+ * @param valueString string to be trimmed
* @param removealStirng extra chars
* @return new string
*/
@@ -217,8 +255,8 @@
* Returns the directory path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
+ * put
+ * @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
@@ -238,8 +276,8 @@
* Returns the absolute path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
+ * put
+ * @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
@@ -249,9 +287,9 @@
/**
* Copies YANG files to the current project's output directory.
*
- * @param yangFileInfo set of YANG files
- * @param outputDir project's output directory
- * @param project maven project
+ * @param yangFileInfo list of YANG files
+ * @param outputDir project's output directory
+ * @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
@@ -318,4 +356,113 @@
throw new IOException("Failed to insert in " + file + "file");
}
}
+
+ /**
+ * Validates a line size in given file whether it is having more then 120 characters.
+ * If yes it will update and give a new file.
+ *
+ * @param dataFile file in which need to verify all lines.
+ * @return updated file
+ * @throws IOException when fails to do IO operations.
+ */
+ public static File validateLineLength(File dataFile) throws IOException {
+ File tempFile = dataFile;
+ FileReader fileReader = new FileReader(dataFile);
+ BufferedReader bufferReader = new BufferedReader(fileReader);
+ try {
+ StringBuilder stringBuilder = new StringBuilder();
+ String line = bufferReader.readLine();
+
+ while (line != null) {
+ if (line.length() > LINE_SIZE) {
+ if (line.contains(PERIOD)) {
+ line = whenDelimiterIsPersent(line, LINE_SIZE);
+ } else if (line.contains(SPACE)) {
+ line = whenSpaceIsPresent(line, LINE_SIZE);
+ }
+ stringBuilder.append(line);
+ } else {
+ stringBuilder.append(line + NEW_LINE);
+ }
+ line = bufferReader.readLine();
+ }
+ FileWriter writer = new FileWriter(tempFile);
+ writer.write(stringBuilder.toString());
+ writer.close();
+ return tempFile;
+ } finally {
+ fileReader.close();
+ bufferReader.close();
+ }
+ }
+
+ /*When delimiters are present in the given line.*/
+ private static String whenDelimiterIsPersent(String line, int lineSize) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ if (line.length() > lineSize) {
+ String[] strArray = line.split(Pattern.quote(PERIOD));
+ stringBuilder = updateString(strArray, stringBuilder, PERIOD, lineSize);
+ } else {
+ stringBuilder.append(line + NEW_LINE);
+ }
+ String[] strArray = stringBuilder.toString().split(NEW_LINE);
+ StringBuilder tempBuilder = new StringBuilder();
+ for (String str : strArray) {
+ if (str.length() > SUB_LINE_SIZE) {
+ if (line.contains(PERIOD) && !line.contains(PERIOD + HASH + OPEN_PARENTHESIS)) {
+ String[] strArr = str.split(Pattern.quote(PERIOD));
+ tempBuilder = updateString(strArr, tempBuilder, PERIOD, SUB_LINE_SIZE);
+ } else if (str.contains(SPACE)) {
+ tempBuilder.append(whenSpaceIsPresent(str, SUB_LINE_SIZE));
+ }
+ } else {
+ tempBuilder.append(str + NEW_LINE);
+ }
+ }
+ return tempBuilder.toString();
+
+ }
+
+ /*When spaces are present in the given line.*/
+ private static String whenSpaceIsPresent(String line, int lineSize) {
+ StringBuilder stringBuilder = new StringBuilder();
+ if (line.length() > lineSize) {
+ String[] strArray = line.split(SPACE);
+ stringBuilder = updateString(strArray, stringBuilder, SPACE, lineSize);
+ } else {
+ stringBuilder.append(line + NEW_LINE);
+ }
+ return stringBuilder.toString();
+ }
+
+ /*Updates the given line with the given size conditions.*/
+ private static StringBuilder updateString(String[] strArray, StringBuilder stringBuilder, String string,
+ int lineSize) {
+
+ StringBuilder tempBuilder = new StringBuilder();
+ for (String str : strArray) {
+ tempBuilder.append(str + string);
+ if (tempBuilder.length() > lineSize) {
+ String tempString = stringBuilder.toString();
+ stringBuilder.delete(ZERO, stringBuilder.length());
+ tempString = trimAtLast(tempString, string);
+ stringBuilder.append(tempString);
+ if (string.equals(PERIOD)) {
+ stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string);
+ } else {
+ stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + str + string);
+ }
+ tempBuilder.delete(ZERO, tempBuilder.length());
+ tempBuilder.append(TWELVE_SPACE_INDENTATION);
+ } else {
+ stringBuilder.append(str + string);
+ }
+ }
+ String tempString = stringBuilder.toString();
+ tempString = trimAtLast(tempString, string);
+ stringBuilder.delete(ZERO, stringBuilder.length());
+ stringBuilder.append(tempString + NEW_LINE);
+ return stringBuilder;
+ }
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
index 00066f9..11a2fa2 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
@@ -71,7 +71,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {AttributesJavaDataType.class };
@@ -87,16 +88,17 @@
*/
@Test
public void testgetJavaClassInfo() {
- test = getJavaImportClass(getStubYangType(TYPE1), false);
+ YangToJavaNamingConflictUtil pluginConfig = null;
+ test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO1)));
- test = getJavaImportClass(getStubYangType(TYPE2), true);
+ test = getJavaImportClass(getStubYangType(TYPE2), true, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO5)));
- test = getJavaImportClass(getStubYangType(TYPE3), false);
+ test = getJavaImportClass(getStubYangType(TYPE3), false, pluginConfig);
assertThat(null, is(test));
- test = getJavaImportClass(getStubYangType(TYPE4), false);
+ test = getJavaImportClass(getStubYangType(TYPE4), false, pluginConfig);
assertThat(null, is(test));
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
index 301c58a..74043f6 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
+
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -44,7 +45,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
index 2f81a60..2a950fc 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "EnumTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/EnumTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 020ba44..05fe52d 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -29,6 +29,7 @@
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
@@ -105,7 +106,7 @@
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {MethodsGenerator.class};
+ Class<?>[] classesToConstruct = {MethodsGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -118,8 +119,10 @@
*/
@Test
public void getTypeConstructorTest() {
+
+ YangPluginConfig pluginConfig = new YangPluginConfig();
JavaAttributeInfo testAttr = getTestAttribute();
- String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME);
+ String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME, pluginConfig);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
}
@@ -162,7 +165,8 @@
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
- String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER);
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
@@ -172,7 +176,8 @@
*/
@Test
public void getConstructorStartTest() {
- String method = getConstructorStart(CLASS_NAME);
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ String method = getConstructorStart(CLASS_NAME, pluginConfig);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
@@ -227,10 +232,10 @@
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
-// assertThat(true, is(
-// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
-// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
-// + ATTRIBUTE_NAME)));
+ assertThat(true, is(
+ method.contains(PUBLIC + SPACE + VOID + SPACE +
+ SET_METHOD_PREFIX + getCapitalCase(CLASS_NAME) + OPEN_PARENTHESIS +
+ STRING_DATA_TYPE + SPACE + ATTRIBUTE_NAME)));
}
/**
@@ -240,7 +245,8 @@
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
GENERATE_SERVICE_AND_MANAGER);
-// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
+ assertThat(true, is(method.contains(VOID + SPACE +
+ SET_METHOD_PREFIX + "Testname")));
}
/**
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
index 02ff5d8..f4d8bf8 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
- generateJavaCode(node, yangPluginConfig, "NotificationTest");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/NotificationTest/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
index 8be657b..9b8077c 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "RpcTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
index 9c0c42f..9dcdfdf 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "UnionTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
index 9819445..d0df0fd 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
@@ -25,6 +25,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -125,7 +126,20 @@
javafileInfo.setJavaName(TEST_DATA_1);
javafileInfo.setBaseCodeGenPath("");
javafileInfo.setPackageFilePath(BASE_PKG);
+ javafileInfo.setPluginConfig(getStubPluginConfig());
module.setJavaFileInfo(javafileInfo);
return module;
}
+
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
+
}
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index 0284ea0..2e9f436 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -22,6 +22,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -55,7 +56,7 @@
*/
@Test
public void builderClassGenerationTest() {
- String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
+ String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
@@ -65,9 +66,10 @@
*/
@Test
public void builderInterfaceGenerationTest() {
- String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false);
+ String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
- is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING)));
+ is(builderInterfaceJavaDoc.contains("Builder for")
+ && builderInterfaceJavaDoc.contains(END_STRING)));
}
/**
@@ -75,7 +77,7 @@
*/
@Test
public void buildGenerationTest() {
- String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false);
+ String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
@@ -90,7 +92,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaDocGen.class };
@@ -106,9 +109,10 @@
*/
@Test
public void constructorGenerationTest() {
- String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false);
+ String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
- is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of")
+ is(constructorDoc.contains("Creates an instance of ")
+ && constructorDoc.contains("builder object of")
&& constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
}
@@ -117,7 +121,7 @@
*/
@Test
public void defaultConstructorGenerationTest() {
- String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false);
+ String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
&& defaultConstructorDoc.contains(END_STRING)));
}
@@ -127,8 +131,9 @@
*/
@Test
public void getterGenerationTest() {
- String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false);
- assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
+ String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
+ assertThat(true,
+ is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
/**
@@ -136,7 +141,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
+ String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
@@ -147,7 +152,7 @@
*/
@Test
public void interfaceGenerationTest() {
- String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
+ String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
&& interfaceJavaDoc.contains(END_STRING)));
@@ -158,8 +163,9 @@
*/
@Test
public void packageInfoGenerationTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
- assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig());
+ assertThat(true,
+ is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
}
/**
@@ -167,7 +173,7 @@
*/
@Test
public void packageInfoGenerationForChildNodeTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true);
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig());
assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
&& packageInfo.contains(END_STRING)));
}
@@ -177,7 +183,7 @@
*/
@Test
public void setterGenerationTest() {
- String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false);
+ String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
@@ -187,7 +193,18 @@
*/
@Test
public void typeDefSetterGenerationTest() {
- String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false);
+ String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
+
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
index 204bd7b..c4558f6 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
@@ -25,6 +25,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.UtilConstants;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
@@ -68,7 +69,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -83,7 +84,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -98,7 +99,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true);
+ addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -114,7 +115,7 @@
File dirPath = new File("invalid/check");
thrown.expect(IOException.class);
thrown.expectMessage(MSG);
- addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath1 = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath1.isFile(), is(false));
}
@@ -130,7 +131,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {YangIoUtils.class };
@@ -192,7 +194,7 @@
addToSource(sourceDir.toString(), project, context);
}
- /*
+ /**
* Unit test case for trim at last method.
*/
@Test
@@ -202,4 +204,14 @@
assertThat(test.contains(TRIM_STRING), is(true));
}
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
}