[ONOS-4350] Inter Jar dependency implementation and code restructuring.
Change-Id: Iacac75e4187aed93ce1754c170a9c19707e5b8c3
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java
new file mode 100644
index 0000000..cf2c07d
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java
@@ -0,0 +1,79 @@
+/*
+ * 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.exception;
+
+/**
+ * Represents custom translator exception for translator's operations.
+ */
+public class TranslatorException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160311L;
+ private String fileName;
+
+ /**
+ * Create a new translator exception.
+ */
+ public TranslatorException() {
+ super();
+ }
+
+ /**
+ * Creates a new translator exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public TranslatorException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new translator exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public TranslatorException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new translator exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public TranslatorException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns generated file name for the exception.
+ *
+ * @return generated file name for the exception
+ */
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ /**
+ * Sets file name in translator exception.
+ *
+ * @param fileName generated file name
+ */
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java
new file mode 100644
index 0000000..b88a8a3
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Custom exception for translator.
+ */
+package org.onosproject.yangutils.translator.exception;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java
new file mode 100644
index 0000000..72ba2e4
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Translator to generate class definition corresponding to YANG definition.
+ */
+package org.onosproject.yangutils.translator;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
new file mode 100644
index 0000000..d4666c0
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+/**
+ * Represents type of java files generated.
+ */
+public final class GeneratedJavaFileType {
+
+ /**
+ * Interface file.
+ */
+ public static final int INTERFACE_MASK = 1;
+
+ /**
+ * Builder interface file.
+ */
+ public static final int BUILDER_INTERFACE_MASK = 2;
+
+ /**
+ * Builder class file.
+ */
+ public static final int BUILDER_CLASS_MASK = 4;
+
+ /**
+ * Impl class file.
+ */
+ public static final int IMPL_CLASS_MASK = 8;
+
+ /**
+ * Interface and class file.
+ */
+ public static final int GENERATE_INTERFACE_WITH_BUILDER = INTERFACE_MASK
+ | BUILDER_INTERFACE_MASK | BUILDER_CLASS_MASK | IMPL_CLASS_MASK;
+
+ /**
+ * Java interface corresponding to rpc.
+ */
+ public static final int GENERATE_SERVICE_AND_MANAGER = 16;
+
+ /**
+ * Java class corresponding to YANG enumeration.
+ */
+ public static final int GENERATE_ENUM_CLASS = 32;
+
+ /**
+ * Java class corresponding to typedef.
+ */
+ public static final int GENERATE_TYPEDEF_CLASS = 64;
+
+ /**
+ * Java class corresponding to union.
+ */
+ public static final int GENERATE_UNION_CLASS = 128;
+
+ /**
+ * Java class corresponding to typedef.
+ */
+ public static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
+ | GENERATE_UNION_CLASS;
+
+ /**
+ * Event class.
+ */
+ public static final int GENERATE_EVENT_CLASS = 256;
+
+ /**
+ * Event listener class.
+ */
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
new file mode 100644
index 0000000..2ffd282
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
@@ -0,0 +1,129 @@
+/*
+ * 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;
+
+/**
+ * Represents type of temporary files generated.
+ */
+public final class GeneratedTempFileType {
+
+ /**
+ * Attributes definition temporary file.
+ */
+ public static final int ATTRIBUTES_MASK = 1;
+
+ /**
+ * Getter methods for interface.
+ */
+ public static final int GETTER_FOR_INTERFACE_MASK = 2;
+
+ /**
+ * Getter methods for class.
+ */
+ public static final int GETTER_FOR_CLASS_MASK = 4;
+
+ /**
+ * Setter methods for interface.
+ */
+ public static final int SETTER_FOR_INTERFACE_MASK = 8;
+
+ /**
+ * Setter methods for class.
+ */
+ public static final int SETTER_FOR_CLASS_MASK = 16;
+
+ /**
+ * Constructor method of class.
+ */
+ public static final int CONSTRUCTOR_IMPL_MASK = 32;
+
+ /**
+ * Hash code implementation of class.
+ */
+ public static final int HASH_CODE_IMPL_MASK = 64;
+
+ /**
+ * Equals implementation of class.
+ */
+ public static final int EQUALS_IMPL_MASK = 128;
+
+ /**
+ * To string implementation of class.
+ */
+ public static final int TO_STRING_IMPL_MASK = 256;
+
+ /**
+ * Of string implementation of class.
+ */
+ public static final int OF_STRING_IMPL_MASK = 512;
+
+ /**
+ * Constructor for type class like typedef, union.
+ */
+ public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1024;
+
+ /**
+ * From string implementation of class.
+ */
+ public static final int FROM_STRING_IMPL_MASK = 2048;
+
+ /**
+ * Enum implementation of class.
+ */
+ public static final int ENUM_IMPL_MASK = 4096;
+
+ /**
+ * Rpc interface of module / sub module.
+ */
+ public static final int RPC_INTERFACE_MASK = 8192;
+
+ /**
+ * Rpc implementation of module / sub module.
+ */
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
new file mode 100644
index 0000000..485878b
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -0,0 +1,200 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+
+/**
+ * Represents the attribute info corresponding to class/interface generated.
+ */
+public final class JavaAttributeInfo {
+
+ /**
+ * The data type info of attribute.
+ */
+ private YangType<?> attrType;
+
+ /**
+ * Name of the attribute.
+ */
+ private String name;
+
+ /**
+ * If the added attribute is a list of info.
+ */
+ private boolean isListAttr;
+
+ /**
+ * If the added attribute has to be accessed in a fully qualified manner.
+ */
+ private boolean isQualifiedName;
+
+ /**
+ * The class info will be used to set the attribute type and package info
+ * will be use for qualified name.
+ */
+ private JavaQualifiedTypeInfo importInfo;
+
+ /**
+ * Creates a java attribute info object.
+ */
+ private JavaAttributeInfo() {
+ }
+
+ /**
+ * Creates object of java attribute info.
+ *
+ * @param attrType YANG type
+ * @param name attribute name
+ * @param isListAttr is list attribute
+ * @param isQualifiedName is qualified name
+ */
+ public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
+ this.attrType = attrType;
+ this.name = name;
+ this.isListAttr = isListAttr;
+ this.isQualifiedName = isQualifiedName;
+ }
+
+ /**
+ * Returns the data type info of attribute.
+ *
+ * @return the data type info of attribute
+ */
+ public YangType<?> getAttributeType() {
+
+ if (attrType == null) {
+ throw new TranslatorException("Expected java attribute type is null");
+ }
+ return attrType;
+ }
+
+ /**
+ * Sets the data type info of attribute.
+ *
+ * @param type the data type info of attribute
+ */
+ public void setAttributeType(YangType<?> type) {
+ attrType = type;
+ }
+
+ /**
+ * Returns name of the attribute.
+ *
+ * @return name of the attribute
+ */
+ public String getAttributeName() {
+
+ if (name == null) {
+ throw new TranslatorException("Expected java attribute name is null");
+ }
+ return name;
+ }
+
+ /**
+ * Sets name of the attribute.
+ *
+ * @param attrName name of the attribute
+ */
+ public void setAttributeName(String attrName) {
+ name = attrName;
+ }
+
+ /**
+ * Returns if the added attribute is a list of info.
+ *
+ * @return the if the added attribute is a list of info
+ */
+ public boolean isListAttr() {
+ return isListAttr;
+ }
+
+ /**
+ * Sets if the added attribute is a list of info.
+ *
+ * @param isList if the added attribute is a list of info
+ */
+ public void setListAttr(boolean isList) {
+ isListAttr = isList;
+ }
+
+ /**
+ * Returns if the added attribute has to be accessed in a fully qualified
+ * manner.
+ *
+ * @return the if the added attribute has to be accessed in a fully
+ * qualified manner.
+ */
+ public boolean isQualifiedName() {
+ return isQualifiedName;
+ }
+
+ /**
+ * Sets if the added attribute has to be accessed in a fully qualified
+ * manner.
+ *
+ * @param isQualified if the added attribute has to be accessed in a fully
+ * qualified manner
+ */
+ public void setIsQualifiedAccess(boolean isQualified) {
+ isQualifiedName = isQualified;
+ }
+
+ /**
+ * Returns the import info for the attribute type. It will be null, if the type
+ * is basic built-in java type.
+ *
+ * @return import info
+ */
+ public JavaQualifiedTypeInfo getImportInfo() {
+ return importInfo;
+ }
+
+ /**
+ * Sets the import info for the attribute type.
+ *
+ * @param importInfo import info for the attribute type
+ */
+ public void setImportInfo(JavaQualifiedTypeInfo importInfo) {
+ this.importInfo = importInfo;
+ }
+
+ /**
+ * Returns java attribute info.
+ *
+ * @param importInfo java qualified type info
+ * @param attributeName attribute name
+ * @param attributeType attribute type
+ * @param isQualifiedAccess is the attribute a qualified access
+ * @param isListAttribute is list attribute
+ * @return java attribute info.
+ */
+ public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
+ YangType<?> attributeType, boolean isQualifiedAccess,
+ boolean isListAttribute) {
+
+ JavaAttributeInfo newAttr = new JavaAttributeInfo();
+ newAttr.setImportInfo(importInfo);
+ newAttr.setAttributeName(attributeName);
+ newAttr.setAttributeType(attributeType);
+ newAttr.setIsQualifiedAccess(isQualifiedAccess);
+ newAttr.setListAttr(isListAttribute);
+
+ return newAttr;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
new file mode 100644
index 0000000..277038c
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+/**
+ * Abstraction of an entity which provides Code generator functionalities.
+ */
+public interface JavaCodeGenerator {
+
+ /**
+ * Traverse the schema of application and generate corresponding code.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to translate the data model tree
+ */
+ void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException;
+
+ /**
+ * Traverse the schema of application and generate corresponding code.
+ *
+ * @throws TranslatorException when fails to generate java code
+ */
+ void generateCodeExit()
+ throws TranslatorException;
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
new file mode 100644
index 0000000..a6eb9d7
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -0,0 +1,262 @@
+/*
+ * 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.IOException;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
+
+/**
+ * Representation of java code generator based on application schema.
+ */
+public final class JavaCodeGeneratorUtil {
+
+ /**
+ * Current YANG node.
+ */
+ private static YangNode curNode;
+
+ /**
+ * Creates a java code generator utility object.
+ */
+ private JavaCodeGeneratorUtil() {
+ }
+
+ /**
+ * Returns current YANG node.
+ *
+ * @return current YANG node
+ */
+ public static YangNode getCurNode() {
+ return curNode;
+ }
+
+ /**
+ * Sets current YANG node.
+ *
+ * @param node current YANG node
+ */
+ public static void setCurNode(YangNode node) {
+ curNode = node;
+ }
+
+ /**
+ * Generates Java code files corresponding to the YANG schema.
+ *
+ * @param rootNode root node of the data model tree
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to generate java code file the current
+ * node
+ */
+ public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
+ throws TranslatorException {
+
+ YangNode codeGenNode = rootNode;
+ TraversalType curTraversal = ROOT;
+
+ while (codeGenNode != null) {
+ if (curTraversal != PARENT) {
+ if (!(codeGenNode instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("Unsupported node to generate code");
+ }
+
+ setCurNode(codeGenNode);
+ try {
+ generateCodeEntry(codeGenNode, yangPlugin);
+ } catch (Exception e) {
+ throw new TranslatorException(e.getMessage());
+ }
+
+ }
+ if (curTraversal != PARENT && codeGenNode.getChild() != null) {
+ curTraversal = CHILD;
+ codeGenNode = codeGenNode.getChild();
+ } else if (codeGenNode.getNextSibling() != null) {
+ try {
+ generateCodeExit(codeGenNode);
+ } catch (Exception e) {
+ throw new TranslatorException(e.getMessage());
+ }
+ curTraversal = SIBILING;
+ codeGenNode = codeGenNode.getNextSibling();
+ } else {
+ try {
+ generateCodeExit(codeGenNode);
+ } catch (Exception e) {
+ throw new TranslatorException(e.getMessage());
+ }
+ curTraversal = PARENT;
+ codeGenNode = codeGenNode.getParent();
+ }
+ }
+ }
+
+ /**
+ * Generates the current nodes code snippet.
+ *
+ * @param codeGenNode current data model node for which the code needs to be
+ * generated
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to generate java code file the current
+ * node
+ */
+ private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
+ throws TranslatorException {
+
+ if (codeGenNode instanceof JavaCodeGenerator) {
+ ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
+ } else {
+ throw new TranslatorException(
+ "Generated data model node cannot be translated to target language code");
+ }
+ }
+
+ /**
+ * Generates the current nodes code target code from the snippet.
+ *
+ * @param codeGenNode current data model node for which the code needs to be
+ * generated
+ * @throws TranslatorException when fails to generate java code file the current
+ * node
+ */
+ private static void generateCodeExit(YangNode codeGenNode)
+ throws TranslatorException {
+
+ if (codeGenNode instanceof JavaCodeGenerator) {
+ ((JavaCodeGenerator) codeGenNode).generateCodeExit();
+ } else {
+ throw new TranslatorException(
+ "Generated data model node cannot be translated to target language code");
+ }
+ }
+
+ /**
+ * Free other YANG nodes of data-model tree when error occurs while file
+ * generation of current node.
+ */
+ private static void freeRestResources() {
+
+ YangNode freedNode = getCurNode();
+ if (getCurNode() != null) {
+ YangNode tempNode = freedNode;
+ TraversalType curTraversal = ROOT;
+
+ 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);
+ }
+ freedNode = freedNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ if (freedNode != tempNode) {
+ free(freedNode);
+ }
+ freedNode = freedNode.getParent();
+ }
+ }
+ }
+ }
+
+ /**
+ * Free the current node.
+ *
+ * @param node YANG node
+ */
+ private static void free(YangNode node) {
+
+ YangNode parent = node.getParent();
+ parent.setChild(null);
+
+ if (node.getNextSibling() != null) {
+ parent.setChild(node.getNextSibling());
+ } else if (node.getPreviousSibling() != null) {
+ parent.setChild(node.getPreviousSibling());
+ }
+ node = null;
+ }
+
+ /**
+ * Delete Java code files corresponding to the YANG schema.
+ *
+ * @param rootNode root node of data-model tree
+ * @throws IOException when fails to delete java code file the current node
+ */
+ public static void translatorErrorHandler(YangNode rootNode)
+ throws IOException {
+
+ 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;
+
+ while (tempNode != null) {
+
+ 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();
+ }
+ }
+
+ freeRestResources();
+ }
+ }
+
+ /**
+ * Closes all the current open file handles of node and delete all generated
+ * files.
+ *
+ * @param node current YANG node
+ * @throws IOException when fails to do IO operations
+ */
+ private static void close(YangNode node)
+ throws IOException {
+ if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles() != null) {
+ ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
new file mode 100644
index 0000000..28302ee
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
@@ -0,0 +1,184 @@
+/*
+ * 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.Serializable;
+
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+/**
+ * Represents cached java file handle, which supports the addition of member attributes and
+ * methods.
+ */
+public class JavaFileInfo implements Serializable {
+
+ private static final long serialVersionUID = 806102633L;
+
+ /**
+ * The type(s) of java source file(s) to be generated when the cached file
+ * handle is closed.
+ */
+ private transient int genFileTypes;
+
+ /**
+ * Name of the module.
+ */
+ private String javaName;
+
+ /**
+ * Java Package of the mapped java class.
+ */
+ private String pkg;
+
+ /**
+ * File generation directory path.
+ */
+ private String relativeFilePath;
+
+ /**
+ * File generation base directory path.
+ */
+ private String codeGenDirFilePath;
+
+ /**
+ * Plugin configuration for naming convention.
+ */
+ private transient YangPluginConfig pluginConfig;
+
+ /**
+ * Returns the types of files being generated corresponding to the YANG
+ * definition.
+ *
+ * @return the types of files being generated corresponding to the YANG
+ * definition
+ */
+ public int getGeneratedFileTypes() {
+ return genFileTypes;
+ }
+
+ /**
+ * Sets the types of files being generated corresponding to the YANG
+ * definition.
+ *
+ * @param fileTypes the types of files being generated corresponding to the
+ * YANG definition
+ */
+ public void setGeneratedFileTypes(int fileTypes) {
+ genFileTypes = fileTypes;
+ }
+
+ /**
+ * Adds the types of files being generated corresponding to the YANG
+ * definition.
+ *
+ * @param fileTypes the types of files being generated corresponding to the
+ * YANG definition
+ */
+ public void addGeneratedFileTypes(int fileTypes) {
+ genFileTypes |= fileTypes;
+ }
+
+ /**
+ * Returns the java name of the node.
+ *
+ * @return the java name of node
+ */
+ public String getJavaName() {
+ return javaName;
+ }
+
+ /**
+ * Sets the java name of the node.
+ *
+ * @param name the java name of node
+ */
+ public void setJavaName(String name) {
+ javaName = name;
+ }
+
+ /**
+ * Returns the mapped java package.
+ *
+ * @return the java package
+ */
+ public String getPackage() {
+ return pkg;
+ }
+
+ /**
+ * Sets the node's package.
+ *
+ * @param nodePackage node's package
+ */
+ public void setPackage(String nodePackage) {
+ pkg = nodePackage;
+ }
+
+ /**
+ * Sets directory package path for code generation.
+ *
+ * @param path directory package path for code generation
+ */
+ public void setPackageFilePath(String path) {
+ relativeFilePath = path;
+ }
+
+ /**
+ * Returns directory package path for code generation.
+ *
+ * @return directory package path for code generation
+ */
+ public String getPackageFilePath() {
+ return relativeFilePath;
+ }
+
+ /**
+ * Returns base directory package path for code generation.
+ *
+ * @return directory package path for code generation
+ */
+ public String getBaseCodeGenPath() {
+ return codeGenDirFilePath;
+ }
+
+ /**
+ * Sets base directory package path for code generation.
+ *
+ * @param path base directory path
+ */
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java
new file mode 100644
index 0000000..485df77
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Represents data model nodes which are required to generate java classes, need to support
+ * java file info.
+ */
+public interface JavaFileInfoContainer {
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ JavaFileInfo getJavaFileInfo();
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ void setJavaFileInfo(JavaFileInfo javaInfo);
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
new file mode 100644
index 0000000..b1c36ec
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -0,0 +1,284 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
+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_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;
+
+import static java.util.Collections.sort;
+
+/**
+ * Represents that generated Java file can contain imports.
+ */
+public class JavaImportData {
+
+ /**
+ * Flag to denote if any list in imported.
+ */
+ private boolean isListToImport;
+
+ /**
+ * Sorted set of import info, to be used to maintain the set of classes to
+ * be imported in the generated class.
+ */
+ private SortedSet<JavaQualifiedTypeInfo> importSet;
+
+ /**
+ * Creates java import data object.
+ */
+ public JavaImportData() {
+ setImportSet(new TreeSet<JavaQualifiedTypeInfo>());
+ }
+
+ /**
+ * Returns if the list needs to be imported.
+ *
+ * @return true if any of the attribute needs to be maintained as a list
+ */
+ public boolean getIfListImported() {
+ return isListToImport;
+ }
+
+ /**
+ * Sets the status of importing list.
+ *
+ * @param isList status to mention list is bing imported
+ */
+ public void setIfListImported(boolean isList) {
+ isListToImport = isList;
+ }
+
+ /**
+ * Returns the set containing the imported class/interface info.
+ *
+ * @return the set containing the imported class/interface info
+ */
+ public SortedSet<JavaQualifiedTypeInfo> getImportSet() {
+ return importSet;
+ }
+
+ /**
+ * Assigns the set containing the imported class/interface info.
+ *
+ * @param importSet the set containing the imported class/interface info
+ */
+ private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) {
+ this.importSet = importSet;
+ }
+
+ /**
+ * Adds an imported class/interface info if it is not already part of the
+ * collection.
+ *
+ * If already part of the collection, check if the packages are same, if so
+ * then return true, to denote it is already in the import collection, and
+ * it can be accessed without qualified access. If the packages do not
+ * match, then do not add to the import collection, and return false to
+ * denote, it is not added to import collection and needs to be accessed in
+ * a qualified manner.
+ *
+ * @param newImportInfo class/interface info being imported
+ * @param className name of the call being generated
+ * @param classPkg generated class package
+ * @return qualified access status of the import node being added
+ */
+ public boolean addImportInfo(JavaQualifiedTypeInfo newImportInfo,
+ String className, String classPkg) {
+
+ if (newImportInfo.getClassInfo().contentEquals(className)) {
+ /*
+ * if the current class name is same as the attribute class name,
+ * then the attribute must be accessed in a qualified manner.
+ */
+ return true;
+ } else if (newImportInfo.getPkgInfo() == null) {
+ /*
+ * If the package info is null, then it is not a candidate for import / qualified access
+ */
+ return false;
+ }
+
+ /*
+ * If the attribute type is having the package info, it is contender
+ * for import list and also need to check if it needs to be a
+ * qualified access.
+ */
+ if (newImportInfo.getPkgInfo().contentEquals(classPkg)) {
+ /**
+ * Package of the referred attribute and the generated class is same, so no need import
+ * or qualified access.
+ */
+ return false;
+ }
+
+ for (JavaQualifiedTypeInfo curImportInfo : getImportSet()) {
+ if (curImportInfo.getClassInfo()
+ .contentEquals(newImportInfo.getClassInfo())) {
+ return !curImportInfo.getPkgInfo()
+ .contentEquals(newImportInfo.getPkgInfo());
+ }
+ }
+
+ /*
+ * import is added, so it is a member for non qualified access
+ */
+ getImportSet().add(newImportInfo);
+ return false;
+ }
+
+ /**
+ * Returns import for class.
+ *
+ * @return imports for class
+ */
+ public List<String> getImports() {
+
+ String importString;
+ List<String> imports = new ArrayList<>();
+
+ for (JavaQualifiedTypeInfo importInfo : getImportSet()) {
+ if (!importInfo.getPkgInfo().equals(EMPTY_STRING) && importInfo.getClassInfo() != null
+ && !importInfo.getPkgInfo().equals(JAVA_LANG)) {
+ importString = IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN
+ + NEW_LINE;
+
+ imports.add(importString);
+ }
+ }
+
+ if (getIfListImported()) {
+ imports.add(getImportForList());
+ }
+
+ sort(imports);
+ return imports;
+ }
+
+ /**
+ * Returns import for hash and equals method.
+ *
+ * @return import for hash and equals method
+ */
+ public String getImportForHashAndEquals() {
+ return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS;
+ }
+
+ /**
+ * Returns import for to string method.
+ *
+ * @return import for to string method
+ */
+ public String getImportForToString() {
+ return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS;
+ }
+
+ /**
+ * Returns import for list attribute.
+ *
+ * @return import for list attribute
+ */
+ public String getImportForList() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import for array list attribute.
+ *
+ * @return import for array list attribute
+ */
+ public String getImportForArrayList() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for AugmentationHolder class.
+ *
+ * @return import string for AugmentationHolder class
+ */
+ public String getAugmentationHolderImport() {
+ return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
+ }
+
+ /**
+ * Returns import string for AugmentedInfo class.
+ *
+ * @return import string for AugmentedInfo class
+ */
+ public String getAugmentedInfoImport() {
+ return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
+ }
+
+ /**
+ * Returns import string for ListenerService class.
+ *
+ * @return import string for ListenerService class
+ */
+ public String getListenerServiceImport() {
+ return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for ListenerRegistry class.
+ *
+ * @return import string for ListenerRegistry class
+ */
+ public String getListenerRegistryImport() {
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportDataContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportDataContainer.java
new file mode 100644
index 0000000..e86b468
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportDataContainer.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Represents the information of the java import data.
+ */
+public interface JavaImportDataContainer {
+
+ /**
+ * Returns the data of java imports to be included in generated file.
+ *
+ * @return data of java imports to be included in generated file
+ */
+ JavaImportData getJavaImportData();
+
+ /**
+ * Sets the data of java imports to be included in generated file.
+ *
+ * @param javaImportData data of java imports to be included in generated
+ * file
+ */
+ void setJavaImportData(JavaImportData javaImportData);
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
new file mode 100644
index 0000000..98e44f8
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
@@ -0,0 +1,235 @@
+/*
+ * 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.Serializable;
+import java.util.Objects;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+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;
+
+import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
+import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
+
+/**
+ * Represents the information about individual imports in the generated file.
+ */
+public class JavaQualifiedTypeInfo
+ implements Comparable<JavaQualifiedTypeInfo>, Serializable {
+
+ private static final long serialVersionUID = 806201634L;
+
+ /**
+ * Package location where the imported class/interface is defined.
+ */
+ private String pkgInfo;
+
+ /**
+ * Class/interface being referenced.
+ */
+ private String classInfo;
+
+ /**
+ * Creates a java qualified type info object.
+ */
+ public JavaQualifiedTypeInfo() {
+ }
+
+ /**
+ * Returns the imported package info.
+ *
+ * @return the imported package info
+ */
+ public String getPkgInfo() {
+ return pkgInfo;
+ }
+
+ /**
+ * Sets the imported package info.
+ *
+ * @param pkgInfo the imported package info
+ */
+ public void setPkgInfo(String pkgInfo) {
+ this.pkgInfo = pkgInfo;
+ }
+
+ /**
+ * Returns the imported class/interface info.
+ *
+ * @return the imported class/interface info
+ */
+ public String getClassInfo() {
+ return classInfo;
+ }
+
+ /**
+ * Sets the imported class/interface info.
+ *
+ * @param classInfo the imported class/interface info
+ */
+ public void setClassInfo(String classInfo) {
+ this.classInfo = classInfo;
+ }
+
+ /**
+ * Updates the leaf's java information.
+ *
+ * @param leaf leaf whose java information is being updated
+ */
+ public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) {
+
+ JavaQualifiedTypeInfo importInfo = leaf.getJavaQualifiedInfo();
+
+ if (leaf.getDataType() == null) {
+ throw new TranslatorException("missing data type of leaf " + leaf.getName());
+ }
+
+ /*
+ * Current leaves holder is adding a leaf info as a attribute to the
+ * current class.
+ */
+ String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
+ leaf.getConflictResolveConfig());
+ if (className != null) {
+ /*
+ * Corresponding to the attribute type a class needs to be imported,
+ * since it can be a derived type or a usage of wrapper classes.
+ */
+ importInfo.setClassInfo(className);
+ String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(),
+ leaf.isLeafList(), leaf.getConflictResolveConfig());
+ if (classPkg == null) {
+ throw new TranslatorException("import package cannot be null when the class is used");
+ }
+ importInfo.setPkgInfo(classPkg);
+ } else {
+ /*
+ * The attribute does not need a class to be imported, for example
+ * built in java types.
+ */
+ String dataTypeName = AttributesJavaDataType.getJavaDataType(leaf.getDataType());
+ if (dataTypeName == null) {
+ throw new TranslatorException("not supported data type");
+ }
+ importInfo.setClassInfo(dataTypeName);
+ }
+ }
+
+ /**
+ * Returns the import info for an attribute, which needs to be used for code
+ * generation for import or for qualified access.
+ *
+ * @param curNode current data model node for which the java file is being
+ * generated
+ * @param attributeName name of the attribute being added, it will used in
+ * import info for child class
+ * @return return the import info for this attribute
+ */
+ public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode,
+ String attributeName) {
+
+ JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
+
+ if (!(curNode instanceof JavaFileInfoContainer)) {
+ throw new TranslatorException("missing java file information to get the package details "
+ + "of attribute corresponding to child node");
+ }
+
+ importInfo.setClassInfo(attributeName);
+ importInfo.setPkgInfo(((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo().getPackage());
+
+ return importInfo;
+ }
+
+ /**
+ * Returns the java qualified type information for the wrapper classes.
+ *
+ * @param referredTypesAttrInfo attribute of referred type
+ * @param conflictResolver plugin configurations
+ * @return return the import info for this attribute
+ */
+ public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo,
+ YangToJavaNamingConflictUtil conflictResolver) {
+
+ /*
+ * 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, conflictResolver));
+ qualifiedInfoOfFromString.setPkgInfo(
+ getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, conflictResolver));
+ return qualifiedInfoOfFromString;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(pkgInfo, classInfo);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof JavaQualifiedTypeInfo) {
+ JavaQualifiedTypeInfo other = (JavaQualifiedTypeInfo) obj;
+ return Objects.equals(pkgInfo, other.pkgInfo) &&
+ Objects.equals(classInfo, other.classInfo);
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the import info matches.
+ *
+ * @param importInfo matched import
+ * @return if equal or not
+ */
+ public boolean exactMatch(JavaQualifiedTypeInfo importInfo) {
+ return equals(importInfo)
+ && Objects.equals(pkgInfo, importInfo.getPkgInfo())
+ && Objects.equals(classInfo, importInfo.getClassInfo());
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("pkgInfo", pkgInfo)
+ .add("classInfo", classInfo).toString();
+ }
+
+ /**
+ * Checks that there is no 2 objects with the same class name.
+ *
+ * @param other compared import info.
+ */
+ @Override
+ public int compareTo(JavaQualifiedTypeInfo other) {
+ return getClassInfo().compareTo(other.getClassInfo());
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoContainer.java
new file mode 100644
index 0000000..c6570c6
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoContainer.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.translator.tojava;
+
+/**
+ * Maintain the java qualified access details for an attribute or a class.
+ */
+public interface JavaQualifiedTypeInfoContainer {
+
+ /**
+ * Obtain the java qualified details.
+ *
+ * @return java qualified type details
+ */
+ JavaQualifiedTypeInfo getJavaQualifiedInfo();
+
+ /**
+ * Assign the qualified type info.
+ *
+ * @param typeInfo qualified type information
+ */
+ void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo);
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
new file mode 100644
index 0000000..14f4cd2
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
@@ -0,0 +1,129 @@
+/*
+ * 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.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;
+
+/**
+ * Represents implementation of java bean code fragments temporary implementations.
+ * Maintains the temp files required specific for bean java snippet generation.
+ */
+public class TempJavaBeanFragmentFiles
+ extends TempJavaFragmentFiles {
+
+ /**
+ * File name for constructor.
+ */
+ private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
+
+ /**
+ * Temporary file handle for constructor of class.
+ */
+ private File constructorImplTempFileHandle;
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file info
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+
+ super(javaFileInfo);
+
+ /*
+ * Initialize getterImpl, attributes, constructor, hash code, equals and
+ * to strings when generation file type matches to impl class mask.
+ */
+ addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
+
+ setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
+ }
+
+ /**
+ * Returns constructor's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getConstructorImplTempFileHandle() {
+ return constructorImplTempFileHandle;
+ }
+
+ /**
+ * Sets to constructor's temporary file handle.
+ *
+ * @param constructor file handle for to constructor
+ */
+ private void setConstructorImplTempFileHandle(File constructor) {
+ constructorImplTempFileHandle = constructor;
+ }
+
+ /**
+ * Adds constructor for class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
+ getGeneratedJavaFiles(), pluginConfig));
+ }
+
+ /**
+ * Adds the new attribute info to the target generated temporary files.
+ *
+ * @param newAttrInfo the attribute info that needs to be added to temporary
+ * files
+ * @throws IOException IO operation fail
+ */
+ @Override
+ void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
+ throws IOException {
+ super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
+ addConstructor(newAttrInfo, pluginConfig);
+ }
+
+ /**
+ * 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 {
+
+ /*
+ * Close constructor temporary file handle and delete the file.
+ */
+ closeFile(getConstructorImplTempFileHandle(), true);
+
+ super.freeTemporaryResources(isErrorOccurred);
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
new file mode 100644
index 0000000..309ee66
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -0,0 +1,317 @@
+/*
+ * 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.IOException;
+
+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_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;
+
+/**
+ * Represents implementation of java code fragments temporary implementations.
+ * Contains fragment file object of different types of java file.
+ * Uses required object(s) to generate the target java file(s).
+ */
+public class TempJavaCodeFragmentFiles {
+
+ /**
+ * Has the temporary files required for bean generated classes.
+ */
+ private TempJavaBeanFragmentFiles beanTempFiles;
+
+ /**
+ * Has the temporary files required for bean generated classes.
+ */
+ private TempJavaTypeFragmentFiles typeTempFiles;
+
+ /**
+ * Has the temporary files required for service generated classes.
+ */
+ private TempJavaServiceFragmentFiles serviceTempFiles;
+
+ /**
+ * Has the temporary files required for enumeration generated classes.
+ */
+ private TempJavaEnumerationFragmentFiles enumerationTempFiles;
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file info
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaCodeFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo));
+ }
+
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) {
+ setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo));
+ }
+
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) {
+ setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
+ }
+
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
+ }
+
+ }
+
+ /**
+ * Retrieves the temp file handle for bean file generation.
+ *
+ * @return temp file handle for bean file generation
+ */
+ public TempJavaBeanFragmentFiles getBeanTempFiles() {
+ return beanTempFiles;
+ }
+
+ /**
+ * Sets temp file handle for bean file generation.
+ *
+ * @param beanTempFiles temp file handle for bean file generation
+ */
+ public void setBeanTempFiles(TempJavaBeanFragmentFiles beanTempFiles) {
+ this.beanTempFiles = beanTempFiles;
+ }
+
+ /**
+ * Retrieves the temp file handle for data type file generation.
+ *
+ * @return temp file handle for data type file generation
+ */
+ public TempJavaTypeFragmentFiles getTypeTempFiles() {
+ return typeTempFiles;
+ }
+
+ /**
+ * Sets temp file handle for data type file generation.
+ *
+ * @param typeTempFiles temp file handle for data type file generation
+ */
+ public void setTypeTempFiles(TempJavaTypeFragmentFiles typeTempFiles) {
+ this.typeTempFiles = typeTempFiles;
+ }
+
+ /**
+ * Retrieves the temp file handle for service file generation.
+ *
+ * @return temp file handle for service file generation
+ */
+ public TempJavaServiceFragmentFiles getServiceTempFiles() {
+ return serviceTempFiles;
+ }
+
+ /**
+ * Sets temp file handle for service file generation.
+ *
+ * @param serviceTempFiles temp file handle for service file generation
+ */
+ public void setServiceTempFiles(TempJavaServiceFragmentFiles serviceTempFiles) {
+ this.serviceTempFiles = serviceTempFiles;
+ }
+
+ /**
+ * Retrieves the temp file handle for enumeration file generation.
+ *
+ * @return temp file handle for enumeration file generation
+ */
+ public TempJavaEnumerationFragmentFiles getEnumerationTempFiles() {
+ return enumerationTempFiles;
+ }
+
+ /**
+ * Sets temp file handle for enumeration file generation.
+ *
+ * @param enumerationTempFiles temp file handle for enumeration file generation
+ */
+ public void setEnumerationTempFiles(
+ TempJavaEnumerationFragmentFiles enumerationTempFiles) {
+ this.enumerationTempFiles = enumerationTempFiles;
+ }
+
+ /**
+ * Constructs java code exit.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+
+ if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ getBeanTempFiles().generateJavaFile(fileType, curNode);
+ }
+
+ /*
+ * Creates user defined data type class file.
+ */
+ if ((fileType & GENERATE_TYPE_CLASS) != 0) {
+ getTypeTempFiles().generateJavaFile(fileType, curNode);
+ }
+
+ /*
+ * Creates service and manager class file.
+ */
+ if (fileType == GENERATE_SERVICE_AND_MANAGER) {
+ getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
+ }
+
+ /*
+ * Creats enumeration class file.
+ */
+ if (fileType == GENERATE_ENUM_CLASS) {
+ getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
+ }
+
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Adds the new attribute info to the target generated temporary files.
+ *
+ * @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,
+ YangPluginConfig pluginConfig)
+ throws IOException {
+
+ if (getBeanTempFiles() != null) {
+ getBeanTempFiles()
+ .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
+ }
+
+ /**
+ * Creates user defined data type class file.
+ */
+ if (getTypeTempFiles() != null) {
+ getTypeTempFiles()
+ .addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
+ }
+ }
+
+ /**
+ * Add all the type in the current data model node as part of the
+ * 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ getTypeTempFiles()
+ .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(YangPluginConfig pluginConfig)
+ throws IOException {
+ if (getBeanTempFiles() != null) {
+ return getBeanTempFiles().addBuildMethodForInterface(pluginConfig);
+ }
+ throw new TranslatorException("build method only supported for bean class");
+ }
+
+ /**
+ * Adds default constructor for class.
+ *
+ * @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, YangPluginConfig pluginConfig)
+ throws IOException {
+ if (getTypeTempFiles() != null) {
+ return getTypeTempFiles()
+ .addDefaultConstructor(modifier, toAppend, pluginConfig);
+ }
+
+ if (getBeanTempFiles() != null) {
+ return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
+ }
+
+ throw new TranslatorException("default constructor should not be added");
+ }
+
+ /**
+ * Adds build method's implementation for class.
+ *
+ * @return build method implementation for class
+ * @throws IOException when fails to append to temporary file
+ */
+ public String addBuildMethodImpl()
+ throws IOException {
+ if (getBeanTempFiles() != null) {
+ return getBeanTempFiles().addBuildMethodImpl();
+ }
+
+ throw new TranslatorException("build should not be added");
+ }
+
+ /**
+ * 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
+ */
+ public void freeTemporaryResources(boolean isErrorOccurred)
+ throws IOException {
+
+ if (getBeanTempFiles() != null) {
+ getBeanTempFiles().freeTemporaryResources(isErrorOccurred);
+ }
+
+ if (getTypeTempFiles() != null) {
+ getTypeTempFiles().freeTemporaryResources(isErrorOccurred);
+ }
+
+ if (getEnumerationTempFiles() != null) {
+ getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
+ }
+
+ if (getServiceTempFiles() != null) {
+ getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
+ }
+
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java
new file mode 100644
index 0000000..1bbf349
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Represents Has temporary file handle.
+ */
+public interface TempJavaCodeFragmentFilesContainer {
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles();
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle);
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
new file mode 100644
index 0000000..2ab6f9d
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
@@ -0,0 +1,316 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangEnum;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+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;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPrefixForIdentifier;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
+
+/**
+ * Represents implementation of java code fragments temporary implementations.
+ * Maintains the temp files required specific for enumeration java snippet generation.
+ */
+public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
+
+ /**
+ * File name for temporary enum class.
+ */
+ private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
+
+ /**
+ * File name for enum class file name suffix.
+ */
+ private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
+
+ /**
+ * Current enum's value.
+ */
+ private int enumValue;
+
+ /**
+ * Contains data of enumSet.
+ */
+ private Map<String, Integer> enumStringMap = new HashMap<>();
+
+ /**
+ * Contains data of enumSet.
+ */
+ private List<String> enumStringList;
+
+ /**
+ * Temporary file handle for enum class file.
+ */
+ private File enumClassTempFileHandle;
+
+ /**
+ * Java file handle for enum class.
+ */
+ private File enumClassJavaFileHandle;
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file info
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+
+ super(javaFileInfo);
+ setEnumSetJavaMap(new HashMap<>());
+ setEnumStringList(new ArrayList<>());
+ /*
+ * Initialize enum when generation file type matches to enum class mask.
+ */
+ addGeneratedTempFile(ENUM_IMPL_MASK);
+ setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
+ }
+
+ /**
+ * Returns enum class java file handle.
+ *
+ * @return enum class java file handle
+ */
+ public File getEnumClassJavaFileHandle() {
+ return enumClassJavaFileHandle;
+ }
+
+ /**
+ * Sets enum class java file handle.
+ *
+ * @param enumClassJavaFileHandle enum class java file handle
+ */
+ private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
+ this.enumClassJavaFileHandle = enumClassJavaFileHandle;
+ }
+
+ /**
+ * Returns enum's value.
+ *
+ * @return enum's value
+ */
+ private int getEnumValue() {
+ return enumValue;
+ }
+
+ /**
+ * Sets enum's value.
+ *
+ * @param enumValue enum's value
+ */
+ private void setEnumValue(int enumValue) {
+ this.enumValue = enumValue;
+ }
+
+ /**
+ * Returns enum set java map.
+ *
+ * @return the enum set java map
+ */
+ public Map<String, Integer> getEnumSetJavaMap() {
+ return enumStringMap;
+ }
+
+ /**
+ * Sets enum set java map.
+ *
+ * @param map the enum set java map to set
+ */
+ private void setEnumSetJavaMap(Map<String, Integer> map) {
+ this.enumStringMap = map;
+ }
+
+ /**
+ * Returns temporary file handle for enum class file.
+ *
+ * @return temporary file handle for enum class file
+ */
+ public File getEnumClassTempFileHandle() {
+ return enumClassTempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle for enum class file.
+ *
+ * @param enumClassTempFileHandle temporary file handle for enum class file
+ */
+ private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
+ this.enumClassTempFileHandle = enumClassTempFileHandle;
+ }
+
+ /**
+ * Adds enum class attributes to temporary file.
+ *
+ * @param curEnumName current YANG enum
+ * @throws IOException when fails to do IO operations.
+ */
+ 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, YangPluginConfig pluginConfig) throws IOException {
+
+ super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
+ if (curNode instanceof YangEnumeration) {
+ YangEnumeration enumeration = (YangEnumeration) curNode;
+ for (YangEnum curEnum : enumeration.getEnumSet()) {
+ String enumName = curEnum.getNamedValue();
+ String prefixForIdentifier = null;
+ if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) {
+ prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver());
+ if (prefixForIdentifier != null) {
+ curEnum.setNamedValue(prefixForIdentifier + enumName);
+ } else {
+ curEnum.setNamedValue(YANG_AUTO_PREFIX + enumName);
+ }
+ }
+ setEnumValue(curEnum.getValue());
+ addToEnumStringList(curEnum.getNamedValue());
+ addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue());
+ addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue(), pluginConfig);
+ }
+ } else {
+ throw new TranslatorException("current node should be of enumeration type.");
+ }
+ }
+
+ /**
+ * Returns java attribute for enum class.
+ *
+ * @param pluginConfig plugin configurations
+ * @return java attribute
+ */
+ public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
+ YangJavaType<?> javaType = new YangJavaType<>();
+ javaType.setDataType(YangDataTypes.INT32);
+ javaType.setDataTypeName("int");
+ javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
+ return getAttributeInfoForTheData(
+ javaType.getJavaQualifiedInfo(),
+ javaType.getDataTypeName(), javaType,
+ getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
+ false);
+ }
+
+ /**
+ * Adds current enum name to java list.
+ *
+ * @param curEnumName current enum name
+ */
+ private void addToEnumSetJavaMap(String curEnumName, int value) {
+ getEnumSetJavaMap().put(getEnumJavaAttribute(curEnumName).toUpperCase(), value);
+ }
+
+ /**
+ * Adds the new attribute info to the target generated temporary files.
+ *
+ * @param curEnumName the attribute name that needs to be added to temporary
+ * files
+ * @throws IOException IO operation fail
+ */
+ void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
+ throws IOException {
+ addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig);
+ }
+
+ /**
+ * 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);
+ setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
+ setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
+ 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 {
+ closeFile(getEnumClassJavaFileHandle(), isErrorOccurred);
+ closeFile(getEnumClassTempFileHandle(), true);
+ super.freeTemporaryResources(isErrorOccurred);
+ }
+
+ /**
+ * Adds to enum string list.
+ *
+ * @param curEnumValue current enum value
+ */
+ private void addToEnumStringList(String curEnumValue) {
+ getEnumStringList().add(getEnumJavaAttribute(curEnumValue).toUpperCase());
+ }
+
+ /**
+ * Returns enum string list.
+ *
+ * @return the enumStringList
+ */
+ public List<String> getEnumStringList() {
+ return enumStringList;
+ }
+
+ /**
+ * Sets enum string list.
+ *
+ * @param enumStringList the enumStringList to set
+ */
+ public void setEnumStringList(List<String> enumStringList) {
+ this.enumStringList = enumStringList;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
new file mode 100644
index 0000000..3c35a71
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -0,0 +1,1663 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_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.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_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;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
+import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.updateJavaFileInfo;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
+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.getPackageDirPathFromJavaJPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+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.INTERFACE;
+import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
+import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
+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.OF_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
+
+/**
+ * Represents implementation of java code fragments temporary implementations.
+ * Manages the common temp file required for Java file(s) generated.
+ */
+public class TempJavaFragmentFiles {
+
+ /**
+ * Information about the java files being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * Imported class info.
+ */
+ private JavaImportData javaImportData;
+
+ /**
+ * The variable which guides the types of temporary files generated using
+ * the temporary generated file types mask.
+ */
+ private int generatedTempFiles;
+
+ /**
+ * Absolute path where the target java file needs to be generated.
+ */
+ private String absoluteDirPath;
+
+ /**
+ * Contains all the interface(s)/class name which will be extended by generated files.
+ */
+ private JavaExtendsListHolder javaExtendsListHolder;
+
+ /**
+ * File type extension for java classes.
+ */
+ private static final String JAVA_FILE_EXTENSION = ".java";
+
+ /**
+ * File type extension for temporary classes.
+ */
+ private static final String TEMP_FILE_EXTENSION = ".tmp";
+
+ /**
+ * Folder suffix for temporary files folder.
+ */
+ private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
+
+ /**
+ * File name for getter method.
+ */
+ private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
+
+ /**
+ * File name for setter method.
+ */
+ private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
+
+ /**
+ * File name for getter method implementation.
+ */
+ private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
+
+ /**
+ * File name for setter method implementation.
+ */
+ private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
+
+ /**
+ * File name for attributes.
+ */
+ private static final String ATTRIBUTE_FILE_NAME = "Attributes";
+
+ /**
+ * File name for to string method.
+ */
+ private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
+
+ /**
+ * File name for hash code method.
+ */
+ private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
+
+ /**
+ * File name for equals method.
+ */
+ private static final String EQUALS_METHOD_FILE_NAME = "Equals";
+
+ /**
+ * File name for from string method.
+ */
+ private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
+
+ /**
+ * File name for interface java file name suffix.
+ */
+ private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
+
+ /**
+ * File name for builder interface file name suffix.
+ */
+ private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
+
+ /**
+ * File name for builder class file name suffix.
+ */
+ private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
+
+ /**
+ * File name for impl class file name suffix.
+ */
+ private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
+
+ /**
+ * Java file handle for interface file.
+ */
+ private File interfaceJavaFileHandle;
+
+ /**
+ * Java file handle for builder interface file.
+ */
+ private File builderInterfaceJavaFileHandle;
+
+ /**
+ * Java file handle for builder class file.
+ */
+ private File builderClassJavaFileHandle;
+
+ /**
+ * Java file handle for impl class file.
+ */
+ private File implClassJavaFileHandle;
+
+ /**
+ * Temporary file handle for attribute.
+ */
+ private File attributesTempFileHandle;
+
+ /**
+ * Temporary file handle for getter of interface.
+ */
+ private File getterInterfaceTempFileHandle;
+
+ /**
+ * Temporary file handle for setter of interface.
+ */
+ private File setterInterfaceTempFileHandle;
+
+ /**
+ * Temporary file handle for getter of class.
+ */
+ private File getterImplTempFileHandle;
+
+ /**
+ * Temporary file handle for setter of class.
+ */
+ private File setterImplTempFileHandle;
+
+ /**
+ * Temporary file handle for hash code method of class.
+ */
+ private File hashCodeImplTempFileHandle;
+
+ /**
+ * Temporary file handle for equals method of class.
+ */
+ private File equalsImplTempFileHandle;
+
+ /**
+ * Temporary file handle for to string method of class.
+ */
+ private File toStringImplTempFileHandle;
+
+ /**
+ * Temporary file handle for from string method of class.
+ */
+ private File fromStringImplTempFileHandle;
+
+ /**
+ * Import info for case.
+ */
+ private JavaQualifiedTypeInfo caseImportInfo;
+
+ /**
+ * Is attribute added.
+ */
+ private boolean isAttributePresent;
+
+ /**
+ * Retrieves the absolute path where the file needs to be generated.
+ *
+ * @return absolute path where the file needs to be generated
+ */
+ private String getAbsoluteDirPath() {
+ return absoluteDirPath;
+ }
+
+ /**
+ * Sets absolute path where the file needs to be generated.
+ *
+ * @param absoluteDirPath absolute path where the file needs to be
+ * generated.
+ */
+ void setAbsoluteDirPath(String absoluteDirPath) {
+ this.absoluteDirPath = absoluteDirPath;
+ }
+
+ /**
+ * Sets the generated java file information.
+ *
+ * @param javaFileInfo generated java file information
+ */
+ public void setJavaFileInfo(JavaFileInfo javaFileInfo) {
+ this.javaFileInfo = javaFileInfo;
+ }
+
+ /**
+ * Retrieves the generated java file information.
+ *
+ * @return generated java file information
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ /**
+ * Retrieves the generated temp files.
+ *
+ * @return generated temp files
+ */
+ int getGeneratedTempFiles() {
+ return generatedTempFiles;
+ }
+
+ /**
+ * Clears the generated file mask.
+ */
+ void clearGeneratedTempFileMask() {
+ generatedTempFiles = 0;
+ }
+
+ /**
+ * Adds to generated temporary files.
+ *
+ * @param generatedTempFile generated file
+ */
+ void addGeneratedTempFile(int generatedTempFile) {
+ generatedTempFiles |= generatedTempFile;
+ setGeneratedTempFiles(generatedTempFiles);
+ }
+
+ /**
+ * Sets generated file files.
+ *
+ * @param fileType generated file type
+ */
+ void setGeneratedTempFiles(int fileType) {
+ generatedTempFiles = fileType;
+ }
+
+ /**
+ * Retrieves the generated Java files.
+ *
+ * @return generated Java files
+ */
+ int getGeneratedJavaFiles() {
+ return getJavaFileInfo().getGeneratedFileTypes();
+ }
+
+ /**
+ * Retrieves the mapped Java class name.
+ *
+ * @return mapped Java class name
+ */
+ String getGeneratedJavaClassName() {
+ return getCapitalCase(getJavaFileInfo().getJavaName());
+ }
+
+ /**
+ * Retrieves the import data for the generated Java file.
+ *
+ * @return import data for the generated Java file
+ */
+ public JavaImportData getJavaImportData() {
+ return javaImportData;
+ }
+
+ /**
+ * Sets import data for the generated Java file.
+ *
+ * @param javaImportData import data for the generated Java file
+ */
+ void setJavaImportData(JavaImportData javaImportData) {
+ this.javaImportData = javaImportData;
+ }
+
+ /**
+ * Retrieves the status of any attributes added.
+ *
+ * @return status of any attributes added
+ */
+ public boolean isAttributePresent() {
+ return isAttributePresent;
+ }
+
+ /**
+ * Sets status of any attributes added.
+ *
+ * @param attributePresent status of any attributes added
+ */
+ public void setAttributePresent(boolean attributePresent) {
+ isAttributePresent = attributePresent;
+ }
+
+ /**
+ * Returns getter methods's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getGetterInterfaceTempFileHandle() {
+ return getterInterfaceTempFileHandle;
+ }
+
+ /**
+ * Sets to getter method's temporary file handle.
+ *
+ * @param getterForInterface file handle for to getter method
+ */
+ private void setGetterInterfaceTempFileHandle(File getterForInterface) {
+ getterInterfaceTempFileHandle = getterForInterface;
+ }
+
+ /**
+ * Returns setter method's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getSetterInterfaceTempFileHandle() {
+ return setterInterfaceTempFileHandle;
+ }
+
+ /**
+ * Sets to setter method's temporary file handle.
+ *
+ * @param setterForInterface file handle for to setter method
+ */
+ private void setSetterInterfaceTempFileHandle(File setterForInterface) {
+ setterInterfaceTempFileHandle = setterForInterface;
+ }
+
+ /**
+ * Returns setter method's impl's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getSetterImplTempFileHandle() {
+ return setterImplTempFileHandle;
+ }
+
+ /**
+ * Sets to setter method's impl's temporary file handle.
+ *
+ * @param setterImpl file handle for to setter method's implementation class
+ */
+ private void setSetterImplTempFileHandle(File setterImpl) {
+ setterImplTempFileHandle = setterImpl;
+ }
+
+ /**
+ * Returns from string method's temporary file handle.
+ *
+ * @return from string method's temporary file handle
+ */
+ public File getFromStringImplTempFileHandle() {
+ return fromStringImplTempFileHandle;
+ }
+
+ /**
+ * Sets from string method's temporary file handle.
+ *
+ * @param fromStringImplTempFileHandle from string method's temporary file
+ * handle
+ */
+ private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
+ this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
+ }
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file information
+ * @throws IOException when fails to create new file handle
+ */
+ TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
+ setJavaImportData(new JavaImportData());
+ setJavaFileInfo(javaFileInfo);
+ setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
+
+ /*
+ * Initialize getter when generation file type matches to interface
+ * mask.
+ */
+ if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
+ }
+
+ /*
+ * Initialize getter and setter when generation file type matches to
+ * builder interface mask.
+ */
+ if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
+ addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
+ }
+
+ /*
+ * Initialize getterImpl, setterImpl and attributes when generation file
+ * type matches to builder class mask.
+ */
+ if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
+ }
+
+ /*
+ * Initialize getterImpl, attributes, constructor, hash code, equals and
+ * to strings when generation file type matches to impl class mask.
+ */
+ if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(HASH_CODE_IMPL_MASK);
+ addGeneratedTempFile(EQUALS_IMPL_MASK);
+ addGeneratedTempFile(TO_STRING_IMPL_MASK);
+ }
+
+ /*
+ * Initialize temp files to generate type class.
+ */
+ if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(HASH_CODE_IMPL_MASK);
+ addGeneratedTempFile(EQUALS_IMPL_MASK);
+ addGeneratedTempFile(TO_STRING_IMPL_MASK);
+ addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+ }
+
+ /*
+ * Initialize temp files to generate enum class.
+ */
+ if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
+ addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+ }
+ /*
+ * Initialize getter and setter when generation file type matches to
+ * builder interface mask.
+ */
+ if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
+ addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
+ }
+
+ /*
+ * Set temporary file handles.
+ */
+ if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
+ setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
+ setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
+ setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
+ setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
+ setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
+ setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
+ setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
+ setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
+ setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
+ }
+
+ }
+
+ /**
+ * Returns java file handle for interface file.
+ *
+ * @return java file handle for interface file
+ */
+ private File getInterfaceJavaFileHandle() {
+ return interfaceJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for interface file.
+ *
+ * @param interfaceJavaFileHandle java file handle
+ */
+ private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
+ this.interfaceJavaFileHandle = interfaceJavaFileHandle;
+ }
+
+ /**
+ * Returns java file handle for builder interface file.
+ *
+ * @return java file handle for builder interface file
+ */
+ private File getBuilderInterfaceJavaFileHandle() {
+ return builderInterfaceJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for builder interface file.
+ *
+ * @param builderInterfaceJavaFileHandle java file handle
+ */
+ private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
+ this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
+ }
+
+ /**
+ * Returns java file handle for builder class file.
+ *
+ * @return java file handle for builder class file
+ */
+ private File getBuilderClassJavaFileHandle() {
+ return builderClassJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for builder class file.
+ *
+ * @param builderClassJavaFileHandle java file handle
+ */
+ private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
+ this.builderClassJavaFileHandle = builderClassJavaFileHandle;
+ }
+
+ /**
+ * Returns java file handle for impl class file.
+ *
+ * @return java file handle for impl class file
+ */
+ private File getImplClassJavaFileHandle() {
+ return implClassJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for impl class file.
+ *
+ * @param implClassJavaFileHandle java file handle
+ */
+ private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
+ this.implClassJavaFileHandle = implClassJavaFileHandle;
+ }
+
+ /**
+ * Returns attribute's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getAttributesTempFileHandle() {
+ return attributesTempFileHandle;
+ }
+
+ /**
+ * Sets attribute's temporary file handle.
+ *
+ * @param attributeForClass file handle for attribute
+ */
+ void setAttributesTempFileHandle(File attributeForClass) {
+ attributesTempFileHandle = attributeForClass;
+ }
+
+ /**
+ * Returns getter method's impl's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getGetterImplTempFileHandle() {
+ return getterImplTempFileHandle;
+ }
+
+ /**
+ * Sets to getter method's impl's temporary file handle.
+ *
+ * @param getterImpl file handle for to getter method's impl
+ */
+ void setGetterImplTempFileHandle(File getterImpl) {
+ getterImplTempFileHandle = getterImpl;
+ }
+
+ /**
+ * Returns hash code method's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getHashCodeImplTempFileHandle() {
+ return hashCodeImplTempFileHandle;
+ }
+
+ /**
+ * Sets hash code method's temporary file handle.
+ *
+ * @param hashCodeMethod file handle for hash code method
+ */
+ void setHashCodeImplTempFileHandle(File hashCodeMethod) {
+ hashCodeImplTempFileHandle = hashCodeMethod;
+ }
+
+ /**
+ * Returns equals mehtod's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getEqualsImplTempFileHandle() {
+ return equalsImplTempFileHandle;
+ }
+
+ /**
+ * Sets equals method's temporary file handle.
+ *
+ * @param equalsMethod file handle for to equals method
+ */
+ void setEqualsImplTempFileHandle(File equalsMethod) {
+ equalsImplTempFileHandle = equalsMethod;
+ }
+
+ /**
+ * Returns to string method's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getToStringImplTempFileHandle() {
+ return toStringImplTempFileHandle;
+ }
+
+ /**
+ * Sets to string method's temporary file handle.
+ *
+ * @param toStringMethod file handle for to string method
+ */
+ void setToStringImplTempFileHandle(File toStringMethod) {
+ toStringImplTempFileHandle = toStringMethod;
+ }
+
+ /**
+ * Returns java extends list holder.
+ *
+ * @return java extends list holder
+ */
+ public JavaExtendsListHolder getJavaExtendsListHolder() {
+ return javaExtendsListHolder;
+ }
+
+ /**
+ * Sets java extends list holder.
+ *
+ * @param javaExtendsListHolder java extends list holder
+ */
+ public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
+ this.javaExtendsListHolder = javaExtendsListHolder;
+ }
+
+ /**
+ * Adds attribute for class.
+ *
+ * @param attr attribute info
+ * @param yangPluginConfig plugin configurations
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
+ throws IOException {
+ 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getGetterInterfaceTempFileHandle(),
+ 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getSetterInterfaceTempFileHandle(),
+ getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
+ + NEW_LINE);
+ }
+
+ /**
+ * Adds setter's implementation for class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addSetterImpl(JavaAttributeInfo attr)
+ throws IOException {
+ appendToFile(getSetterImplTempFileHandle(),
+ getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
+ +
+ NEW_LINE);
+ }
+
+ /**
+ * 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
+ || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
+ getGeneratedJavaFiles()) + NEW_LINE);
+ } else {
+ appendToFile(getGetterImplTempFileHandle(),
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ }
+ }
+
+ /**
+ * Adds build method for interface.
+ *
+ * @param pluginConfig plugin configurations
+ * @return build method for interface
+ * @throws IOException when fails to append to temporary file
+ */
+ String addBuildMethodForInterface(YangPluginConfig pluginConfig)
+ throws IOException {
+ return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
+ }
+
+ /**
+ * Adds build method's implementation for class.
+ *
+ * @return build method implementation for class
+ * @throws IOException when fails to append to temporary file
+ */
+ String addBuildMethodImpl()
+ throws IOException {
+ return getBuildString(getGeneratedJavaClassName()) + NEW_LINE;
+ }
+
+ /**
+ * Adds default constructor for class.
+ *
+ * @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, YangPluginConfig pluginConfig)
+ throws IOException {
+ 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(YangPluginConfig pluginCnfig)
+ throws IOException {
+ return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig)
+ + getOfMethod(getGeneratedJavaClassName(), null);
+ }
+
+ /**
+ * Adds hash code method for class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addHashCodeMethod(JavaAttributeInfo attr)
+ throws IOException {
+ appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
+ }
+
+ /**
+ * Adds equals method for class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addEqualsMethod(JavaAttributeInfo attr)
+ throws IOException {
+ appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
+ }
+
+ /**
+ * Adds ToString method for class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addToStringMethod(JavaAttributeInfo attr)
+ throws IOException {
+ appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
+ }
+
+ /**
+ * Adds from string method for union class.
+ *
+ * @param javaAttributeInfo type attribute info
+ * @param fromStringAttributeInfo from string attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
+ JavaAttributeInfo fromStringAttributeInfo)
+ throws IOException {
+ appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
+ fromStringAttributeInfo) + NEW_LINE);
+ }
+
+ /**
+ * Returns a temporary file handle for the specific file type.
+ *
+ * @param fileName file name
+ * @return temporary file handle
+ * @throws IOException when fails to create new file handle
+ */
+ File getTemporaryFileHandle(String fileName)
+ throws IOException {
+ String path = getTempDirPath();
+ File dir = new File(path);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ File file = new File(path + fileName + TEMP_FILE_EXTENSION);
+ if (!file.exists()) {
+ file.createNewFile();
+ } else {
+ throw new IOException(fileName + " is reused due to YANG naming");
+ }
+ return file;
+ }
+
+ /**
+ * Returns a temporary file handle for the specific file type.
+ *
+ * @param fileName file name
+ * @return temporary file handle
+ * @throws IOException when fails to create new file handle
+ */
+ File getJavaFileHandle(String fileName)
+ throws IOException {
+ return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
+ }
+
+ /**
+ * Returns data from the temporary files.
+ *
+ * @param file temporary file handle
+ * @return stored data from temporary files
+ * @throws IOException when failed to get data from the given file
+ */
+ public String getTemporaryDataFromFileHandle(File file)
+ throws IOException {
+
+ String path = getTempDirPath();
+ if (new File(path + file.getName()).exists()) {
+ return readAppendFile(path + file.getName(), EMPTY_STRING);
+ } else {
+ throw new IOException("Unable to get data from the given "
+ + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
+ }
+ }
+
+ /**
+ * Returns temporary directory path.
+ *
+ * @return directory path
+ */
+ String getTempDirPath() {
+ return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName()
+ + TEMP_FOLDER_NAME_SUFIX + SLASH;
+ }
+
+ /**
+ * Parses attribute to get the attribute string.
+ *
+ * @param attr attribute info
+ * @param pluginConfig plugin configurations
+ * @return attribute string
+ */
+ 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(), pluginConfig.getConflictResolver());
+ if (attr.isQualifiedName()) {
+ return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
+ attr.getImportInfo().getClassInfo(),
+ attributeName, attr.isListAttr());
+ } else {
+ return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
+ attr.isListAttr());
+ }
+ }
+
+ /**
+ * Appends content to temporary file.
+ *
+ * @param file temporary file
+ * @param data data to be appended
+ * @throws IOException when fails to append to file
+ */
+ void appendToFile(File file, String data)
+ throws IOException {
+ try {
+ insertDataIntoJavaFile(file, data);
+ } catch (IOException ex) {
+ throw new IOException("failed to write in temp file.");
+ }
+ }
+
+ /**
+ * Adds current node info as and attribute to the parent generated file.
+ *
+ * @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, YangPluginConfig pluginConfig)
+ throws IOException {
+ YangNode parent = getParentNodeInGenCode(curNode);
+ if (!(parent instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("missing parent node to contain current node info in generated file");
+ }
+
+ if (parent instanceof YangJavaGrouping) {
+ /*
+ * In case of grouping, there is no need to add the information, it
+ * will be taken care in uses
+ */
+ return;
+ }
+
+ JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
+ parent, isList);
+ if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("missing parent temp file handle");
+ }
+ getNodesInterfaceFragmentFiles(parent)
+ .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
+ }
+
+ /**
+ * Adds current node info as and attribute to the parent generated file.
+ *
+ * @param curNode current node which needs to be added as an attribute in
+ * the parent generated code
+ * @param pluginConfig plugin configurations
+ * @param targetNode target node to add the attribute
+ * @throws IOException IO operation exception
+ */
+ public static void addCurNodeAsAttributeInTargetTempFile(YangNode curNode,
+ YangPluginConfig pluginConfig, YangNode targetNode)
+ throws IOException {
+
+ if (!(targetNode instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("invalid target node to generated file");
+ }
+
+ if (targetNode instanceof YangJavaGrouping) {
+ /*
+ * In case of grouping, there is no need to add the information, it
+ * will be taken care in uses
+ */
+ return;
+ }
+
+ boolean isList = curNode instanceof YangList;
+
+ JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
+ targetNode, isList);
+ if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("missing target node's temp file handle");
+ }
+ getNodesInterfaceFragmentFiles(targetNode)
+ .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
+ }
+
+ /**
+ * Creates an attribute info object corresponding to a data model node and
+ * return it.
+ *
+ * @param curNode current data model node for which the java code generation
+ * is being handled
+ * @param targetNode target node in which the current node is an attribute
+ * @param isListNode is the current added attribute needs to be a list
+ * @return AttributeInfo attribute details required to add in temporary
+ * files
+ */
+ public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
+ YangNode targetNode, boolean isListNode) {
+ String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ if (curNodeName == null) {
+ updateJavaFileInfo(curNode, null);
+ curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ }
+
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
+ getCapitalCase(curNodeName));
+ if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("Parent node does not have file info");
+ }
+ TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(targetNode);
+ JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
+
+ boolean isQualified;
+ if ((targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule)
+ && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
+
+ isQualified = true;
+ } else {
+ String className;
+ if (targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule) {
+ className = getCapitalCase(fileInfo.getJavaName()) + "Service";
+ } else {
+ className = getCapitalCase(fileInfo.getJavaName());
+ }
+
+ isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
+ className, fileInfo.getPackage());
+ }
+
+ if (isListNode) {
+ parentImportData.setIfListImported(true);
+ }
+
+ return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
+ }
+
+ /**
+ * Resolves groupings java qualified info.
+ *
+ * @param curNode grouping node
+ * @param pluginConfig plugin configurations
+ * @return groupings java qualified info
+ */
+ public static JavaQualifiedTypeInfo resolveGroupingsQuailifiedInfo(YangNode curNode,
+ YangPluginConfig pluginConfig) {
+
+ JavaFileInfo groupingFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
+ if (groupingFileInfo.getPackage() == null) {
+ List<String> parentNames = new ArrayList<>();
+
+ YangNode tempNode = curNode.getParent();
+ YangNode groupingSuperParent = null;
+ while (tempNode != null) {
+ parentNames.add(tempNode.getName());
+ groupingSuperParent = tempNode;
+ tempNode = tempNode.getParent();
+ }
+
+ String pkg = null;
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) groupingSuperParent).getJavaFileInfo();
+ if (parentInfo.getPackage() == null) {
+ if (groupingSuperParent instanceof YangJavaModule) {
+ YangJavaModule module = (YangJavaModule) groupingSuperParent;
+ String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
+ .getRevision().getRevDate(), pluginConfig.getConflictResolver());
+ pkg = modulePkg;
+ } else if (groupingSuperParent instanceof YangJavaSubModule) {
+ YangJavaSubModule submodule = (YangJavaSubModule) groupingSuperParent;
+ String subModulePkg = getRootPackage(submodule.getVersion(),
+ submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
+ submodule.getRevision().getRevDate(), pluginConfig.getConflictResolver());
+ pkg = subModulePkg;
+ }
+ } else {
+ pkg = parentInfo.getPackage();
+ }
+ for (String name : parentNames) {
+ pkg = pkg + PERIOD + getCamelCase(name, pluginConfig.getConflictResolver());
+ }
+
+ qualifiedTypeInfo.setPkgInfo(pkg.toLowerCase());
+ qualifiedTypeInfo.setClassInfo(
+ getCapitalCase(getCamelCase(curNode.getName(), pluginConfig.getConflictResolver())));
+ return qualifiedTypeInfo;
+
+ } else {
+ qualifiedTypeInfo.setPkgInfo(groupingFileInfo.getPackage().toLowerCase());
+ qualifiedTypeInfo.setClassInfo(getCapitalCase(groupingFileInfo.getJavaName()));
+ return qualifiedTypeInfo;
+ }
+ }
+
+ /**
+ * Returns interface fragment files for node.
+ *
+ * @param node YANG node
+ * @return interface fragment files for node
+ */
+ public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) {
+ TempJavaFragmentFiles tempJavaFragmentFiles;
+ if (node instanceof RpcNotificationContainer) {
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+ } else {
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles();
+ }
+ return tempJavaFragmentFiles;
+ }
+
+ /**
+ * 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, YangPluginConfig pluginConfig) {
+ caseImportInfo = new JavaQualifiedTypeInfo();
+ YangNode parent = getParentNodeInGenCode(curNode);
+ if (!(parent instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("missing parent node to contain current node info in generated file");
+ }
+ if (!(curNode instanceof JavaFileInfoContainer)) {
+ throw new TranslatorException("missing java file information to get the package details "
+ + "of attribute corresponding to child node");
+ }
+ caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
+ pluginConfig.getConflictResolver())));
+ caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
+
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
+ getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
+ }
+
+ /**
+ * Adds leaf attributes in generated files.
+ *
+ * @param listOfLeaves list of YANG leaf
+ * @param yangPluginConfig plugin config
+ * @throws IOException IO operation fail
+ */
+ public void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (listOfLeaves != null) {
+ for (YangLeaf leaf : listOfLeaves) {
+ if (!(leaf instanceof JavaLeafInfoContainer)) {
+ throw new TranslatorException("Leaf does not have java information");
+ }
+ JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
+ javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
+ javaLeaf.updateJavaQualifiedInfo();
+ JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
+ javaLeaf.getJavaQualifiedInfo(),
+ javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
+ javaLeaf.getDataType(),
+ getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
+ false);
+ addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
+ }
+ }
+ }
+
+ /**
+ * Adds leaf list's attributes in generated files.
+ *
+ * @param listOfLeafList list of YANG leaves
+ * @param yangPluginConfig plugin config
+ * @throws IOException IO operation fail
+ */
+ public void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (listOfLeafList != null) {
+ for (YangLeafList leafList : listOfLeafList) {
+ if (!(leafList instanceof JavaLeafInfoContainer)) {
+ 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(
+ javaLeaf.getJavaQualifiedInfo(),
+ javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
+ javaLeaf.getDataType(),
+ getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
+ true);
+ addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
+ }
+ }
+ }
+
+ /**
+ * Adds all the leaves in the current data model node as part of the
+ * generated temporary file.
+ *
+ * @param curNode java file info of the generated file
+ * @param yangPluginConfig plugin config
+ * @throws IOException IO operation fail
+ */
+ public void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (!(curNode instanceof YangLeavesHolder)) {
+ throw new TranslatorException("Data model node does not have any leaves");
+ }
+ YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
+ addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig);
+ addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig);
+ }
+
+ /**
+ * Adds the new attribute info to the target generated temporary files.
+ *
+ * @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, YangPluginConfig pluginConfig)
+ throws IOException {
+ setAttributePresent(true);
+ if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
+ addAttribute(newAttrInfo, pluginConfig);
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
+ addGetterForInterface(newAttrInfo, pluginConfig);
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
+ addSetterForInterface(newAttrInfo, pluginConfig);
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
+ addSetterImpl(newAttrInfo);
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
+ addGetterImpl(newAttrInfo, pluginConfig);
+ }
+ if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
+ addHashCodeMethod(newAttrInfo);
+ }
+ if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
+ addEqualsMethod(newAttrInfo);
+ }
+ if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
+ addToStringMethod(newAttrInfo);
+ }
+
+ if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
+ JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
+ pluginConfig.getConflictResolver());
+ /*
+ * Create a new java attribute info with qualified information of
+ * wrapper classes.
+ */
+ JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
+ newAttrInfo.getAttributeName(),
+ newAttrInfo.getAttributeType(),
+ getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
+
+ addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
+ }
+ }
+
+ /**
+ * Returns java class name.
+ *
+ * @param suffix for the class name based on the file type
+ * @return java class name
+ */
+ String getJavaClassName(String suffix) {
+ return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
+ }
+
+ /**
+ * Returns the directory path.
+ *
+ * @return directory path
+ */
+ private String getDirPath() {
+ return getJavaFileInfo().getPackageFilePath();
+ }
+
+ /**
+ * Constructs java code exit.
+ *
+ * @param fileType generated file type
+ * @param curNode current YANG node
+ * @throws IOException when fails to generate java files
+ */
+ public void generateJavaFile(int fileType, YangNode curNode)
+ throws IOException {
+ List<String> imports = new ArrayList<>();
+ imports = getJavaImportData().getImports();
+
+ createPackage(curNode);
+
+ /*
+ * Generate java code.
+ */
+ if ((fileType & INTERFACE_MASK) != 0 || (fileType &
+ BUILDER_INTERFACE_MASK) != 0) {
+
+ /*
+ * Create interface file.
+ */
+ setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
+ setInterfaceJavaFileHandle(
+ generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
+ /*
+ * Create builder interface file.
+ */
+ if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
+ setBuilderInterfaceJavaFileHandle(
+ getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
+ setBuilderInterfaceJavaFileHandle(
+ generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
+ isAttributePresent()));
+ /*
+ * Append builder interface file to interface file and close it.
+ */
+ mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
+ validateLineLength(getInterfaceJavaFileHandle());
+ }
+ insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentationHoldersImport(curNode, imports, false);
+ }
+ if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentedInfoImport(curNode, imports, false);
+ }
+ if (curNode instanceof YangCase) {
+ removeCaseImport(imports);
+ }
+ }
+ if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
+ if (isAttributePresent()) {
+ addImportsToStringAndHasCodeMethods(curNode, imports);
+ }
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentedInfoImport(curNode, imports, true);
+ addArrayListImport(curNode, imports, true);
+ }
+ sortImports(imports);
+ /*
+ * Create builder class file.
+ */
+ setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
+ setBuilderClassJavaFileHandle(
+ generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode,
+ isAttributePresent()));
+ /*
+ * Create impl class file.
+ */
+ if ((fileType & IMPL_CLASS_MASK) != 0) {
+ setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
+ setImplClassJavaFileHandle(
+ generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent()));
+ /*
+ * Append impl class to builder class and close it.
+ */
+ mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
+ validateLineLength(getBuilderClassJavaFileHandle());
+ }
+ insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentedInfoImport(curNode, imports, false);
+ addArrayListImport(curNode, imports, false);
+ }
+ }
+ /*
+ * Close all the file handles.
+ */
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Adds imports for ToString and HashCodeMethod.
+ *
+ * @param curNode current YANG node
+ * @param imports import list
+ * @return import list
+ */
+ public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
+ imports.add(getJavaImportData().getImportForHashAndEquals());
+ imports.add(getJavaImportData().getImportForToString());
+ return imports;
+ }
+
+ /**
+ * Removes case import info from import list.
+ *
+ * @param imports list of imports
+ * @return import for class
+ */
+ private List<String> removeCaseImport(List<String> imports) {
+ if (imports != null && caseImportInfo != null) {
+ String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
+ SEMI_COLAN + NEW_LINE;
+ imports.remove(caseImport);
+ }
+ return imports;
+ }
+
+ /**
+ * 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
+ */
+ public void freeTemporaryResources(boolean isErrorOccurred)
+ throws IOException {
+ boolean isError = isErrorOccurred;
+ /*
+ * Close all java file handles and when error occurs delete the files.
+ */
+ if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
+ closeFile(getInterfaceJavaFileHandle(), isError);
+ }
+ if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
+ closeFile(getBuilderClassJavaFileHandle(), isError);
+ }
+ if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
+ closeFile(getBuilderInterfaceJavaFileHandle(), true);
+ }
+ if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
+ closeFile(getImplClassJavaFileHandle(), true);
+ }
+
+ /*
+ * Close all temporary file handles and delete the files.
+ */
+ if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
+ closeFile(getGetterImplTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
+ closeFile(getAttributesTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
+ closeFile(getHashCodeImplTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
+ closeFile(getToStringImplTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
+ closeFile(getEqualsImplTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
+ closeFile(getFromStringImplTempFileHandle(), true);
+ }
+ }
+
+ /**
+ * Returns if the attribute needs to be accessed in a qualified manner or
+ * not, if it needs to be imported, then the same needs to be done.
+ *
+ * @param importInfo import info for the current attribute being added
+ * @return status of the qualified access to the attribute
+ */
+ public boolean getIsQualifiedAccessOrAddToImportList(
+ JavaQualifiedTypeInfo importInfo) {
+
+ return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(),
+ getJavaFileInfo().getPackage());
+ }
+
+ /**
+ * Checks if the import info is same as the package of the current generated
+ * java file.
+ *
+ * @param importInfo import info for an attribute
+ * @return true if the import info is same as the current nodes package
+ * false otherwise
+ */
+ public boolean isImportPkgEqualCurNodePkg(JavaQualifiedTypeInfo importInfo) {
+ return getJavaFileInfo().getPackage()
+ .contentEquals(importInfo.getPkgInfo());
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
new file mode 100644
index 0000000..0d6215e
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -0,0 +1,802 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+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.getEnumJavaAttribute;
+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;
+
+/**
+ * Represents implementation of java service code fragments temporary implementations.
+ * Maintains the temp files required specific for service and manager java snippet generation.
+ */
+public class TempJavaServiceFragmentFiles
+ extends TempJavaFragmentFiles {
+
+ /**
+ * File name for rpc method.
+ */
+ private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
+
+ /**
+ * File name for rpc implementation method.
+ */
+ 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.
+ */
+ private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
+
+ /**
+ * File name for generated class file for manager
+ * suffix.
+ */
+ 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;
+
+ /**
+ * Temporary file handle for rpc manager impl.
+ */
+ private File rpcImplTempFileHandle;
+
+ /**
+ * Java file handle for rpc interface file.
+ */
+ private File serviceInterfaceJavaFileHandle;
+
+ /**
+ * Java file handle for manager impl file.
+ */
+ 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
+ */
+ private File getServiceInterfaceJavaFileHandle() {
+ return serviceInterfaceJavaFileHandle;
+ }
+
+ /**
+ * Sets rpc method's java file handle.
+ *
+ * @param serviceInterfaceJavaFileHandle file handle for to rpc method
+ */
+ private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) {
+ this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle;
+ }
+
+ /**
+ * Returns managers java file handle.
+ *
+ * @return java file handle
+ */
+ public File getManagerJavaFileHandle() {
+ return managerJavaFileHandle;
+ }
+
+ /**
+ * Sets manager java file handle.
+ *
+ * @param managerJavaFileHandle file handle for to manager
+ */
+ public void setManagerJavaFileHandle(File managerJavaFileHandle) {
+ this.managerJavaFileHandle = managerJavaFileHandle;
+ }
+
+ /**
+ * Returns rpc method's temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ public File getRpcInterfaceTempFileHandle() {
+ return rpcInterfaceTempFileHandle;
+ }
+
+ /**
+ * Sets rpc method's temporary file handle.
+ *
+ * @param rpcInterfaceTempFileHandle file handle for to rpc method
+ */
+ private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) {
+ this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle;
+ }
+
+ /**
+ * Retrieves the manager impl temp file.
+ *
+ * @return the manager impl temp file
+ */
+ public File getRpcImplTempFileHandle() {
+ return rpcImplTempFileHandle;
+ }
+
+ /**
+ * Sets the manager impl temp file.
+ *
+ * @param rpcImplTempFileHandle the manager impl temp file
+ */
+ public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
+ this.rpcImplTempFileHandle = rpcImplTempFileHandle;
+ }
+
+ /**
+ * 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
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+ 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));
+ }
+
+ /**
+ * 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 {
+ List<String> imports = getJavaImportData().getImports();
+
+ createPackage(curNode);
+
+ boolean isNotification = false;
+ if (curNode instanceof YangJavaModule) {
+ if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) {
+ isNotification = true;
+ }
+ } else if (curNode instanceof YangJavaSubModule) {
+ if (!((YangJavaSubModule) curNode).getNotificationNodes().isEmpty()) {
+ isNotification = true;
+ }
+ }
+
+ if (isNotification) {
+ addListnersImport(curNode, imports, true, LISTENER_SERVICE);
+ }
+ /**
+ * Creates rpc interface file.
+ */
+ setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
+ generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
+
+ if (isNotification) {
+ addListnersImport(curNode, imports, false, LISTENER_SERVICE);
+ addListnersImport(curNode, imports, true, LISTENER_REG);
+ }
+ addAnnotationsImports(imports, true);
+ /**
+ * Create builder class file.
+ */
+ setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
+ generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
+
+ insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
+ 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.
+ */
+ freeTemporaryResources(false);
+ }
+
+ /**
+ * Adds rpc string information to applicable temp file.
+ *
+ * @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, YangPluginConfig pluginConfig,
+ String rpcName)
+ throws IOException {
+ String rpcInput = EMPTY_STRING;
+ String rpcOutput = VOID;
+ String rpcInputJavaDoc = EMPTY_STRING;
+ if (javaAttributeInfoOfInput != null) {
+ rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName());
+ }
+ if (javaAttributeInfoOfOutput != null) {
+ rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName());
+ }
+ if (!rpcInput.equals(EMPTY_STRING)) {
+ rpcInputJavaDoc = RPC_INPUT_VAR_NAME;
+ }
+ appendToFile(getRpcInterfaceTempFileHandle(),
+ generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig)
+ + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
+ appendToFile(getRpcImplTempFileHandle(),
+ getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
+ }
+
+ /**
+ * Adds the JAVA rpc snippet information.
+ *
+ * @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, YangPluginConfig pluginConfig,
+ String rpcName)
+ throws IOException {
+ 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);
+ }
+
+ /**
+ * 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;
+
+ 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);
+ closeFile(getSetterInterfaceTempFileHandle(), true);
+ closeFile(getSetterImplTempFileHandle(), true);
+
+ 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()));
+ String notificationName = ((YangNotification) curNode).getName();
+
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
+ getCapitalCase(currentInfo));
+
+ JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
+ null, false, false);
+
+ /*Adds java info for event in respective temp files.*/
+ addEventEnum(notificationName, 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
+ + getEnumJavaAttribute(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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
new file mode 100644
index 0000000..930b6b4
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -0,0 +1,353 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangType;
+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.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
+
+/**
+ * Represents implementation of java data type code fragments temporary implementations.
+ * Maintains the temp files required specific for user defined data type java snippet generation.
+ */
+public class TempJavaTypeFragmentFiles
+ extends TempJavaFragmentFiles {
+
+ /**
+ * File name for of string method.
+ */
+ private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
+
+ /**
+ * File name for construction for special type like union, typedef.
+ */
+ private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
+
+ /**
+ * File name for typedef class file name suffix.
+ */
+ private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
+
+ /**
+ * File name for generated class file for special type like union, typedef
+ * suffix.
+ */
+ private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
+
+ /**
+ * Temporary file handle for of string method of class.
+ */
+ private File ofStringImplTempFileHandle;
+
+ /**
+ * Temporary file handle for constructor for type class.
+ */
+ private File constructorForTypeTempFileHandle;
+
+ /**
+ * Java file handle for typedef class file.
+ */
+ private File typedefClassJavaFileHandle;
+
+ /**
+ * Java file handle for type class like union, typedef file.
+ */
+ private File typeClassJavaFileHandle;
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file info
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaTypeFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+
+ super(javaFileInfo);
+
+ /*
+ * Initialize getterImpl, attributes, hash code, equals and to strings
+ * when generation file type matches to typeDef class mask.
+ */
+ addGeneratedTempFile(OF_STRING_IMPL_MASK);
+ addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK);
+ addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+
+ setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
+ setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
+
+ }
+
+ /**
+ * Returns type class constructor method's temporary file handle.
+ *
+ * @return type class constructor method's temporary file handle
+ */
+
+ public File getConstructorForTypeTempFileHandle() {
+ return constructorForTypeTempFileHandle;
+ }
+
+ /**
+ * Sets type class constructor method's temporary file handle.
+ *
+ * @param constructorForTypeTempFileHandle type class constructor method's
+ * temporary file handle
+ */
+ private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) {
+ this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle;
+ }
+
+ /**
+ * Returns java file handle for typedef class file.
+ *
+ * @return java file handle for typedef class file
+ */
+ File getTypedefClassJavaFileHandle() {
+ return typedefClassJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for typedef class file.
+ *
+ * @param typedefClassJavaFileHandle java file handle
+ */
+ private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
+ this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
+ }
+
+ /**
+ * Returns java file handle for type class file.
+ *
+ * @return java file handle for type class file
+ */
+ File getTypeClassJavaFileHandle() {
+ return typeClassJavaFileHandle;
+ }
+
+ /**
+ * Sets the java file handle for type class file.
+ *
+ * @param typeClassJavaFileHandle type file handle
+ */
+ private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
+ this.typeClassJavaFileHandle = typeClassJavaFileHandle;
+ }
+
+ /**
+ * Returns of string method's temporary file handle.
+ *
+ * @return of string method's temporary file handle
+ */
+
+ public File getOfStringImplTempFileHandle() {
+ return ofStringImplTempFileHandle;
+ }
+
+ /**
+ * Set of string method's temporary file handle.
+ *
+ * @param ofStringImplTempFileHandle of string method's temporary file
+ * handle
+ */
+ private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) {
+ this.ofStringImplTempFileHandle = ofStringImplTempFileHandle;
+ }
+
+ /**
+ * Adds all the type in the current data model node as part of the generated
+ * temporary file.
+ *
+ * @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, YangPluginConfig pluginConfig)
+ throws IOException {
+
+ List<YangType<?>> typeList = yangTypeHolder.getTypeList();
+ if (typeList != null) {
+ for (YangType<?> yangType : typeList) {
+ if (!(yangType instanceof YangJavaType)) {
+ throw new TranslatorException("Type does not have Java info");
+ }
+ YangJavaType<?> javaType = (YangJavaType<?>) yangType;
+ javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
+ String typeName = javaType.getDataTypeName();
+ typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
+ JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
+ javaType.getJavaQualifiedInfo(),
+ typeName, javaType,
+ getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
+ false);
+ addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo,
+ pluginConfig);
+ }
+ }
+ }
+
+ /**
+ * Adds the new attribute info to the target generated temporary files for
+ * union class.
+ *
+ * @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,
+ YangPluginConfig pluginConfig)
+ throws IOException {
+
+ super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
+
+ if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
+ addOfStringMethod(javaAttributeInfo, pluginConfig);
+ }
+ if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
+ addTypeConstructor(javaAttributeInfo, pluginConfig);
+ }
+ }
+
+ /**
+ * 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
+ 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, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
+ getGeneratedJavaClassName(), pluginConfig)
+ + NEW_LINE);
+ }
+
+ /**
+ * 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;
+
+ if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0) {
+ closeFile(getTypedefClassJavaFileHandle(), isError);
+ }
+
+ if ((getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
+ closeFile(getTypeClassJavaFileHandle(), isError);
+ }
+
+ if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
+ closeFile(getConstructorForTypeTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
+ closeFile(getOfStringImplTempFileHandle(), true);
+ }
+ if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
+ closeFile(getFromStringImplTempFileHandle(), true);
+ }
+
+ super.freeTemporaryResources(isErrorOccurred);
+
+ }
+
+ /**
+ * 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 {
+ List<String> imports = new ArrayList<>();
+ if (isAttributePresent()) {
+ imports = getJavaImportData().getImports();
+ }
+
+ createPackage(curNode);
+
+ /*
+ * Creates type def class file.
+ */
+ if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
+ addImportsToStringAndHasCodeMethods(curNode, imports);
+ setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
+ generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
+ }
+ /*
+ * Creates type class file.
+ */
+ if ((fileType & GENERATE_UNION_CLASS) != 0) {
+ addImportsToStringAndHasCodeMethods(curNode, imports);
+ setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
+ generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
+ }
+
+ /*
+ * Close all the file handles.
+ */
+ freeTemporaryResources(false);
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TraversalType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TraversalType.java
new file mode 100644
index 0000000..dd7db35
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TraversalType.java
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+/**
+ * Represents data model tree traversal types.
+ */
+public enum TraversalType {
+
+ /**
+ * Start of traversal at the tree root.
+ */
+ ROOT,
+
+ /**
+ * Child node traversal.
+ */
+ CHILD,
+
+ /**
+ * Sibling node traversal.
+ */
+ SIBILING,
+
+ /**
+ * Parent node traversal.
+ */
+ PARENT
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
new file mode 100644
index 0000000..4d68fe2
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
@@ -0,0 +1,409 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNotification;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangRpc;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUnion;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
+
+/**
+ * Represents factory to create data model objects based on the target file type.
+ */
+public final class YangDataModelFactory {
+
+ /**
+ * Creates a YANG data model factory object.
+ */
+ private YangDataModelFactory() {
+ }
+
+ /**
+ * Based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaModule();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaAugment();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaCase();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaChoice();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaContainer();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaGrouping();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaList();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaSubModule();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaTypeDef();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaUnion();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaUses();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaNotification();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaLeaf();
+ }
+ default: {
+ throw new RuntimeException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangLeafList getYangLeafList(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaLeafList();
+ }
+ default: {
+ throw new RuntimeException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaRpc();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaInput();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaOutput();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaEnumeration();
+ }
+ default: {
+ throw new TranslatorException("Only YANG to Java is supported.");
+ }
+ }
+ }
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
+ public static YangType getYangType(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaType();
+ }
+ default: {
+ throw new RuntimeException("Only YANG to Java is supported.");
+ }
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaCodeGeneratorInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaCodeGeneratorInfo.java
new file mode 100644
index 0000000..8dc0db5
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaCodeGeneratorInfo.java
@@ -0,0 +1,30 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+
+/**
+ * Represents YANG java info containing interface for java code generator, java
+ * file information, java import data and temp java code fragment files. This
+ * interface serves as a generic interface and help to unify the generate code
+ * entry function.
+ */
+public interface JavaCodeGeneratorInfo
+ extends JavaFileInfoContainer, TempJavaCodeFragmentFilesContainer {
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
new file mode 100644
index 0000000..3722ad3
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
@@ -0,0 +1,75 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
+
+/**
+ * Represent java based identification of the YANG leaves.
+ */
+public interface JavaLeafInfoContainer
+ extends JavaQualifiedTypeInfoContainer {
+ /**
+ * Retreives the data type of the leaf.
+ *
+ * @return data type of the leaf
+ */
+ YangType<?> getDataType();
+
+ /**
+ * Retreives the name of the leaf.
+ *
+ * @return name of the leaf
+ */
+ String getName();
+
+ /**
+ * Retreives the java name of the leaf.
+ *
+ * @param conflictResolveConfig user config to resolve conflicts
+ * @return name of the leaf
+ */
+ String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig);
+
+ /**
+ * Identifies if object is a leaf-list.
+ *
+ * @return true if leaf-list false otherwise
+ */
+ boolean isLeafList();
+
+ /**
+ * 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
new file mode 100644
index 0000000..5b1e7c5
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
@@ -0,0 +1,33 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
+
+/**
+ * Represent java based identification of the YANG leaves.
+ */
+public interface JavaQualifiedTypeResolver
+ extends JavaQualifiedTypeInfoContainer {
+
+ /**
+ * updates the qualified access details of the type.
+ *
+ * @param confilictResolver plugin configurations
+ */
+ void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver);
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
new file mode 100644
index 0000000..6ac0fb7
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
@@ -0,0 +1,132 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangAugment;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
+
+/**
+ * Represents augment information extended to support java code generation.
+ */
+public class YangJavaAugment
+ extends YangAugment
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201632L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates a YANG java augment object.
+ */
+ public YangJavaAugment() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * augment info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for augmentable node " + getName());
+ }
+ }
+
+ /**
+ * Create a java file using the YANG augment info.
+ *
+ * @throws TranslatorException when failed to do translator operations
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for augmentable node " + getName());
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
new file mode 100644
index 0000000..ba7bd01
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -0,0 +1,130 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangCase;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
+
+/**
+ * Represents case information extended to support java code generation.
+ */
+public class YangJavaCase
+ extends YangCase
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201631L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java case object.
+ */
+ public YangJavaCase() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * case info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for case node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG case info.
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for case node " + getName());
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
new file mode 100644
index 0000000..4096972
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -0,0 +1,130 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangChoice;
+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.INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
+
+/**
+ * Represents choice information extended to support java code generation.
+ */
+public class YangJavaChoice
+ extends YangChoice
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201631L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java choice object.
+ */
+ public YangJavaChoice() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(INTERFACE_MASK);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * choice info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, false);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for choice node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG choice info.
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for choice node " + getName());
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
new file mode 100644
index 0000000..c056632
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
@@ -0,0 +1,133 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangContainer;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
+
+/**
+ * Represents container information extended to support java code generation.
+ */
+public class YangJavaContainer
+ extends YangContainer
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201630L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java container object.
+ */
+ public YangJavaContainer() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * container info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, false);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for container node " + getName());
+ }
+ }
+
+ /**
+ * Create a java file using the YANG container info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for container node " + getName());
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
new file mode 100644
index 0000000..16cabc2
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
@@ -0,0 +1,135 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+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_ENUM_CLASS;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
+
+/**
+ * Represents YANG java enumeration information extended to support java code generation.
+ */
+public class YangJavaEnumeration
+ extends YangEnumeration
+ implements JavaCodeGenerator, JavaCodeGeneratorInfo {
+
+ private static final long serialVersionUID = 806201629L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java enumeration object.
+ */
+ public YangJavaEnumeration() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * enumeration info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operations fails
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for enumeration node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG enumeration info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for enumeration node " + getName());
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
new file mode 100644
index 0000000..8a90a44
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
@@ -0,0 +1,118 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangGrouping;
+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.utils.YangJavaModelUtils.updatePackageInfo;
+
+/**
+ * Represents grouping information extended to support java code generation.
+ */
+public class YangJavaGrouping
+ extends YangGrouping
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201628L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG Java grouping object.
+ */
+ public YangJavaGrouping() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException {
+ try {
+ updatePackageInfo(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(e.getCause());
+ }
+ }
+
+ @Override
+ public void generateCodeExit()
+ throws TranslatorException {
+ /*
+ * Do nothing.
+ */
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
new file mode 100644
index 0000000..db59174
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
@@ -0,0 +1,134 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangInput;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
+
+/**
+ * Represents input information extended to support java code generation.
+ */
+public class YangJavaInput
+ extends YangInput
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201627L;
+
+ /**
+ * Contains information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates an instance of java input.
+ */
+ public YangJavaInput() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * input info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for input node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG input info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for input node " + getName());
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
new file mode 100644
index 0000000..9f39dce
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
@@ -0,0 +1,91 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
+
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.updateLeavesJavaQualifiedInfo;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+
+/**
+ * Represents java information corresponding to the YANG leaf.
+ */
+public class YangJavaLeaf
+ extends YangLeaf
+ implements JavaLeafInfoContainer {
+
+ private static final long serialVersionUID = 806201636L;
+
+ private JavaQualifiedTypeInfo javaQualifiedAccess;
+ private transient YangToJavaNamingConflictUtil conflictResolveConfig;
+
+ /**
+ * Returns a new YANG leaf object with java qualified access details.
+ */
+ public YangJavaLeaf() {
+ super();
+ setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
+ }
+
+ @Override
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedAccess;
+ }
+
+ @Override
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
+ javaQualifiedAccess = typeInfo;
+
+ }
+
+ @Override
+ public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
+ return getCamelCase(getName(), conflictResolveConfig);
+ }
+
+ @Override
+ public boolean isLeafList() {
+ return false;
+ }
+
+ @Override
+ public void updateJavaQualifiedInfo() {
+ updateLeavesJavaQualifiedInfo(this);
+ }
+
+ /**
+ * 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java
new file mode 100644
index 0000000..91c550f
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafList.java
@@ -0,0 +1,89 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
+
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.updateLeavesJavaQualifiedInfo;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+
+/**
+ * Represents java information corresponding to the YANG leaf-list.
+ */
+public class YangJavaLeafList
+ extends YangLeafList
+ implements JavaLeafInfoContainer {
+
+ private static final long serialVersionUID = 806201638L;
+
+ private JavaQualifiedTypeInfo javaQualifiedAccess;
+ private transient YangToJavaNamingConflictUtil conflictResolveConfig;
+
+ /**
+ * Returns a new YANG leaf object with java qualified access details.
+ */
+ public YangJavaLeafList() {
+ super();
+ setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
+ }
+
+ @Override
+ public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
+ return getCamelCase(getName(), conflictResolveConfig);
+ }
+
+ @Override
+ public boolean isLeafList() {
+ return true;
+ }
+
+ @Override
+ public void updateJavaQualifiedInfo() {
+ updateLeavesJavaQualifiedInfo(this);
+ }
+
+ @Override
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedAccess;
+ }
+
+ @Override
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
new file mode 100644
index 0000000..6f08b5d
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
@@ -0,0 +1,132 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangList;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
+
+/**
+ * Represents YANG list information extended to support java code generation.
+ */
+public class YangJavaList
+ extends YangList
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201626L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java list object.
+ */
+ public YangJavaList() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * list info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, true);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for list node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG list info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for list node " + getName());
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
new file mode 100644
index 0000000..1413f9c
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -0,0 +1,212 @@
+/*
+ * 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.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;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
+
+/**
+ * Represents module information extended to support java code generation.
+ */
+public class YangJavaModule
+ extends YangModule
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201625L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * List of notifications nodes.
+ */
+ private List<YangNode> notificationNodes;
+
+ /**
+ * Creates a YANG node of module type.
+ */
+ public YangJavaModule() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ 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);
+
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Generates java code for module.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to generate the source files
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate(),
+ yangPlugin.getConflictResolver());
+ try {
+ generateCodeOfRootNode(this, yangPlugin, modulePkg);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for module node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG module info.
+ */
+ @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() +
+ getJavaFileInfo().getPackageFilePath());
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for module node " + 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
new file mode 100644
index 0000000..68f8164
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -0,0 +1,176 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+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.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
+
+/**
+ * Represents notification information extended to support java code generation.
+ */
+public class YangJavaNotification
+ extends YangNotification
+ implements JavaCodeGenerator, JavaCodeGeneratorInfo {
+
+ private static final long serialVersionUID = 806201624L;
+
+ /**
+ * Contains information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates an instance of java Notification.
+ */
+ public YangJavaNotification() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * notification info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) 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.
+ */
+
+ // Generate subject of the notification(event), this is simple interface
+ // with builder class.
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ addNotificationToExtendsList();
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for notification node " + getName());
+ }
+ }
+
+ /*Adds current notification info to the extends list so its parents service*/
+ private void addNotificationToExtendsList() {
+ YangNode parent = getParent();
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles().getJavaExtendsListHolder();
+ JavaQualifiedTypeInfo event = new JavaQualifiedTypeInfo();
+
+ String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
+ .getJavaFileInfo().getJavaName());
+ event.setClassInfo(parentInfo + EVENT_STRING);
+ event.setPkgInfo(getJavaFileInfo().getPackage());
+ holder.addToExtendsList(event, parent);
+
+ JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo();
+
+ eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
+ eventListener.setPkgInfo(getJavaFileInfo().getPackage());
+ holder.addToExtendsList(eventListener, parent);
+
+ }
+
+ /**
+ * Creates a java file using the YANG notification info.
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for notification node " + getName());
+ }
+
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
new file mode 100644
index 0000000..dda3fc9
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
@@ -0,0 +1,136 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangOutput;
+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_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
+
+/**
+ * Represents output information extended to support java code generation.
+ */
+public class YangJavaOutput
+ extends YangOutput
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201623L;
+
+ /**
+ * Contains information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates an instance of java output.
+ */
+ public YangJavaOutput() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * output info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for output node " + getName());
+ }
+
+ }
+
+ /**
+ * Creates a java file using the YANG output info.
+ *
+ * @throws TranslatorException translator operation fail
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code exit for output node " + getName());
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
new file mode 100644
index 0000000..f3730a2
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -0,0 +1,254 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangRpc;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
+import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
+import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
+import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
+
+/**
+ * Represents rpc information extended to support java code generation.
+ */
+public class YangJavaRpc
+ extends YangRpc
+ implements JavaCodeGenerator, JavaCodeGeneratorInfo {
+
+ private static final long serialVersionUID = 806201622L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * Temproary file for code generation.
+ */
+ private transient TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
+
+ /**
+ * Creates an instance of YANG java rpc.
+ */
+ public YangJavaRpc() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new TranslatorException("missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempJavaCodeFragmentFiles;
+ }
+
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempJavaCodeFragmentFiles = fileHandle;
+ }
+
+ /**
+ * Prepares the information for java code generation corresponding to YANG
+ * RPC info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException translator operations fails
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException {
+
+ // Add package information for rpc and create corresponding folder.
+ try {
+ updatePackageInfo(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to prepare generate code entry for RPC node " + getName());
+ }
+ }
+
+ /**
+ * Creates a java file using the YANG RPC info.
+ *
+ * @throws TranslatorException translator operations fails
+ */
+ @Override
+ public void generateCodeExit()
+ throws TranslatorException {
+ // Get the parent module/sub-module.
+ YangNode parent = getParentNodeInGenCode(this);
+
+ // Parent should be holder of rpc or notification.
+ if (!(parent instanceof RpcNotificationContainer)) {
+ throw new TranslatorException("parent node of rpc can only be module or sub-module");
+ }
+
+ /*
+ * Create attribute info for input and output of rpc and add it to the
+ * parent import list.
+ */
+
+ JavaAttributeInfo javaAttributeInfoOfInput = null;
+ JavaAttributeInfo javaAttributeInfoOfOutput = null;
+
+ // Get the child input and output node and obtain create java attribute
+ // info.
+ YangNode yangNode = getChild();
+ while (yangNode != null) {
+ if (yangNode instanceof YangInput) {
+ javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this);
+
+ } else if (yangNode instanceof YangOutput) {
+ javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this);
+ } else {
+ throw new TranslatorException("RPC should contain only input/output child nodes.");
+ }
+ yangNode = yangNode.getNextSibling();
+ }
+
+ if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("missing parent temp file handle");
+ }
+
+ /*
+ * Add the rpc information to the parent's service temp file.
+ */
+ try {
+
+ ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
+ ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(), getName());
+
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for RPC node " + getName());
+ }
+ // No file will be generated during RPC exit.
+ }
+
+ /**
+ * Creates an attribute info object corresponding to a data model node and
+ * return it.
+ *
+ * @param childNode child data model node(input / output) for which the java code generation
+ * is being handled
+ * @param currentNode parent node (module / sub-module) in which the child node is an attribute
+ * @return AttributeInfo attribute details required to add in temporary
+ * files
+ */
+ public JavaAttributeInfo getChildNodeAsAttributeInParentService(
+ YangNode childNode, YangNode currentNode) {
+
+ YangNode parentNode = getParentNodeInGenCode(currentNode);
+
+ String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(childNode,
+ getCapitalCase(childNodeName));
+ if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("Parent node does not have file info");
+ }
+
+ TempJavaFragmentFiles tempJavaFragmentFiles;
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+
+ if (tempJavaFragmentFiles == null) {
+ throw new TranslatorException("Parent node does not have service file info");
+ }
+ boolean isQualified = addImportToService(qualifiedTypeInfo);
+ return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
+ }
+
+ /**
+ * Adds to service class import list.
+ *
+ * @param importInfo import info
+ * @return true or false
+ */
+ private boolean addImportToService(JavaQualifiedTypeInfo importInfo) {
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) getParent()).getJavaFileInfo();
+
+ if (importInfo.getClassInfo().contentEquals(SERVICE)
+ || importInfo.getClassInfo().contentEquals(COMPONENT)
+ || importInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
+ || importInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
+ || importInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
+ || importInfo.getClassInfo().contentEquals(REFERENCE)
+ || importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
+ || importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
+ return true;
+ }
+
+ String className;
+ className = getCapitalCase(fileInfo.getJavaName()) + "Service";
+
+ return ((TempJavaCodeFragmentFilesContainer) getParent()).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles().getJavaImportData().addImportInfo(importInfo,
+ className, fileInfo.getPackage());
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
new file mode 100644
index 0000000..d838682
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -0,0 +1,216 @@
+/*
+ * 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.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;
+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;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
+
+/**
+ * Represents sub module information extended to support java code generation.
+ */
+public class YangJavaSubModule
+ extends YangSubModule
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201621L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * List of notifications nodes.
+ */
+ private List<YangNode> notificationNodes = new ArrayList<>();
+
+ /**
+ * Creates YANG java sub module object.
+ */
+ public YangJavaSubModule() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ 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);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Returns the name space of the module to which the sub module belongs to.
+ *
+ * @param belongsToInfo Information of the module to which the sub module
+ * belongs
+ * @return the name space string of the module.
+ */
+ public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
+ return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace().getUri();
+ }
+
+ /**
+ * Prepares the information for java code generation corresponding to YANG
+ * submodule info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to translate
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
+ getRevision().getRevDate(), yangPlugin.getConflictResolver());
+ try {
+ generateCodeOfRootNode(this, yangPlugin, subModulePkg);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "failed to prepare generate code entry for submodule node " + getName());
+ }
+
+ }
+
+ /**
+ * Creates a java file using the YANG submodule info.
+ */
+ @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() +
+ getJavaFileInfo().getPackageFilePath());
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for submodule node " + 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
new file mode 100644
index 0000000..e537743
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
@@ -0,0 +1,86 @@
+/*
+ * 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.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangType;
+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.
+ *
+ * @param <T> generic parameter for YANG java type
+ */
+public class YangJavaType<T>
+ extends YangType<T>
+ implements JavaQualifiedTypeResolver {
+
+ private JavaQualifiedTypeInfo javaQualifiedAccess;
+
+ /**
+ * Create a YANG leaf object with java qualified access details.
+ */
+ public YangJavaType() {
+ super();
+ setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
+ }
+
+ @Override
+ public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil conflictResolver) {
+ JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
+
+ /*
+ * Type is added as an attribute in the class.
+ */
+ String className = AttributesJavaDataType.getJavaImportClass(this, false, conflictResolver);
+ if (className != null) {
+ /*
+ * Corresponding to the attribute type a class needs to be imported,
+ * since it can be a derived type or a usage of wrapper classes.
+ */
+ importInfo.setClassInfo(className);
+ String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
+ false, conflictResolver);
+ if (classPkg == null) {
+ throw new TranslatorException("import package cannot be null when the class is used");
+ }
+ importInfo.setPkgInfo(classPkg);
+ } else {
+ /*
+ * The attribute does not need a class to be imported, for example
+ * built in java types.
+ */
+ String dataTypeName = AttributesJavaDataType.getJavaDataType(this);
+ if (dataTypeName == null) {
+ throw new TranslatorException("not supported data type");
+ }
+ importInfo.setClassInfo(dataTypeName);
+ }
+ setJavaQualifiedInfo(importInfo);
+ }
+
+ @Override
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedAccess;
+ }
+
+ @Override
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
+ javaQualifiedAccess = typeInfo;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
new file mode 100644
index 0000000..0124510
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
@@ -0,0 +1,135 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+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_TYPEDEF_CLASS;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
+
+/**
+ * Represents type define information extended to support java code generation.
+ */
+public class YangJavaTypeDef
+ extends YangTypeDef
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201620L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates a YANG java typedef object.
+ */
+ public YangJavaTypeDef() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_TYPEDEF_CLASS);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * typedef info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to translate
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for typedef node " + getName());
+ }
+
+ }
+
+ /**
+ * Create a java file using the YANG typedef info.
+ *
+ * @throws TranslatorException when fails to translate
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for typedef node " + getName());
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
new file mode 100644
index 0000000..eac8e52
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
@@ -0,0 +1,133 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.YangUnion;
+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_UNION_CLASS;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
+
+/**
+ * Represents union information extended to support java code generation.
+ */
+public class YangJavaUnion
+ extends YangUnion
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201619L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates an instance of YANG java union.
+ */
+ public YangJavaUnion() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ getJavaFileInfo().setGeneratedFileTypes(GENERATE_UNION_CLASS);
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new RuntimeException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ /**
+ * Prepare the information for java code generation corresponding to YANG
+ * union info.
+ *
+ * @param yangPlugin YANG plugin config
+ * @throws TranslatorException when fails to translate
+ */
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for union node " + getName());
+ }
+
+ }
+
+ /**
+ * Creates a java file using the YANG union info.
+ *
+ * @throws TranslatorException when fails to translate
+ */
+ @Override
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for union node " + getName());
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
new file mode 100644
index 0000000..f6166a5
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
@@ -0,0 +1,155 @@
+/*
+ * 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.javamodel;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangUses;
+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.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeAsAttributeInTargetTempFile;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
+
+/**
+ * Represents uses information extended to support java code generation.
+ */
+public class YangJavaUses
+ extends YangUses
+ implements JavaCodeGeneratorInfo, JavaCodeGenerator {
+
+ private static final long serialVersionUID = 806201618L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
+ */
+ private transient TempJavaCodeFragmentFiles tempFileHandle;
+
+ /**
+ * Creates YANG java uses object.
+ */
+ public YangJavaUses() {
+ super();
+ setJavaFileInfo(new JavaFileInfo());
+ }
+
+ /**
+ * Returns the generated java file information.
+ *
+ * @return generated java file information
+ */
+ @Override
+ public JavaFileInfo getJavaFileInfo() {
+ if (javaFileInfo == null) {
+ throw new TranslatorException("Missing java info in java datamodel node");
+ }
+ return javaFileInfo;
+ }
+
+ /**
+ * Sets the java file info object.
+ *
+ * @param javaInfo java file info object
+ */
+ @Override
+ public void setJavaFileInfo(JavaFileInfo javaInfo) {
+ javaFileInfo = javaInfo;
+ }
+
+ /**
+ * Returns the temporary file handle.
+ *
+ * @return temporary file handle
+ */
+ @Override
+ public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
+ return tempFileHandle;
+ }
+
+ /**
+ * Sets temporary file handle.
+ *
+ * @param fileHandle temporary file handle
+ */
+ @Override
+ public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ tempFileHandle = fileHandle;
+ }
+
+ @Override
+ public void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException {
+ try {
+ updatePackageInfo(this, yangPlugin);
+
+ if (!(getParentNodeInGenCode(this) instanceof JavaCodeGeneratorInfo)) {
+ throw new TranslatorException("invalid container of uses");
+ }
+ JavaCodeGeneratorInfo javaCodeGeneratorInfo = (JavaCodeGeneratorInfo) getParentNodeInGenCode(this);
+
+ if (javaCodeGeneratorInfo instanceof YangGrouping) {
+ /*
+ * Do nothing, since it will taken care in the groupings uses.
+ */
+ return;
+ }
+
+ for (List<YangLeaf> leavesList : getUsesResolvedLeavesList()) {
+ // add the resolved leaves to the parent as an attribute
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles().addLeavesInfoToTempFiles(leavesList, yangPlugin);
+ }
+
+ for (List<YangLeafList> listOfLeafLists : getUsesResolvedListOfLeafList()) {
+ // add the resolved leaf-list to the parent as an attribute
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles().addLeafListInfoToTempFiles(listOfLeafLists, yangPlugin);
+ }
+
+ for (YangNode usesResolvedNode : getUsesResolvedNodeList()) {
+ // add the resolved nodes to the parent as an attribute
+ addCurNodeAsAttributeInTargetTempFile(usesResolvedNode, yangPlugin,
+ getParentNodeInGenCode(this));
+ }
+
+ } catch (IOException e) {
+ throw new TranslatorException(e.getCause());
+ }
+ }
+
+ @Override
+ public void generateCodeExit()
+ throws TranslatorException {
+ /*
+ * Do nothing.
+ */
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java
new file mode 100644
index 0000000..3257922
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Maintains application's schema mapped to java classes / interfaces.
+ */
+package org.onosproject.yangutils.translator.tojava.javamodel;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java
new file mode 100644
index 0000000..1aac09e
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Generates java class definition from data model.
+ */
+package org.onosproject.yangutils.translator.tojava;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
new file mode 100644
index 0000000..19ed11d
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
@@ -0,0 +1,506 @@
+/*
+ * 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.utils;
+
+import java.util.Stack;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUnion;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+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 org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
+
+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.getCurNodePackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
+import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
+import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
+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.
+ */
+public final class AttributesJavaDataType {
+
+ /**
+ * Creates an instance of attribute java data type.
+ */
+ private AttributesJavaDataType() {
+ }
+
+ /**
+ * Returns java type.
+ *
+ * @param yangType YANG type
+ * @return java type
+ */
+ public static String getJavaDataType(YangType<?> yangType) {
+
+ YangDataTypes type = yangType.getDataType();
+
+ switch (type) {
+ case INT8:
+ return BYTE;
+ case INT16:
+ return SHORT;
+ case INT32:
+ return INT;
+ case INT64:
+ return LONG;
+ case UINT8:
+ return SHORT;
+ case UINT16:
+ return INT;
+ case UINT32:
+ return LONG;
+ case UINT64:
+ return BIG_INTEGER;
+ case BINARY:
+ return YANG_BINARY_CLASS;
+ case DECIMAL64:
+ return YANG_DECIMAL64_CLASS;
+ case STRING:
+ return STRING_DATA_TYPE;
+ case BOOLEAN:
+ return BOOLEAN_DATA_TYPE;
+ default:
+ throw new TranslatorException("given data type is not supported.");
+ }
+ }
+
+ /**
+ * Returns from string method parsed string.
+ *
+ * @param targetDataType target data type
+ * @param yangType YANG type
+ * @return parsed string
+ */
+ public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
+
+ YangDataTypes type = yangType.getDataType();
+
+ switch (type) {
+ case INT8:
+ return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
+ case INT16:
+ return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
+ case INT32:
+ return INTEGER_WRAPPER + PERIOD + PARSE_INT;
+ case INT64:
+ return LONG_WRAPPER + PERIOD + PARSE_LONG;
+ case UINT8:
+ return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
+ case UINT16:
+ return INTEGER_WRAPPER + PERIOD + PARSE_INT;
+ case UINT32:
+ return LONG_WRAPPER + PERIOD + PARSE_LONG;
+ case UINT64:
+ return NEW + SPACE + BIG_INTEGER;
+ case STRING:
+ return EMPTY_STRING;
+ case EMPTY:
+ case BOOLEAN:
+ return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
+ case DECIMAL64:
+ case BITS:
+ case BINARY:
+ case UNION:
+ case ENUMERATION:
+ case DERIVED:
+ return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
+ default:
+ throw new TranslatorException("given data type is not supported.");
+ }
+ }
+
+ /**
+ * Returns java import class.
+ *
+ * @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,
+ YangToJavaNamingConflictUtil pluginConfig) {
+
+ YangDataTypes type = yangType.getDataType();
+
+ if (isListAttr) {
+ switch (type) {
+ case INT8:
+ return BYTE_WRAPPER;
+ case INT16:
+ return SHORT_WRAPPER;
+ case INT32:
+ return INTEGER_WRAPPER;
+ case INT64:
+ return LONG_WRAPPER;
+ case UINT8:
+ return SHORT_WRAPPER;
+ case UINT16:
+ return INTEGER_WRAPPER;
+ case UINT32:
+ return LONG_WRAPPER;
+ case UINT64:
+ return BIG_INTEGER;
+ case DECIMAL64:
+ return YANG_DECIMAL64_CLASS;
+ case STRING:
+ return STRING_DATA_TYPE;
+ case BOOLEAN:
+ return BOOLEAN_WRAPPER;
+ case ENUMERATION:
+ return getCapitalCase(
+ getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
+ case BITS:
+ return YANG_BITS_CLASS;
+ case BINARY:
+ return YANG_BINARY_CLASS;
+ case LEAFREF:
+ //TODO:LEAFREF
+ break;
+ case IDENTITYREF:
+ //TODO:IDENTITYREF
+ break;
+ case EMPTY:
+ return BOOLEAN_WRAPPER;
+ case UNION:
+ return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
+ case INSTANCE_IDENTIFIER:
+ //TODO:INSTANCE_IDENTIFIER
+ break;
+ case DERIVED:
+ return getCapitalCase(
+ getCamelCase(yangType.getDataTypeName(), pluginConfig));
+ default:
+ throw new TranslatorException("given data type is not supported.");
+ }
+ } else {
+ switch (type) {
+ case UINT64:
+ return BIG_INTEGER;
+ case DECIMAL64:
+ return YANG_DECIMAL64_CLASS;
+ case STRING:
+ return STRING_DATA_TYPE;
+ case ENUMERATION:
+ return getCapitalCase(
+ getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
+ case BITS:
+ return YANG_BITS_CLASS;
+ case BINARY:
+ return YANG_BINARY_CLASS;
+ case LEAFREF:
+ //TODO:LEAFREF
+ break;
+ case IDENTITYREF:
+ //TODO:IDENTITYREF
+ break;
+ case EMPTY:
+ return BOOLEAN_DATA_TYPE;
+ case UNION:
+ return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
+ pluginConfig));
+ case INSTANCE_IDENTIFIER:
+ //TODO:INSTANCE_IDENTIFIER
+ break;
+ case DERIVED:
+ return getCapitalCase(
+ getCamelCase(yangType.getDataTypeName(), pluginConfig));
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns java import package.
+ *
+ * @param yangType YANG type
+ * @param isListAttr if the attribute is of list type
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return java import package
+ */
+ public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr,
+ YangToJavaNamingConflictUtil conflictResolver) {
+
+ YangDataTypes type = yangType.getDataType();
+
+ if (isListAttr) {
+ switch (type) {
+ case INT8:
+ case INT16:
+ case INT32:
+ case INT64:
+ case UINT8:
+ case UINT16:
+ case UINT32:
+ case STRING:
+ case BOOLEAN:
+ case EMPTY:
+ return JAVA_LANG;
+ case UINT64:
+ return JAVA_MATH;
+ case ENUMERATION:
+ return getEnumsPackage(yangType, conflictResolver);
+ case DECIMAL64:
+ case BITS:
+ case BINARY:
+ return YANG_TYPES_PKG;
+ case LEAFREF:
+ //TODO:LEAFREF
+ break;
+ case IDENTITYREF:
+ //TODO:IDENTITYREF
+ break;
+ case UNION:
+ return getUnionPackage(yangType, conflictResolver);
+ case INSTANCE_IDENTIFIER:
+ //TODO:INSTANCE_IDENTIFIER
+ break;
+ case DERIVED:
+ return getTypDefsPackage(yangType, conflictResolver);
+ default:
+ throw new TranslatorException("given data type is not supported.");
+ }
+ } else {
+ switch (type) {
+ case UINT64:
+ return JAVA_MATH;
+ case STRING:
+ return JAVA_LANG;
+ case ENUMERATION:
+ return getEnumsPackage(yangType, conflictResolver);
+ case DECIMAL64:
+ case BITS:
+ case BINARY:
+ return YANG_TYPES_PKG;
+ case LEAFREF:
+ //TODO:LEAFREF
+ break;
+ case IDENTITYREF:
+ //TODO:IDENTITYREF
+ break;
+ case EMPTY:
+ return JAVA_LANG;
+ case UNION:
+ return getUnionPackage(yangType, conflictResolver);
+ case INSTANCE_IDENTIFIER:
+ //TODO:INSTANCE_IDENTIFIER
+ break;
+ case DERIVED:
+ return getTypDefsPackage(yangType, conflictResolver);
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns java package for typedef node.
+ *
+ * @param type YANG type
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return java package for typedef node
+ */
+ private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
+ Object var = type.getDataTypeExtendedInfo();
+ if (!(var instanceof YangDerivedInfo)) {
+ throw new TranslatorException("type should have been derived.");
+ }
+
+ if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() instanceof YangTypeDef)) {
+ throw new TranslatorException("derived info is not an instance of typedef.");
+ }
+
+ YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef();
+ if (typedef.getJavaFileInfo().getPackage() == null) {
+ return getPackageFromParent(typedef.getParent(), conflictResolver);
+ }
+ return typedef.getJavaFileInfo().getPackage();
+ }
+
+ /**
+ * Returns java package for union node.
+ *
+ * @param type YANG type
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return java package for union node
+ */
+ private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
+
+ if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
+ throw new TranslatorException("type should have been union.");
+ }
+
+ YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo();
+ if (union.getJavaFileInfo().getPackage() == null) {
+ return getPackageFromParent(union.getParent(), conflictResolver);
+ }
+ return union.getJavaFileInfo().getPackage();
+ }
+
+ /**
+ * Returns YANG enumeration's java package.
+ *
+ * @param type YANG type
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return YANG enumeration's java package
+ */
+ private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
+
+ if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
+ throw new TranslatorException("type should have been enumeration.");
+ }
+ YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo();
+ if (enumeration.getJavaFileInfo().getPackage() == null) {
+ return getPackageFromParent(enumeration.getParent(), conflictResolver);
+ }
+ return enumeration.getJavaFileInfo().getPackage();
+ }
+
+ /**
+ * Returns package from parent node.
+ *
+ * @param parent parent YANG node
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return java package from parent node
+ */
+ private static String getPackageFromParent(YangNode parent,
+ YangToJavaNamingConflictUtil conflictResolver) {
+ if (!(parent instanceof JavaFileInfoContainer)) {
+ throw new TranslatorException("invalid child node is being processed.");
+ }
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ if (parentInfo.getPackage() == null) {
+ updateJavaFileInfo(parent, conflictResolver);
+ }
+ return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
+ }
+
+ /**
+ * Update the referred data model nodes java file info, this will be called,
+ * when the linked node is yet to translate. Then resolve until the parent hierarchy.
+ *
+ * @param yangNode node whose java info needs to be updated
+ * @param conflictResolver yang plugin config
+ */
+ public static void updateJavaFileInfo(YangNode yangNode,
+ YangToJavaNamingConflictUtil conflictResolver) {
+ Stack<YangNode> nodesToUpdatePackage = new Stack<YangNode>();
+
+ /*
+ * Add the nodes to be updated for package info in a stack.
+ */
+ while (yangNode != null
+ && ((JavaFileInfoContainer) yangNode)
+ .getJavaFileInfo().getPackage() == null) {
+ nodesToUpdatePackage.push(yangNode);
+ yangNode = yangNode.getParent();
+ }
+
+ /*
+ * If the package is not updated till root node, then root package needs to
+ * be updated.
+ */
+ if (yangNode == null) {
+ yangNode = nodesToUpdatePackage.pop();
+ String pkg;
+ if (yangNode instanceof YangJavaModule) {
+ YangJavaModule module = (YangJavaModule) yangNode;
+ pkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
+ .getRevision().getRevDate(), conflictResolver);
+ } else if (yangNode instanceof YangJavaSubModule) {
+ YangJavaSubModule submodule = (YangJavaSubModule) yangNode;
+ pkg = getRootPackage(submodule.getVersion(),
+ submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
+ submodule.getRevision().getRevDate(), conflictResolver);
+ } else {
+ throw new TranslatorException("Invalid root node of data model tree");
+ }
+
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setJavaName(getCamelCase(yangNode.getName(), conflictResolver));
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setPackage(pkg);
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setPackageFilePath(getPackageDirPathFromJavaJPackage(
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .getPackage()));
+ }
+
+ /**
+ * Parent of the node in stack is updated with java info,
+ * all the nodes can be popped and updated
+ */
+ while (nodesToUpdatePackage.size() != 0) {
+ yangNode = nodesToUpdatePackage.pop();
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setJavaName(getCamelCase(yangNode.getName(), conflictResolver));
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setPackage(getCurNodePackage(yangNode));
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .setPackageFilePath(getPackageDirPathFromJavaJPackage(
+ ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
+ .getPackage()));
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
new file mode 100644
index 0000000..dde4b03
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -0,0 +1,301 @@
+/*
+ * 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.utils;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
+
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
+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.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
+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.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
+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.FINAL;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
+import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
+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.MANAGER;
+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.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
+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;
+
+/**
+ * Represents generator for class definition of generated files.
+ */
+public final class ClassDefinitionGenerator {
+
+ /**
+ * Creates an instance of class definition generator.
+ */
+ private ClassDefinitionGenerator() {
+ }
+
+ /**
+ * Based on the file type and the YANG name of the file, generate the class
+ * / interface definition start.
+ *
+ * @param genFileTypes generated file type
+ * @param yangName class name
+ * @return class definition
+ */
+ public static String generateClassDefinition(int genFileTypes, String yangName) {
+
+ /**
+ * Based on the file type and the YANG name of the file, generate the
+ * class / interface definition start.
+ */
+ switch (genFileTypes) {
+ case BUILDER_CLASS_MASK:
+ return getBuilderClassDefinition(yangName);
+ case IMPL_CLASS_MASK:
+ return getImplClassDefinition(yangName);
+ case BUILDER_INTERFACE_MASK:
+ return getBuilderInterfaceDefinition(yangName);
+ case GENERATE_TYPEDEF_CLASS:
+ case GENERATE_UNION_CLASS:
+ return getTypeClassDefinition(yangName);
+ case GENERATE_ENUM_CLASS:
+ return getEnumClassDefinition(yangName);
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Based on the file type and the YANG name of the file, generate the class
+ * / interface definition start.
+ *
+ * @param genFileTypes generated file type
+ * @param yangName class name
+ * @param curNode current YANG node
+ * @return class definition
+ */
+ public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
+
+ /**
+ * Based on the file type and the YANG name of the file, generate the
+ * class / interface definition start.
+ */
+ switch (genFileTypes) {
+ case INTERFACE_MASK:
+ return getInterfaceDefinition(yangName, curNode);
+ case GENERATE_SERVICE_AND_MANAGER:
+ return getRpcInterfaceDefinition(yangName, curNode);
+ case GENERATE_EVENT_CLASS:
+ 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;
+ }
+ }
+
+ /**
+ * Returns enum file class definition.
+ *
+ * @param yangName class name
+ * @return enum file class definition
+ */
+ private static String getEnumClassDefinition(String yangName) {
+ return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns interface file class definition.
+ *
+ * @param yangName file name
+ * @return definition
+ */
+ private static String getInterfaceDefinition(String yangName, YangNode curNode) {
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
+
+ if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
+ String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
+ for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
+ if (!holder.getExtendedClassStore().get(info)) {
+ def = def + info.getClassInfo() + COMMA + SPACE;
+ } else {
+ def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
+ }
+ }
+
+ def = trimAtLast(def, COMMA);
+
+ return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+ return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns builder interface file class definition.
+ *
+ * @param yangName java class name, corresponding to which the builder class
+ * is being generated
+ * @return definition
+ */
+ private static String getBuilderInterfaceDefinition(String yangName) {
+ return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
+ }
+
+ /**
+ * Returns builder file class definition.
+ *
+ * @param yangName file name
+ * @return definition
+ */
+ private static String getBuilderClassDefinition(String yangName) {
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns impl file class definition.
+ *
+ * @param yangName file name
+ * @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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Returns type file class definition.
+ *
+ * @param yangName file name
+ * @return definition
+ */
+ private static String getTypeClassDefinition(String yangName) {
+ return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns RPC file interface definition.
+ *
+ * @param yangName file name
+ * @param curNode current YANG node
+ * @return definition
+ */
+ private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) {
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder();
+ if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
+ curNode = curNode.getChild();
+ while (curNode != null) {
+ if (curNode instanceof YangJavaNotification) {
+ return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
+ }
+ curNode = curNode.getNextSibling();
+ }
+ }
+ if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
+ return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + IMPLEMENTS + SPACE
+ + yangName.substring(0, yangName.length() - 7) + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /* Provides class definition when RPC interface needs to extends any event.*/
+ private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
+ JavaExtendsListHolder holder) {
+
+ if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
+ String[] strArray = yangName.split(SERVICE);
+ 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;
+ }
+ yangName = yangName.substring(0, yangName.length() - 7);
+ 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 + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns event class definition.
+ *
+ * @param javaName file name
+ * @return definition
+ */
+ private static String getEventDefinition(String javaName, String eventName) {
+ String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
+ + javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+
+ return classDef;
+ }
+
+ /**
+ * Returns event listener interface definition.
+ *
+ * @param javaName file name
+ * @return definition
+ */
+ private static String getEventListenerDefinition(String javaName) {
+ String intfDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
+ + javaName;
+ if (intfDef.length() < 8) {
+ throw new RuntimeException("Event listener interface name is error");
+ }
+ intfDef = intfDef.substring(0, intfDef.length() - 8);
+ intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+
+ return intfDef;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
new file mode 100644
index 0000000..b254e87
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -0,0 +1,157 @@
+/*
+ * 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.utils;
+
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+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.EQUAL;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+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_PARENTHESIS;
+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.SPACE;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
+
+/**
+ * Represents utility class to generate the java snippet.
+ */
+public final class JavaCodeSnippetGen {
+
+ /**
+ * Creates an instance of java code snippet gen.
+ */
+ private JavaCodeSnippetGen() {
+ }
+
+ /**
+ * Returns the java file header comment.
+ *
+ * @return the java file header comment
+ */
+ public static String getFileHeaderComment() {
+
+ /**
+ * TODO return the file header.
+ */
+ return null;
+ }
+
+ /**
+ * Returns the textual java code information corresponding to the import list.
+ *
+ * @param importInfo import info
+ * @return the textual java code information corresponding to the import
+ * list
+ */
+ public static String getImportText(JavaQualifiedTypeInfo importInfo) {
+ return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns the textual java code for attribute definition in class.
+ *
+ * @param javaAttributeTypePkg Package of the attribute type
+ * @param javaAttributeType java attribute type
+ * @param javaAttributeName name of the attribute
+ * @param isList is list attribute
+ * @return the textual java code for attribute definition in class
+ */
+ public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
+ String javaAttributeName, boolean isList) {
+
+ String attributeDefination = PRIVATE + SPACE;
+
+ if (!isList) {
+ if (javaAttributeTypePkg != null) {
+ attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD;
+ }
+
+ attributeDefination = attributeDefination + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
+ + NEW_LINE;
+ } else {
+ attributeDefination = attributeDefination + LIST + DIAMOND_OPEN_BRACKET;
+ if (javaAttributeTypePkg != null) {
+ attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD;
+ }
+
+ attributeDefination = attributeDefination + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE
+ + javaAttributeName + SEMI_COLAN + NEW_LINE;
+ }
+ return attributeDefination;
+ }
+
+ /**
+ * Returns list attribute string.
+ *
+ * @param type attribute type
+ * @return list attribute string
+ */
+ public static String getListAttribute(String type) {
+ return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
+ }
+
+ /**
+ * Returns attribute of augmented info for generated impl file.
+ *
+ * @return attribute of augmented info for generated impl file
+ */
+ public static String getAugmentedInfoAttribute() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
+ + getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
+ + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
+
+ /**
+ * Returns based on the file type and the YANG name of the file, generate the class
+ * / interface definition close.
+ *
+ * @return corresponding textual java code information
+ */
+ public static String getJavaClassDefClose() {
+ return CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns string for enum's attribute.
+ *
+ * @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, 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
new file mode 100644
index 0000000..36986b8
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
+
+/**
+ * Represent the extends list for generated java classes. It holds the class details which needs
+ * to be extended by the generated java code.
+ */
+public class JavaExtendsListHolder {
+
+ /**
+ * Creates an instance of JavaExtendsListHolder.
+ */
+ public JavaExtendsListHolder() {
+ setExtendedClassStore(new HashMap<>());
+ setExtendsList(new ArrayList<>());
+ }
+
+ private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
+ private List<JavaQualifiedTypeInfo> extendsList;
+
+ /**
+ * Returns extends list.
+ *
+ * @return extends list
+ */
+ public Map<JavaQualifiedTypeInfo, Boolean> getExtendedClassStore() {
+ return extendedClassStore;
+ }
+
+ /**
+ * Sets extends list.
+ *
+ * @param extendedClass map of classes need to be extended
+ */
+ private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
+ this.extendedClassStore = extendedClass;
+ }
+
+ /**
+ * Adds to the extends list.
+ *
+ * @param info java file info
+ * @param node YANG node
+ */
+ public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
+
+ JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
+ boolean qualified = importData.addImportInfo(info,
+ getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
+
+ /*true means import should be added*/
+ getExtendedClassStore().put(info, qualified);
+
+ addToExtendsList(info);
+ }
+
+ /**
+ * Returns extends list.
+ *
+ * @return the extendsList
+ */
+ public List<JavaQualifiedTypeInfo> getExtendsList() {
+ return extendsList;
+ }
+
+ /**
+ * Sets extends info list.
+ *
+ * @param classInfoList the extends List to set
+ */
+ private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) {
+ this.extendsList = classInfoList;
+ }
+
+ /**
+ * Adds extends info to list.
+ *
+ * @param classInfo class info
+ */
+ private void addToExtendsList(JavaQualifiedTypeInfo classInfo) {
+ getExtendsList().add(classInfo);
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
new file mode 100644
index 0000000..c082d26
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -0,0 +1,915 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+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;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
+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.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
+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;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_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.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
+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;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
+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;
+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_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.MANAGER;
+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.YangIoUtils.insertDataIntoJavaFile;
+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.
+ */
+public final class JavaFileGenerator {
+
+ private JavaFileGenerator() {
+ }
+
+ /**
+ * Returns generated interface file for current node.
+ *
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param isAttrPresent if any attribute is present or not
+ * @return interface file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode,
+ boolean isAttrPresent)
+ throws IOException {
+
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String className = getCapitalCase(javaFileInfo.getJavaName());
+
+ initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className);
+
+ if (isAttrPresent) {
+ /**
+ * Add getter methods to interface file.
+ */
+ try {
+ /**
+ * Getter methods.
+ */
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while interface file generation");
+ }
+ }
+ return validateLineLength(file);
+ }
+
+ /**
+ * Returns generated builder interface file for current node.
+ *
+ * @param file file
+ * @param curNode current YANG node
+ * @param isAttrPresent if any attribute is present or not
+ * @return builder interface file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateBuilderInterfaceFile(File file, YangNode curNode, boolean isAttrPresent)
+ 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, pluginConfig);
+ List<String> methods = new ArrayList<>();
+ if (isAttrPresent) {
+ try {
+ /**
+ * Getter methods.
+ */
+ methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ /**
+ * Setter methods.
+ */
+ methods.add(NEW_LINE);
+ methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while builder interface file generation");
+ }
+ }
+ /**
+ * Add build method to builder interface file.
+ */
+ methods.add(
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .addBuildMethodForInterface(pluginConfig));
+
+ /**
+ * Add getters and setters in builder interface.
+ */
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+ return validateLineLength(file);
+ }
+
+ /**
+ * Returns generated builder class file for current node.
+ *
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param isAttrPresent if any attribute is present or not
+ * @return builder class file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode,
+ boolean isAttrPresent)
+ 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, pluginConfig);
+
+ List<String> methods = new ArrayList<>();
+
+ if (isAttrPresent) {
+ /**
+ * Add attribute strings.
+ */
+ try {
+ insertDataIntoJavaFile(file,
+ NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while builder class file generation");
+ }
+
+ try {
+ /**
+ * Getter methods.
+ */
+ methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ /**
+ * Setter methods.
+ */
+ methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()) +
+ NEW_LINE);
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while builder class file generation");
+ }
+ } else {
+ insertDataIntoJavaFile(file, NEW_LINE);
+ }
+ /**
+ * Add default constructor and build method impl.
+ */
+ methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .addBuildMethodImpl());
+ methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig));
+
+ /**
+ * Add methods in builder class.
+ */
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+ return validateLineLength(file);
+ }
+
+ /**
+ * Returns generated manager class file for current node.
+ *
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param isAttrPresent if any attribute is present or not
+ * @return builder class file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode,
+ boolean isAttrPresent)
+ throws IOException {
+
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER;
+
+ initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
+
+ List<String> methods = new ArrayList<>();
+
+ insertDataIntoJavaFile(file, LOGGER_STATEMENT);
+ methods.add(addActivateMethod());
+ methods.add(addDeActivateMethod());
+
+ try {
+ if (isAttrPresent) {
+ /**
+ * Getter methods.
+ */
+ methods.add(
+ getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ /**
+ * Setter methods.
+ */
+ methods.add(
+ getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles())
+ + NEW_LINE);
+
+ }
+ if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
+ JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
+ /**
+ * Rpc methods
+ */
+ methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK,
+ javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ }
+ insertDataIntoJavaFile(file, NEW_LINE);
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while manager class file generation");
+ }
+
+ /**
+ * Add methods in builder class.
+ */
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+ return validateLineLength(file);
+ }
+
+ /**
+ * Returns generated impl class file for current node.
+ *
+ * @param file file
+ * @param curNode current YANG node
+ * @param isAttrPresent if any attribute is present or not
+ * @return impl class file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent)
+ 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, pluginConfig);
+
+ List<String> methods = new ArrayList<>();
+
+ TempJavaCodeFragmentFiles javaCodeFragmentFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles();
+ boolean isAugmentationHolderExtended = isAugmentationHolderExtended(
+ javaCodeFragmentFiles.getBeanTempFiles().getJavaExtendsListHolder().getExtendsList());
+ /**
+ * Add attribute for augmented info's list.
+ */
+ if (isAugmentationHolderExtended) {
+ insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
+ }
+ if (isAttrPresent) {
+ /**
+ * Add attribute strings.
+ */
+ try {
+ insertDataIntoJavaFile(file,
+ NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while impl class file generation");
+ }
+
+ insertDataIntoJavaFile(file, NEW_LINE);
+ try {
+ /**
+ * Getter methods.
+ */
+ methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()));
+
+ /**
+ * Hash code method.
+ */
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
+ getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)));
+ /**
+ * Equals method.
+ */
+ methods.add(getEqualsMethodClose(
+ getEqualsMethodOpen(className + IMPL) + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles())));
+ /**
+ * To string method.
+ */
+ methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles())
+ + getToStringMethodClose());
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while impl class file generation");
+ }
+ } else {
+ insertDataIntoJavaFile(file, NEW_LINE);
+ }
+ try {
+
+ /**
+ * Constructor.
+ */
+ 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) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while impl class file generation");
+ }
+
+ /**
+ * Add method for augment info's list.
+ */
+ if (isAugmentationHolderExtended) {
+ methods.add(getAddAugmentInfoMethodImpl());
+ methods.add(getAugmentInfoListImpl());
+ methods.add(getRemoveAugmentationImpl());
+ }
+
+ /**
+ * Add methods in impl class.
+ */
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + method + NEW_LINE);
+ }
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates class file for type def.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @return type def class file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports)
+ 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, pluginConfig);
+
+ List<String> methods = new ArrayList<>();
+
+ /**
+ * Add attribute strings.
+ */
+ try {
+ insertDataIntoJavaFile(file,
+ NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while type def class file generation");
+ }
+
+ /**
+ * Default constructor.
+ */
+ methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
+
+ try {
+
+ /**
+ * Type constructor.
+ */
+ methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Of method.
+ */
+ methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Getter method.
+ */
+ methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Hash code method.
+ */
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
+ getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles())
+ .replace(NEW_LINE, EMPTY_STRING)));
+
+ /**
+ * Equals method.
+ */
+ methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING)
+ + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())));
+
+ /**
+ * To string method.
+ */
+ methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
+ + getToStringMethodClose());
+
+ JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
+ /**
+ * From string method.
+ */
+ methods.add(getFromStringMethodSignature(className, pluginConfig)
+ + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles()) + getFromStringMethodClose());
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while type def class file generation");
+ }
+
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates class file for union type.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @return type def class file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateUnionClassFile(File file, YangNode curNode, List<String> imports)
+ 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, pluginConfig);
+
+ List<String> methods = new ArrayList<>();
+
+ /**
+ * Add attribute strings.
+ */
+ try {
+ insertDataIntoJavaFile(file,
+ NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles()));
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while union class file generation");
+ }
+
+ /**
+ * Default constructor.
+ */
+ methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
+
+ try {
+
+ /**
+ * Type constructor.
+ */
+ methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Of string method.
+ */
+ methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Getter method.
+ */
+ methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+
+ /**
+ * Hash code method.
+ */
+ methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
+ getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles())
+ .replace(NEW_LINE, EMPTY_STRING)));
+
+ /**
+ * Equals method.
+ */
+ methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING)
+ + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())));
+
+ /**
+ * To string method.
+ */
+ methods.add(getToStringMethodOpen() + getOmitNullValueString() +
+ getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles()) + getToStringMethodClose());
+
+ /**
+ * From string method.
+ */
+ methods.add(getFromStringMethodSignature(className, pluginConfig)
+ + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
+ + getFromStringMethodClose());
+
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while union class file generation");
+ }
+
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates class file for type enum.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @return class file for type enum
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateEnumClassFile(File file, YangNode curNode)
+ 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, pluginConfig);
+ /**
+ * Add attribute strings.
+ */
+ try {
+ JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
+ insertDataIntoJavaFile(file,
+ trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, javaGeninfo
+ .getTempJavaCodeFragmentFiles().getEnumerationTempFiles()), COMMA), NEW_LINE)
+ + SEMI_COLAN + NEW_LINE);
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + getCapitalCase(className)
+ + " while enum class file generation");
+ }
+
+ /**
+ * Add an
+ * attribute to get the enum's values.
+ */
+ insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
+
+ /**
+ * Add a constructor for enum.
+ */
+ 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(pluginConfig),
+ enumFragFiles.getEnumSetJavaMap(),
+ enumFragFiles.getEnumStringList(), pluginConfig)
+ + NEW_LINE);
+
+ /**
+ * Add a getter method for enum.
+ */
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig)
+ + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
+
+ try {
+ insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig)
+ + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getEnumerationTempFiles())
+ + getFromStringMethodClose());
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " +
+ getCapitalCase(className) + " while enum class file generation");
+ }
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates interface file for rpc.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @param isAttributePresent is attribute present
+ * @return rpc class file
+ * @throws IOException when fails to generate class file
+ */
+ public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports,
+ boolean isAttributePresent)
+ throws IOException {
+
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
+ initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
+
+ List<String> methods = new ArrayList<>();
+
+ try {
+ if (isAttributePresent) {
+
+ /**
+ * Getter methods.
+ */
+ methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles()));
+ /**
+ * Setter methods.
+ */
+ methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles()));
+ }
+ if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
+ JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
+ /**
+ * Rpc methods
+ */
+ methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK,
+ javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ }
+ } catch (IOException e) {
+ throw new IOException("No data found in temporary java code fragment files for " + className
+ + " while rpc class file generation");
+ }
+
+ for (String method : methods) {
+ insertDataIntoJavaFile(file, method);
+ }
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
+
+ return validateLineLength(file);
+ }
+
+ /**
+ * Generates event file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @throws IOException when fails to generate class file
+ */
+ public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
+
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ + EVENT_STRING;
+
+ TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
+
+ 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);
+ }
+
+ /**
+ * Generates event listener file.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param imports imports for file
+ * @throws IOException when fails to generate class file
+ */
+ public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
+ throws IOException {
+
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ + EVENT_LISTENER_STRING;
+
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
new file mode 100644
index 0000000..c940791
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -0,0 +1,513 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
+import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
+import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
+
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
+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.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
+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;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_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.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
+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.NEW_LINE;
+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.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+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.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.JavaDocGen.getJavaDoc;
+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.
+ */
+public final class JavaFileGeneratorUtils {
+
+ /**
+ * Creates an instance of java file generator util.
+ */
+ private JavaFileGeneratorUtils() {
+ }
+
+ /**
+ * Returns a file object for generated file.
+ *
+ * @param fileName file name
+ * @param filePath file package path
+ * @param extension file extension
+ * @param handle cached file handle
+ * @return file object
+ */
+ public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) {
+
+ return new File(handle.getBaseCodeGenPath() + filePath + SLASH + fileName + extension);
+ }
+
+ /**
+ * Returns data stored in temporary files.
+ *
+ * @param generatedTempFiles temporary file types
+ * @param tempJavaFragmentFiles temp java fragment files
+ * @return data stored in temporary files
+ * @throws IOException when failed to get the data from temporary file handle
+ */
+ public static String getDataFromTempFileHandle(int generatedTempFiles,
+ TempJavaFragmentFiles tempJavaFragmentFiles)
+ throws IOException {
+
+ TempJavaTypeFragmentFiles typeFragmentFiles = null;
+
+ if (tempJavaFragmentFiles instanceof TempJavaTypeFragmentFiles) {
+ typeFragmentFiles = (TempJavaTypeFragmentFiles) tempJavaFragmentFiles;
+ }
+
+ TempJavaBeanFragmentFiles beanFragmentFiles = null;
+
+ if (tempJavaFragmentFiles instanceof TempJavaBeanFragmentFiles) {
+ beanFragmentFiles = (TempJavaBeanFragmentFiles) tempJavaFragmentFiles;
+ }
+
+ TempJavaServiceFragmentFiles serviceFragmentFiles = null;
+ if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
+ serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
+ }
+
+ if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
+ } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle());
+ } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterInterfaceTempFileHandle());
+ } else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterImplTempFileHandle());
+ } else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle());
+ } else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
+ if (beanFragmentFiles == null) {
+ throw new TranslatorException("Required constructor info is missing.");
+ }
+ return beanFragmentFiles
+ .getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle());
+ } else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle());
+ } else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEqualsImplTempFileHandle());
+ } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle());
+ } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
+ if (typeFragmentFiles == null) {
+ throw new TranslatorException("Required of string implementation info is missing.");
+ }
+ return typeFragmentFiles
+ .getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle());
+ } else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
+ if (typeFragmentFiles == null) {
+ throw new TranslatorException("Required constructor implementation info is missing.");
+ }
+ return typeFragmentFiles
+ .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle());
+ } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle());
+ } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
+ if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) {
+ throw new TranslatorException("Required enum info is missing.");
+ }
+ TempJavaEnumerationFragmentFiles enumFragmentFiles =
+ (TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles;
+ return enumFragmentFiles
+ .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle());
+ } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc interface info is missing.");
+ }
+ return serviceFragmentFiles
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle());
+ } else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
+ if (serviceFragmentFiles == null) {
+ throw new TranslatorException("Required rpc implementation info is missing.");
+ }
+ 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;
+ }
+
+ /**
+ * Initiates generation of file based on generated file type.
+ *
+ * @param file generated file
+ * @param className generated file class name
+ * @param genType 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 genType, List<String> imports,
+ String pkg, YangPluginConfig pluginConfig)
+ throws IOException {
+
+ try {
+ file.createNewFile();
+ appendContents(file, className, genType, imports, pkg, pluginConfig);
+ } catch (IOException e) {
+ throw new IOException("Failed to create " + file.getName() + " class file.");
+ }
+ }
+
+ /**
+ * Initiates generation of file based on generated file type.
+ *
+ * @param file generated file
+ * @param genType generated file type
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param className class name
+ * @throws IOException when fails to generate a file
+ */
+ public static void initiateJavaFileGeneration(File file, int genType, List<String> imports,
+ YangNode curNode, String className)
+ throws IOException {
+
+ try {
+ if (file.exists()) {
+ throw new IOException(file.getName() + " is reused due to YANG naming");
+ }
+
+ file.createNewFile();
+ appendContents(file, genType, imports, curNode, className);
+ } catch (IOException e) {
+ throw new IOException("Failed to create " + file.getName() + " class file.");
+ }
+ }
+
+ /**
+ * Appends all the contents into a generated java file.
+ *
+ * @param file generated file
+ * @param genType generated file type
+ * @param importsList list of java imports
+ * @param curNode current YANG node
+ * @param className class name
+ * @throws IOException
+ */
+ private static void appendContents(File file, int genType, List<String> importsList, YangNode curNode,
+ String className)
+ throws IOException {
+
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String name = javaFileInfo.getJavaName();
+ String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
+
+ String pkgString = null;
+ if (genType == GENERATE_EVENT_CLASS
+ || genType == GENERATE_EVENT_LISTENER_INTERFACE
+ || genType == GENERATE_EVENT_SUBJECT_CLASS) {
+ pkgString = parsePackageString((path + PERIOD + name).toLowerCase(), importsList);
+ } else {
+ pkgString = parsePackageString(path, importsList);
+ }
+ switch (genType) {
+ case INTERFACE_MASK:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, INTERFACE, curNode, className);
+ break;
+ case GENERATE_SERVICE_AND_MANAGER:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, RPC_INTERFACE, curNode, className);
+ break;
+ case GENERATE_EVENT_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, EVENT, curNode, className);
+ break;
+ case GENERATE_EVENT_LISTENER_INTERFACE:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, EVENT_LISTENER, curNode, className);
+ break;
+ case GENERATE_EVENT_SUBJECT_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Appends all the contents into a generated java file.
+ *
+ * @param file generated file
+ * @param fileName generated file name
+ * @param genType generated file type
+ * @param importsList list of java imports
+ * @param pkg generated file package
+ * @param pluginConfig plugin configurations
+ * @throws IOException when fails to append contents
+ */
+ private static void appendContents(File file, String fileName, int genType, List<String> importsList, String pkg,
+ YangPluginConfig pluginConfig)
+ throws IOException {
+
+ String pkgString = parsePackageString(pkg, importsList);
+
+ switch (genType) {
+ case IMPL_CLASS_MASK:
+ write(file, fileName, genType, IMPL_CLASS, pluginConfig);
+ break;
+ case BUILDER_INTERFACE_MASK:
+ write(file, fileName, genType, BUILDER_INTERFACE, pluginConfig);
+ break;
+ case GENERATE_TYPEDEF_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, fileName, genType, IMPL_CLASS, pluginConfig);
+ break;
+ case BUILDER_CLASS_MASK:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, fileName, genType, BUILDER_CLASS, pluginConfig);
+ break;
+ case GENERATE_UNION_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, fileName, genType, IMPL_CLASS, pluginConfig);
+ break;
+ case GENERATE_ENUM_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, fileName, genType, ENUM_CLASS, pluginConfig);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Removes base directory path from package and generates package string for file.
+ *
+ * @param javaPkg generated java package
+ * @param importsList list of imports
+ * @return package string
+ */
+ private static String parsePackageString(String javaPkg, List<String> importsList) {
+
+ javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg));
+ if (importsList != null) {
+ if (!importsList.isEmpty()) {
+ return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE;
+ } else {
+ return PACKAGE + SPACE + javaPkg + SEMI_COLAN;
+ }
+ } else {
+ return PACKAGE + SPACE + javaPkg + SEMI_COLAN;
+ }
+ }
+
+ /**
+ * Appends other contents to interface, builder and typedef classes.
+ * for example : ONOS copyright, imports and package.
+ *
+ * @param file generated file
+ * @param pkg generated package
+ * @param importsList list of imports
+ * @throws IOException when fails to append contents
+ */
+ private static void appendHeaderContents(File file, String pkg, List<String> importsList)
+ throws IOException {
+
+ insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader());
+ insertDataIntoJavaFile(file, pkg);
+
+ /*
+ * TODO: add the file header using
+ * JavaCodeSnippetGen.getFileHeaderComment
+ */
+
+ if (importsList != null) {
+ insertDataIntoJavaFile(file, NEW_LINE);
+ for (String imports : importsList) {
+ insertDataIntoJavaFile(file, imports);
+ }
+ }
+ }
+
+ /**
+ * Writes data to the specific generated file.
+ *
+ * @param file generated file
+ * @param genType generated file type
+ * @param javaDocType java doc type
+ * @param curNode current YANG node
+ * @param fileName file name
+ * @throws IOException when fails to write into a file
+ */
+ 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.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
+ insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, addComponentString());
+ } else {
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ }
+ } else {
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ }
+ insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
+ }
+
+ /**
+ * Writes data to the specific generated file.
+ *
+ * @param file generated file
+ * @param fileName file name
+ * @param genType generated file type
+ * @param javaDocType java doc type
+ * @param pluginConfig plugin configurations
+ * @throws IOException when fails to write into a file
+ */
+ private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
+ YangPluginConfig pluginConfig)
+ throws IOException {
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
+ }
+
+ /**
+ * Returns integer attribute for enum's class to get the values.
+ *
+ * @param className enum's class name
+ * @return enum's attribute
+ */
+ public static String getEnumsValueAttribute(String className) {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ + 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
new file mode 100644
index 0000000..95355aa
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -0,0 +1,490 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+
+import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_DIGITS;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
+import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
+import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
+
+/**
+ * Represents an utility Class for translating the name from YANG to java convention.
+ */
+public final class JavaIdentifierSyntax {
+
+ private static final int MAX_MONTHS = 12;
+ private static final int MAX_DAYS = 31;
+ private static final int INDEX_ZERO = 0;
+ private static final int INDEX_ONE = 1;
+ private static final int INDEX_TWO = 2;
+ private static final int VALUE_CHECK = 10;
+ private static final String ZERO = "0";
+
+ /**
+ * Create instance of java identifier syntax.
+ */
+ private JavaIdentifierSyntax() {
+ }
+
+ /**
+ * Returns the root package string.
+ *
+ * @param version YANG version
+ * @param nameSpace name space of the module
+ * @param revision revision of the module defined
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return the root package string
+ */
+ public static String getRootPackage(byte version, String nameSpace, String revision,
+ YangToJavaNamingConflictUtil conflictResolver) {
+
+ String pkg;
+ pkg = DEFAULT_BASE_PKG;
+ pkg = pkg + PERIOD;
+ pkg = pkg + getYangVersion(version);
+ pkg = pkg + PERIOD;
+ pkg = pkg + getPkgFromNameSpace(nameSpace, conflictResolver);
+ pkg = pkg + PERIOD;
+ pkg = pkg + getYangRevisionStr(revision);
+
+ return pkg.toLowerCase();
+ }
+
+ /**
+ * Returns the node package string.
+ *
+ * @param curNode current java node whose package string needs to be set
+ * @return returns the root package string
+ */
+ public static String getCurNodePackage(YangNode curNode) {
+
+ String pkg;
+ if (!(curNode instanceof JavaFileInfoContainer)
+ || curNode.getParent() == null) {
+ throw new TranslatorException("missing parent node to get current node's package");
+ }
+
+ YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
+ if (!(parentNode instanceof JavaFileInfoContainer)) {
+ throw new TranslatorException("missing parent java node to get current node's package");
+ }
+ JavaFileInfo parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
+ pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
+ return pkg.toLowerCase();
+ }
+
+ /**
+ * Returns version.
+ *
+ * @param ver YANG version
+ * @return version
+ */
+ private static String getYangVersion(byte ver) {
+ return VERSION_PREFIX + ver;
+ }
+
+ /**
+ * Returns package name from name space.
+ *
+ * @param nameSpace name space of YANG module
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return java package name as per java rules
+ */
+ private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) {
+
+ ArrayList<String> pkgArr = new ArrayList<String>();
+ nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
+ String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
+ String[] nameSpaceArr = properNameSpace.split(COLAN);
+
+ for (String nameSpaceString : nameSpaceArr) {
+ pkgArr.add(nameSpaceString);
+ }
+ return getPkgFrmArr(pkgArr, conflictResolver);
+ }
+
+ /**
+ * Returns revision string array.
+ *
+ * @param date YANG module revision
+ * @return revision string
+ * @throws TranslatorException when date is invalid.
+ */
+ private static String getYangRevisionStr(String date) throws TranslatorException {
+
+ String[] revisionArr = date.split(HYPHEN);
+
+ String rev = REVISION_PREFIX;
+ rev = rev + revisionArr[INDEX_ZERO];
+
+ if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS
+ && Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) {
+ for (int i = INDEX_ONE; i < revisionArr.length; i++) {
+
+ Integer val = Integer.parseInt(revisionArr[i]);
+ if (val < VALUE_CHECK) {
+ rev = rev + ZERO;
+ }
+ rev = rev + val;
+ }
+
+ return rev;
+ } else {
+ throw new TranslatorException("Date in revision is not proper: " + date);
+ }
+ }
+
+ /**
+ * Returns the package string.
+ *
+ * @param pkgArr package array
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return package string
+ */
+ private static String getPkgFrmArr(ArrayList<String> pkgArr, YangToJavaNamingConflictUtil conflictResolver) {
+
+ String pkg = EMPTY_STRING;
+ int size = pkgArr.size();
+ int i = 0;
+ for (String member : pkgArr) {
+ boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
+ if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
+ String prefix = getPrefixForIdentifier(conflictResolver);
+ member = prefix + member;
+ }
+ pkg = pkg + member;
+ if (i != size - 1) {
+ pkg = pkg + PERIOD;
+ }
+ i++;
+ }
+ return pkg;
+ }
+
+ /**
+ * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
+ *
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return prefix which needs to be added
+ */
+ public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
+
+ String prefixForIdentifier = null;
+ if (conflictResolver != null) {
+ prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
+ }
+ if (prefixForIdentifier != null) {
+ prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
+ String[] strArray = prefixForIdentifier.split(COLAN);
+ try {
+ if (strArray[0].isEmpty()) {
+ List<String> stringArrangement = new ArrayList<String>();
+ for (int i = 1; i < strArray.length; i++) {
+ stringArrangement.add(strArray[i]);
+ }
+ strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
+ }
+ prefixForIdentifier = strArray[0];
+ for (int j = 1; j < strArray.length; j++) {
+ prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
+ strArray[j].substring(1);
+ }
+ } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
+ throw new TranslatorException("The given prefix in pom.xml is invalid.");
+ }
+ } else {
+ prefixForIdentifier = YANG_AUTO_PREFIX;
+ }
+ return prefixForIdentifier;
+ }
+
+ /**
+ * Returns the YANG identifier name as java identifier.
+ *
+ * @param yangIdentifier identifier in YANG file
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return corresponding java identifier
+ */
+ public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
+
+ if (conflictResolver != null) {
+ String replacementForHyphen = conflictResolver.getReplacementForHyphen();
+ String replacementForPeriod = conflictResolver.getReplacementForPeriod();
+ String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
+ if (replacementForPeriod != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
+ PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
+ }
+ if (replacementForUnderscore != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
+ UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
+ }
+ if (replacementForHyphen != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
+ HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
+ }
+ }
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
+ String[] strArray = yangIdentifier.split(COLAN);
+ if (strArray[0].isEmpty()) {
+ List<String> stringArrangement = new ArrayList<String>();
+ for (int i = 1; i < strArray.length; i++) {
+ stringArrangement.add(strArray[i]);
+ }
+ strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
+ }
+ return upperCaseConflictResolver(strArray, conflictResolver);
+ }
+
+ /**
+ * Resolves the conflict when input has upper case.
+ *
+ * @param stringArray containing strings for upper case conflict resolver
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return camel cased string
+ */
+ private static String upperCaseConflictResolver(String[] stringArray,
+ YangToJavaNamingConflictUtil conflictResolver) {
+
+ for (int l = 0; l < stringArray.length; l++) {
+ String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
+ for (int m = 0; m < upperCaseSplitArray.length; m++) {
+ if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
+ int check = m;
+ while (check + 1 < upperCaseSplitArray.length) {
+ if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
+ upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
+ check = check + 1;
+ } else if (upperCaseSplitArray[check + 1]
+ .matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
+ upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
+ break;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ StringBuilder strBuilder = new StringBuilder();
+ for (String element : upperCaseSplitArray) {
+ strBuilder.append(element);
+ }
+ stringArray[l] = strBuilder.toString();
+ }
+ List<String> result = new ArrayList<String>();
+ for (String element : stringArray) {
+ String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
+ for (String letter : capitalCaseSplitArray) {
+ String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
+ List<String> list = Arrays.asList(arrayForAddition);
+ for (String str : list) {
+ if (str != null && !str.isEmpty()) {
+ result.add(str);
+ }
+ }
+ }
+ }
+ stringArray = result.toArray(new String[result.size()]);
+ return applyCamelCaseRule(stringArray, conflictResolver);
+ }
+
+ /**
+ * Applies the rule that a string does not end with a capitalized letter and capitalizes
+ * the letter next to a number in an array.
+ *
+ * @param stringArray containing strings for camel case separation
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return camel case rule checked string
+ */
+ private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
+
+ String ruleChecker = stringArray[0].toLowerCase();
+ int i;
+ if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
+ i = 0;
+ ruleChecker = EMPTY_STRING;
+ } else {
+ i = 1;
+ }
+ for (; i < stringArray.length; i++) {
+ if (i + 1 == stringArray.length) {
+ if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
+ || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
+ ruleChecker = ruleChecker + stringArray[i].toLowerCase();
+ break;
+ }
+ }
+ if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
+ for (int j = 0; j < stringArray[i].length(); j++) {
+ char letterCheck = stringArray[i].charAt(j);
+ if (Character.isLetter(letterCheck)) {
+ stringArray[i] = stringArray[i].substring(0, j)
+ + stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
+ break;
+ }
+ }
+ ruleChecker = ruleChecker + stringArray[i];
+ } else {
+ ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
+ }
+ }
+ String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
+ return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
+ }
+
+ /**
+ * Adds prefix, if the string begins with digit or is a java key word.
+ *
+ * @param camelCasePrefix string for adding prefix
+ * @param conflictResolver object of YANG to java naming conflict util
+ * @return prefixed camel case string
+ */
+ private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
+
+ String prefix = getPrefixForIdentifier(conflictResolver);
+ if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
+ camelCasePrefix = prefix + camelCasePrefix;
+ }
+ if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
+ camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
+ + camelCasePrefix.substring(1);
+ }
+ return camelCasePrefix;
+ }
+
+ /**
+ * Restricts consecutive capital cased string as a rule in camel case.
+ *
+ * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
+ * @return string without consecutive capital case
+ */
+ private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
+
+ for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
+ if (k + 1 < consecCapitalCaseRemover.length()) {
+ if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
+ if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
+ consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
+ + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
+ + consecCapitalCaseRemover.substring(k + 2);
+ }
+ }
+ }
+ }
+ return consecCapitalCaseRemover;
+ }
+
+ /**
+ * Returns the YANG identifier name as java identifier with first letter
+ * in capital.
+ *
+ * @param yangIdentifier identifier in YANG file
+ * @return corresponding java identifier
+ */
+ public static String getCapitalCase(String yangIdentifier) {
+ yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
+ return restrictConsecutiveCapitalCase(yangIdentifier);
+ }
+
+ /**
+ * Returns the YANG identifier name as java identifier with first letter
+ * in small.
+ *
+ * @param yangIdentifier identifier in YANG file.
+ * @return corresponding java identifier
+ */
+ public static String getSmallCase(String yangIdentifier) {
+ return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
+ }
+
+ /**
+ * Returns the java Package from package path.
+ *
+ * @param packagePath package path
+ * @return java package
+ */
+ public static String getJavaPackageFromPackagePath(String packagePath) {
+ return packagePath.replace(SLASH, PERIOD);
+ }
+
+ /**
+ * Returns enum's java name.
+ *
+ * @param name enum's name
+ * @return enum's java name
+ */
+ public static String getEnumJavaAttribute(String name) {
+
+ name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
+ String[] strArray = name.split(COLAN);
+ String output = EMPTY_STRING;
+ if (strArray[0].isEmpty()) {
+ List<String> stringArrangement = new ArrayList<String>();
+ for (int i = 1; i < strArray.length; i++) {
+ stringArrangement.add(strArray[i]);
+ }
+ strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
+ }
+ for (int i = 0; i < strArray.length; i++) {
+ if (i > 0 && i < strArray.length) {
+ output = output + UNDER_SCORE;
+ }
+ output = output + strArray[i];
+ }
+ return output;
+ }
+
+ /**
+ * Returns the directory path corresponding to java package.
+ *
+ * @param packagePath package path
+ * @return java package
+ */
+ public static String getPackageDirPathFromJavaJPackage(String packagePath) {
+ return packagePath.replace(PERIOD, SLASH);
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
new file mode 100644
index 0000000..b6889c8
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -0,0 +1,1086 @@
+/*
+ * 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.utils;
+
+import java.util.List;
+import java.util.Map;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
+import static org.onosproject.yangutils.utils.UtilConstants.CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
+import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.CLEAR;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
+import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
+import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
+import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
+import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.HASH;
+import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.IF;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
+import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
+import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.NULL;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.OF;
+import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
+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.OTHER;
+import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
+import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
+import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
+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;
+import static org.onosproject.yangutils.utils.UtilConstants.THIS;
+import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
+import static org.onosproject.yangutils.utils.UtilConstants.TO;
+import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
+import static org.onosproject.yangutils.utils.UtilConstants.TRY;
+import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
+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;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
+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.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.YangIoUtils.trimAtLast;
+
+/**
+ * Represents generator for methods of generated files based on the file type.
+ */
+public final class MethodsGenerator {
+
+ /**
+ * Creates an instance of method generator.
+ */
+ private MethodsGenerator() {
+ }
+
+ /**
+ * 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, YangPluginConfig pluginConfig) {
+ return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name);
+ }
+
+ /**
+ * Returns getter string.
+ *
+ * @param attr attribute info
+ * @param generatedJavaFiles generated java files
+ * @param pluginConfig plugin configurations
+ * @return getter string
+ */
+ 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(), pluginConfig)
+ + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
+ }
+
+ /**
+ * Returns setter string.
+ *
+ * @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,
+ YangPluginConfig pluginConfig) {
+
+ String attrType = getReturnType(attr);
+ String attributeName = attr.getAttributeName();
+ JavaDocGen.JavaDocType type;
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ type = MANAGER_SETTER_METHOD;
+ } else {
+ type = SETTER_METHOD;
+ }
+
+ return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig)
+ + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
+ }
+
+ /**
+ * Returns constructor method string.
+ *
+ * @param name class name
+ * @param pluginConfig plugin configurations
+ * @return constructor string
+ */
+ public static String getConstructorString(String name, YangPluginConfig pluginConfig) {
+ return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
+ }
+
+ /**
+ * Returns default constructor method string.
+ *
+ * @param name class name
+ * @param modifierType modifier type
+ * @param pluginConfig plugin configurations
+ * @return default constructor string
+ */
+ public static String getDefaultConstructorString(String name, String modifierType,
+ YangPluginConfig pluginConfig) {
+ return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig)
+ + getDefaultConstructor(name, modifierType)
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns check not null string.
+ *
+ * @param name attribute name
+ * @return check not null string
+ */
+ public static String getCheckNotNull(String name) {
+ return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns build method string.
+ *
+ * @param name class name
+ * @return build string
+ */
+ public static String getBuildString(String name) {
+ return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name);
+ }
+
+ /**
+ * Returns the getter method strings for class file.
+ *
+ * @param attr attribute info
+ * @param generatedJavaFiles for the type of java file being generated
+ * @return getter method for class
+ */
+ public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
+
+ String attrQuaifiedType = getReturnType(attr);
+ String attributeName = attr.getAttributeName();
+
+ if (!attr.isListAttr()) {
+ return getGetter(attrQuaifiedType, attributeName, generatedJavaFiles);
+ }
+ String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
+ return getGetter(listAttr, attributeName, generatedJavaFiles);
+ }
+
+ /**
+ * Returns getter for attribute.
+ *
+ * @param type return type
+ * @param name attribute name
+ * @param generatedJavaFiles generated java files
+ * @return getter for attribute
+ */
+ public static String getGetter(String type, String name, int generatedJavaFiles) {
+ String ret = parseTypeForReturnValue(type);
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ } else {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ + CLOSE_CURLY_BRACKET;
+ }
+
+ }
+
+ /*Provides string to return for type.*/
+ private static String parseTypeForReturnValue(String type) {
+ switch (type) {
+ case BYTE:
+ case INT:
+ case SHORT:
+ case LONG:
+ return "0";
+ case BOOLEAN_DATA_TYPE:
+ return FALSE;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns the setter method strings for class file.
+ *
+ * @param attr attribute info
+ * @param className name of the class
+ * @param generatedJavaFiles generated java files
+ * @return setter method for class
+ */
+ public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
+
+ String attrQuaifiedType = getReturnType(attr);
+ String attributeName = attr.getAttributeName();
+ if (!attr.isListAttr()) {
+ return getSetter(className, attributeName, attrQuaifiedType, generatedJavaFiles);
+ }
+ String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
+ return getSetter(className, attributeName, listAttr, generatedJavaFiles);
+ }
+
+ /**
+ * Returns setter for attribute.
+ *
+ * @param className class name
+ * @param name attribute name
+ * @param type return type
+ * @return setter for attribute
+ */
+ private static String getSetter(String className, String name, String type, int generatedJavaFiles) {
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
+ + 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;
+ }
+ }
+
+ /**
+ * Returns the setter method strings for class file.
+ *
+ * @param attr attribute info
+ * @return setter method for class
+ */
+ public static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
+
+ String attrQuaifiedType = getReturnType(attr);
+ String attributeName = attr.getAttributeName();
+ return getTypeDefSetter(attrQuaifiedType, attributeName);
+ }
+
+ /**
+ * Returns type def's setter for attribute.
+ *
+ * @param type data type
+ * @param name attribute name
+ * @return setter for type def's attribute
+ */
+ private static String getTypeDefSetter(String type, String name) {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name)
+ + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE
+ + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns override string.
+ *
+ * @return override string
+ */
+ public static String getOverRideString() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
+ }
+
+ /**
+ * Returns the getter method strings for interface file.
+ *
+ * @param yangName name of the attribute
+ * @param returnType return type of attribute
+ * @param isList is list attribute
+ * @param generatedJavaFiles generated java files
+ * @return getter method for interface
+ */
+ public static String getGetterForInterface(String yangName, String returnType, boolean isList,
+ int generatedJavaFiles) {
+
+ if (!isList) {
+ return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
+ }
+ String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET;
+ return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
+ }
+
+ /**
+ * Returns getter for attribute in interface.
+ *
+ * @param returnType return type
+ * @param yangName attribute name
+ * @return getter for interface
+ */
+ private static String getGetterInterfaceString(String returnType, String yangName,
+ int generatedJavaFiles) {
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
+ } else {
+ return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
+ }
+
+ /**
+ * Returns the setter method strings for interface file.
+ *
+ * @param attrName name of the attribute
+ * @param attrType return type of attribute
+ * @param className name of the java class being generated
+ * @param isList is list attribute
+ * @param generatedJavaFiles generated java files
+ * @return setter method for interface
+ */
+ public static String getSetterForInterface(String attrName, String attrType, String className,
+ boolean isList, int generatedJavaFiles) {
+
+ if (!isList) {
+ return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
+ }
+ String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
+ }
+
+ /**
+ * Returns setter string for interface.
+ *
+ * @param className class name
+ * @param attrName attribute name
+ * @param attrType attribute type
+ * @return setter string
+ */
+ private static String getSetterInterfaceString(String className, String attrName, String attrType,
+ int generatedJavaFiles) {
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+
+ return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
+ + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
+ } else {
+ return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
+ + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
+ }
+
+ /**
+ * Returns list string.
+ *
+ * @return list string
+ */
+ private static String getListString() {
+ return LIST + DIAMOND_OPEN_BRACKET;
+ }
+
+ /**
+ * Returns return type for attribute.
+ *
+ * @param attr attribute info
+ * @return return type
+ */
+ private static String getReturnType(JavaAttributeInfo attr) {
+
+ String returnType = EMPTY_STRING;
+ if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
+ returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
+ }
+ returnType = returnType + attr.getImportInfo().getClassInfo();
+ return returnType;
+ }
+
+ /**
+ * Returns the build method strings for interface file.
+ *
+ * @param yangName name of the interface
+ * @return build method for interface
+ */
+ public static String getBuildForInterface(String yangName) {
+ return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns constructor string for impl class.
+ *
+ * @param yangName class name
+ * @param pluginConfig plugin configurations
+ * @return constructor string
+ */
+ public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) {
+
+ 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;
+ }
+
+ /**
+ * Returns the constructor strings for class file.
+ *
+ * @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,
+ YangPluginConfig pluginConfig) {
+
+ String attributeName = attr.getAttributeName();
+ String constructor;
+
+ if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ 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, pluginConfig.getConflictResolver()) + SPACE + EQUAL
+ + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ }
+ return constructor;
+ }
+
+ /**
+ * Returns the rpc strings for service interface.
+ *
+ * @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,
+ YangPluginConfig pluginConfig) {
+
+ rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
+ if (!inputName.equals(EMPTY_STRING)) {
+ inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
+ }
+ return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
+ + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
+
+ /**
+ * Returns the rpc strings for manager impl.
+ *
+ * @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,
+ YangPluginConfig pluginConfig) {
+
+ rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
+ if (!inputName.equals(EMPTY_STRING)) {
+ inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
+ }
+
+ String method =
+ getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
+ + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
+ if (!outputName.contentEquals(VOID)) {
+ method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
+ + NEW_LINE;
+ }
+ method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+
+ return method;
+ }
+
+ /**
+ * Returns the build method strings for class file.
+ *
+ * @param yangName class name
+ * @return build method string for class
+ */
+ public static String getBuild(String yangName) {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE
+ + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns the Default constructor strings for class file.
+ *
+ * @param name name of the class
+ * @param modifierType modifier type for default constructor
+ * @return Default constructor for class
+ */
+ private static String getDefaultConstructor(String name, String modifierType) {
+ return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns to string method's open strings.
+ *
+ * @return string method's open string
+ */
+ public static String getToStringMethodOpen() {
+ return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO
+ + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE;
+ }
+
+ /**
+ * Returns omit null value string.
+ *
+ * @return omit null value string
+ */
+ public static String getOmitNullValueString() {
+ return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
+ }
+
+ /**
+ * Returns to string method's close string.
+ *
+ * @return to string method close string
+ */
+ public static String getToStringMethodClose() {
+ return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns to string method for class.
+ *
+ * @param attr attribute info
+ * @return to string method
+ */
+ public static String getToStringMethod(JavaAttributeInfo attr) {
+
+ String attributeName = attr.getAttributeName();
+ return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
+ + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
+ }
+
+ /**
+ * 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, 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;
+ }
+
+ /**
+ * Return from string method's close string.
+ *
+ * @return from string method's close string
+ */
+ public static String getFromStringMethodClose() {
+ return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Return from string method's body string.
+ *
+ * @param attr attribute info
+ * @param fromStringAttributeInfo attribute info for the from string
+ * wrapper type
+ * @return from string method's body string
+ */
+ public static String getFromStringMethod(JavaAttributeInfo attr,
+ JavaAttributeInfo fromStringAttributeInfo) {
+
+ return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
+ + getParsedSubString(attr, fromStringAttributeInfo) + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION
+ + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString()
+ + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns sub string with try statement for union's from string method.
+ *
+ * @return sub string with try statement for union's from string method
+ */
+ public static String getTrySubString() {
+ return TRY + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns sub string with return statement for union's from string method.
+ *
+ * @return sub string with return statement for union's from string method
+ */
+ public static String getReturnOfSubString() {
+ return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
+
+ /**
+ * Returns sub string with catch statement for union's from string method.
+ *
+ * @return sub string with catch statement for union's from string method
+ */
+ public static String getCatchSubString() {
+ return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns sub string with parsed statement for union's from string method.
+ *
+ * @param attr attribute info
+ * @return sub string with parsed statement for union's from string method
+ */
+ private static String getParsedSubString(JavaAttributeInfo attr,
+ JavaAttributeInfo fromStringAttributeInfo) {
+
+ String targetDataType = getReturnType(attr);
+ String parseFromStringMethod = getParseFromStringMethod(targetDataType,
+ fromStringAttributeInfo.getAttributeType());
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
+ + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ }
+
+ /**
+ * Returns hash code method open strings.
+ *
+ * @return hash code method open string
+ */
+ public static String getHashCodeMethodOpen() {
+ return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
+ }
+
+ /**
+ * Returns hash code methods close string.
+ *
+ * @param hashcodeString hash code string
+ * @return to hash code method close string
+ */
+ public static String getHashCodeMethodClose(String hashcodeString) {
+ hashcodeString = trimAtLast(hashcodeString, COMMA);
+ hashcodeString = trimAtLast(hashcodeString, SPACE);
+ return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns hash code method for class.
+ *
+ * @param attr attribute info
+ * @return hash code method
+ */
+ public static String getHashCodeMethod(JavaAttributeInfo attr) {
+ return attr.getAttributeName() + COMMA + SPACE;
+ }
+
+ /**
+ * Returns equals method open strings.
+ *
+ * @param className class name
+ * @return equals method open string
+ */
+ public static String getEqualsMethodOpen(String className) {
+ return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING
+ + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
+ }
+
+ /**
+ * Returns equal methods if condition string.
+ *
+ * @return if condition string
+ */
+ private static String getEqualsMethodsCommonIfCondition() {
+ return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE
+ + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns if condition for specific class object in equals method.
+ *
+ * @param className class name
+ * @return if condition string
+ */
+ private static String getEqualsMethodsSpecificIfCondition(String className) {
+ return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className
+ + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE
+ + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE;
+ }
+
+ /**
+ * Returns equals methods close string.
+ *
+ * @param equalMethodString equal method string
+ * @return equals method close string
+ */
+ public static String getEqualsMethodClose(String equalMethodString) {
+ equalMethodString = trimAtLast(equalMethodString, AND);
+ equalMethodString = trimAtLast(equalMethodString, AND);
+ equalMethodString = trimAtLast(equalMethodString, SPACE);
+ equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
+ return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns equals method for class.
+ *
+ * @param attr attribute info
+ * @return equals method
+ */
+ public static String getEqualsMethod(JavaAttributeInfo attr) {
+
+ String attributeName = attr.getAttributeName();
+ return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
+ + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
+ + AND;
+ }
+
+ /**
+ * Returns of method string for class.
+ *
+ * @param name class name
+ * @param attr attribute info
+ * @return of method string
+ */
+ public static String getOfMethod(String name, JavaAttributeInfo attr) {
+
+ String attrQualifiedType = getReturnType(attr);
+
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
+ + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns of method's string and java doc for special type.
+ *
+ * @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,
+ YangPluginConfig pluginConfig) {
+
+ String attrType = getReturnType(attr);
+ String attrName = attr.getAttributeName();
+
+ return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ + getOfMethodString(attrType, generatedJavaClassName);
+ }
+
+ /**
+ * Returns of method's string.
+ *
+ * @param type data type
+ * @param className class name
+ * @return of method's string
+ */
+ private static String getOfMethodString(String type, String className) {
+
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS
+ + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns string and java doc for constructor of type class.
+ *
+ * @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, YangPluginConfig pluginConfig) {
+
+ String attrType = getReturnType(attr);
+ String attrName = attr.getAttributeName();
+
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
+ }
+
+ /**
+ * Returns type constructor string.
+ *
+ * @param type data type
+ * @param name attribute name
+ * @param className class name
+ * @return type constructor string
+ */
+ private static String getTypeConstructorString(String type, String name, String className) {
+
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns implementation of add augmentation method of AugmentationHolder class.
+ *
+ * @return implementation of add augmentation method of AugmentationHolder class
+ */
+ public static String getAddAugmentInfoMethodImpl() {
+ String method = FOUR_SPACE_INDENTATION;
+ method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+
+ return method;
+ }
+
+ /**
+ * Returns implementation of get augment info list method of AugmentationHolder class.
+ *
+ * @return implementation of get augment info list method of AugmentationHolder class
+ */
+ public static String getAugmentInfoListImpl() {
+
+ String method = FOUR_SPACE_INDENTATION;
+ method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET
+ + AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ + CLOSE_CURLY_BRACKET;
+ return method;
+ }
+
+ /**
+ * Returns implementation of remove augmentation method of AugmentationHolder class.
+ *
+ * @return implementation of remove augmentation method of AugmentationHolder class
+ */
+ public static String getRemoveAugmentationImpl() {
+ String method = FOUR_SPACE_INDENTATION;
+ method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove"
+ + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + PERIOD + CLEAR + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return method;
+ }
+
+ /**
+ * Returns enum's constructor.
+ *
+ * @param className enum's class name
+ * @return enum's constructor
+ */
+ public static String getEnumsConstrcutor(String className) {
+ return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
+ + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ }
+
+ /**
+ * Provides string to be added in augment node's constructor.
+ *
+ * @param curNode current YANG node
+ * @return constructors string
+ */
+ public static String getAugmentsAddToAugmentedMethod(YangNode curNode) {
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+
+ String name = targetNodes.get(targetNodes.size() - 1).getName();
+ String captialCase = getCapitalCase(name);
+ String smallCase = getSmallCase(captialCase);
+ return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE
+ + NEW + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION
+ + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+
+ }
+
+ private static String getAugmentsAddToAugmentedMethodStart() {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING + AUGMENTABLE + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns of method for enum class.
+ *
+ * @param className class name
+ * @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, YangPluginConfig pluginConfig) {
+ String attrType = getReturnType(attr);
+ String attrName = attr.getAttributeName();
+
+ String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE
+ + OF + OPEN_PARENTHESIS
+ + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ int value = 0;
+ for (String str : enumList) {
+
+ value = enumMap.get(str);
+ method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE
+ + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
+ + str + SEMI_COLAN + NEW_LINE;
+ }
+ method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION
+ + 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, 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
new file mode 100644
index 0000000..f70ec53
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
@@ -0,0 +1,349 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+
+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;
+
+import static java.util.Collections.sort;
+
+/**
+ * Represents utilities for temporary java code fragments.
+ */
+public final class TempJavaCodeFragmentFilesUtils {
+
+ /**
+ * Creates a private instance of temporary java code fragment utils.
+ */
+ private TempJavaCodeFragmentFilesUtils() {
+ }
+
+ /**
+ * Adds import for AugmentationHolders class.
+ *
+ * @param curNode current YANG node
+ * @param imports list of imports
+ * @param operation add or delete import
+ */
+ public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
+ String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
+
+ /**
+ * Adds import for AugmentedInfo class.
+ *
+ * @param curNode current YANG node
+ * @param imports list of imports
+ * @param operation add or delete import
+ */
+ public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
+ String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
+
+ /**
+ * Returns temp java fragment.
+ *
+ * @param curNode current YANG node
+ * @return temp java fragments
+ */
+ public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) {
+ TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles();
+ if (container.getBeanTempFiles() != null) {
+ return container.getBeanTempFiles();
+ }
+ if (container.getServiceTempFiles() != null) {
+ return container.getServiceTempFiles();
+ }
+
+ return null;
+ }
+
+ /**
+ * Updated imports with augmented nodes import.
+ *
+ * @param curNode current YANG node
+ * @param imports list of imports
+ * @param operation to add or to delete
+ */
+ public static void addAugmentedNodesImport(YangNode curNode, List<String> imports, boolean operation) {
+
+ String nodesImport = "";
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+ YangNode parent = curNode.getParent();
+ if (parent instanceof YangJavaModule) {
+ // Add impl class import.
+ nodesImport = getAugmendtedNodesImports(parent, targetNodes, true) + SEMI_COLAN + NEW_LINE;
+ performOperationOnImports(imports, nodesImport, operation);
+ // Add builder class import.
+ if (targetNodes.size() > 2) {
+ nodesImport = getAugmendtedNodesImports(parent, targetNodes, false) + SEMI_COLAN + NEW_LINE;
+ performOperationOnImports(imports, nodesImport, operation);
+ }
+ }
+ // TODO: add functionality for submodule and uses.
+ }
+
+ /**
+ * Returns imports for augmented node.
+ *
+ * @param parent parent YANG node
+ * @param targetNodes list of target nodes
+ * @param isImplClass if impl class's import required
+ * @return imports for augmented node
+ */
+ private static String getAugmendtedNodesImports(YangNode parent, List<YangNodeIdentifier> targetNodes,
+ boolean isImplClass) {
+ String pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
+
+ for (int i = 0; i < targetNodes.size() - 1; i++) {
+ pkgInfo = pkgInfo + PERIOD + targetNodes.get(i).getName();
+ }
+ String classInfo = targetNodes.get(targetNodes.size() - 1).getName();
+ if (!isImplClass) {
+ return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER;
+ }
+ return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER + PERIOD
+ + getCapitalCase(classInfo) + IMPL;
+ }
+
+ /**
+ * Provides string to be added in augment node's constructor.
+ *
+ * @param curNode current YANG node
+ * @return constructors string
+ */
+ public static String getAugmentsAddToAugmentedClassString(YangNode curNode) {
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+
+ String name = targetNodes.get(targetNodes.size() - 1).getName();
+ String captialCase = getCapitalCase(name);
+ String smallCase = getSmallCase(captialCase);
+ return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE + NEW
+ + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION + OPEN_PARENTHESIS
+ + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+
+ }
+
+ /**
+ * Adds import for array list.
+ *
+ * @param curNode current YANG node
+ * @param imports list of imports
+ * @param operation add or delete import
+ */
+ public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
+ String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList();
+ String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList();
+ performOperationOnImports(imports, arrayListImport, operation);
+ if (!imports.contains(listImport)) {
+ /**
+ * List can be there because of attribute also , so no need to remove it and operation will
+ * always be add(true).
+ */
+ performOperationOnImports(imports, listImport, true);
+ }
+ }
+
+ /**
+ * Adds listener's imports.
+ *
+ * @param curNode currentYangNode.
+ * @param imports import list
+ * @param operation add or remove
+ * @param classInfo class info to be added to import list
+ */
+ public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation,
+ String classInfo) {
+ String thisImport = "";
+ if (classInfo.equals(LISTENER_SERVICE)) {
+ thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport();
+ performOperationOnImports(imports, thisImport, operation);
+ } else {
+ thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
+ }
+
+ /**
+ * 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
+ * @param curImport current import
+ * @param operation add or remove
+ * @return import list
+ */
+ private static List<String> performOperationOnImports(List<String> imports, String curImport,
+ boolean operation) {
+ if (operation) {
+ imports.add(curImport);
+ } else {
+ imports.remove(curImport);
+ }
+ sortImports(imports);
+ return imports;
+ }
+
+ /**
+ * Returns true if AugmentationHolder class needs to be extended.
+ *
+ * @param extendsList list of classes need to be extended
+ * @return true or false
+ */
+ public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) {
+ for (JavaQualifiedTypeInfo info : extendsList) {
+ return info.getClassInfo().equals(AUGMENTATION_HOLDER);
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if AugmentedInfo class needs to be extended.
+ *
+ * @param extendsList list of classes need to be extended
+ * @return true or false
+ */
+ public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) {
+ for (JavaQualifiedTypeInfo info : extendsList) {
+ return info.getClassInfo().equals(AUGMENTED_INFO);
+ }
+ return false;
+ }
+
+ /**
+ * Closes the file handle for temporary file.
+ *
+ * @param file file to be closed
+ * @param toBeDeleted flag to indicate if file needs to be deleted
+ * @throws IOException when failed to close the file handle
+ */
+ public static void closeFile(File file, boolean toBeDeleted)
+ throws IOException {
+
+ if (file != null) {
+ updateFileHandle(file, null, true);
+ if (toBeDeleted) {
+ file.delete();
+ }
+ }
+ }
+
+ /**
+ * Returns sorted import list.
+ *
+ * @param imports import list
+ * @return sorted import list
+ */
+ public static List<String> sortImports(List<String> imports) {
+ sort(imports);
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
new file mode 100644
index 0000000..3f378c7
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -0,0 +1,352 @@
+/*
+ * 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.utils;
+
+import java.io.IOException;
+
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+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.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+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;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
+
+/**
+ * Represents utility class for YANG java model.
+ */
+public final class YangJavaModelUtils {
+
+ /**
+ * Creates an instance of YANG java model utility.
+ */
+ private YangJavaModelUtils() {
+ }
+
+ /**
+ * Updates YANG java file package information.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPluginConfig YANG plugin config
+ * @throws IOException IO operations fails
+ */
+ public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+
+ javaCodeGeneratorInfo.getJavaFileInfo()
+ .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
+ yangPluginConfig.getConflictResolver()));
+ javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
+ javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
+ getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
+ javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
+ javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
+ }
+
+ /**
+ * Updates YANG java file package information for specified package.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPlugin YANG plugin config
+ * @throws IOException IO operations fails
+ */
+ private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
+ String pkg)
+ throws IOException {
+ javaCodeGeneratorInfo.getJavaFileInfo()
+ .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
+ yangPlugin.getConflictResolver()));
+ javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
+ javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
+ getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
+ javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
+ javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
+ }
+
+ /**
+ * Updates temporary java code fragment files.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @throws IOException IO operations fails
+ */
+ private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
+ throws IOException {
+ javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles(
+ new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo()));
+ }
+
+ /**
+ * Updates leaf information in temporary java code fragment files.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @throws IOException IO operations fails
+ */
+ private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
+ /*
+ * Module / sub module node code generation.
+ */
+ 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
+ * Case
+ * Grouping
+ * Input
+ * List
+ * Notification
+ * Output
+ */
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
+ (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+ } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
+ /*
+ * Typedef
+ * Union
+ */
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
+ } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
+ /*
+ * Enumeration
+ */
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
+ .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+
+ } else if (javaCodeGeneratorInfo instanceof YangChoice) {
+ /*Do nothing, only the interface needs to be generated*/
+ } else {
+ throw new TranslatorException("Unsupported Node Translation");
+ }
+ }
+
+ /**
+ * Process generate code entry of YANG node.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @throws IOException IO operations fails
+ */
+ private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (!(javaCodeGeneratorInfo instanceof YangNode)) {
+ throw new TranslatorException("translation is not supported for the node");
+ }
+ createTempFragmentFile(javaCodeGeneratorInfo);
+ updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
+
+ }
+
+ /**
+ * 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
+ * @param yangPlugin YANG plugin config
+ * @param isMultiInstance flag to indicate whether it's a list
+ * @throws IOException IO operations fails
+ */
+ public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPlugin, boolean isMultiInstance)
+ throws IOException {
+ if (!(javaCodeGeneratorInfo instanceof YangNode)) {
+ throw new TranslatorException("Invalid node for translation");
+ }
+
+ /*
+ * Generate the Java files corresponding to the current node.
+ */
+ generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin);
+
+ /*
+ * Update the current nodes info in its parent nodes generated files.
+ */
+ addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
+ }
+
+ /**
+ * Generates code for the current data model node and adds support for it to be augmented.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPlugin YANG plugin config
+ * @throws IOException IO operations fails
+ */
+ public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPlugin)
+ throws IOException {
+ if (!(javaCodeGeneratorInfo instanceof YangNode)) {
+ throw new TranslatorException("invalid node for translation");
+ }
+
+ generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
+
+ /*
+ TODO: Need to use this, when augmentation is added in YMS
+ * For augmentation of nodes.
+
+ if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
+ JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
+ augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
+ augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo);
+
+ } else if (javaCodeGeneratorInfo instanceof YangAugment) {
+ JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo();
+ augmentedInfo.setClassInfo(AUGMENTED_INFO);
+ augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
+
+ }
+ */
+ if (javaCodeGeneratorInfo instanceof YangCase) {
+ YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
+ JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
+ String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
+ String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
+ parentsInfo.setClassInfo(parentName);
+ parentsInfo.setPkgInfo(parentPkg);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
+
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
+ .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
+
+ }
+ }
+
+ /**
+ * Generates code for the current data model node.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPluginConfig YANG plugin config
+ * @throws IOException IO operations fails
+ */
+ public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig)
+ throws IOException {
+ if (!(javaCodeGeneratorInfo instanceof YangNode)) {
+ // TODO:throw exception
+ }
+ updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
+ generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
+ }
+
+ /**
+ * Generates code for the root module/sub-module node.
+ *
+ * @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPluginConfig YANG plugin config
+ * @param rootPkg package of the root node
+ * @throws IOException IO operations fails
+ */
+ public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
+ YangPluginConfig yangPluginConfig, String rootPkg)
+ throws IOException {
+ if (!(javaCodeGeneratorInfo instanceof YangNode)) {
+ // TODO:throw exception
+ }
+ updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
+
+ if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
+ 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/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
new file mode 100644
index 0000000..f827698
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
@@ -0,0 +1,75 @@
+/*
+ * 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.utils;
+
+/**
+ * Representation of plugin configurations required for YANG utils.
+ */
+public final class YangPluginConfig {
+
+ /**
+ * Contains the code generation directory.
+ */
+ private String codeGenDir;
+
+ /**
+ * Contains information of naming conflicts that can be resolved.
+ */
+ private YangToJavaNamingConflictUtil conflictResolver;
+
+ /**
+ * Creates an object for YANG plugin config.
+ */
+ public YangPluginConfig() {
+ }
+
+ /**
+ * Sets the path of the java code where it has to be generated.
+ *
+ * @param codeGenDir path of the directory
+ */
+ public void setCodeGenDir(String codeGenDir) {
+ this.codeGenDir = codeGenDir;
+ }
+
+ /**
+ * Returns the code generation directory path.
+ *
+ * @return code generation directory
+ */
+ public String getCodeGenDir() {
+ return codeGenDir;
+ }
+
+ /**
+ * Sets the object.
+ *
+ * @param conflictResolver object of the class
+ */
+ public void setConflictResolver(YangToJavaNamingConflictUtil conflictResolver) {
+ this.conflictResolver = conflictResolver;
+ }
+
+ /**
+ * Returns the object.
+ *
+ * @return object of the class
+ */
+ public YangToJavaNamingConflictUtil getConflictResolver() {
+ return conflictResolver;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java
new file mode 100644
index 0000000..4f701b6
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java
@@ -0,0 +1,121 @@
+/*
+ * 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.utils;
+
+/**
+ * Representation of YANG to java naming conflict resolver util.
+ */
+public final class YangToJavaNamingConflictUtil {
+
+ /**
+ * Contains the replacement value for a period.
+ */
+ private static String replacementForPeriodInIdentifier;
+
+ /**
+ * Contains the replacement value for an underscore.
+ */
+ private static String replacementForUnderscoreInIdentifier;
+
+ /**
+ * Contains the replacement value for a hyphen.
+ */
+ private static String replacementForHyphenInIdentifier;
+
+ /**
+ * Contains the prefix value for adding with the identifier.
+ */
+ private static String prefixForIdentifier;
+
+ /**
+ * Creates an object for YANG to java naming conflict util.
+ */
+ public YangToJavaNamingConflictUtil() {
+ }
+
+ /**
+ * Sets the replacement value for a period.
+ *
+ * @param periodReplacement replacement value for period
+ */
+ public void setReplacementForPeriod(String periodReplacement) {
+ replacementForPeriodInIdentifier = periodReplacement;
+ }
+
+ /**
+ * Returns the replaced period value.
+ *
+ * @return replaced period
+ */
+ public String getReplacementForPeriod() {
+ return replacementForPeriodInIdentifier;
+ }
+
+ /**
+ * Sets the replacement value for a hyphen.
+ *
+ * @param hyphenReplacement replacement value for hyphen
+ */
+ public void setReplacementForHyphen(String hyphenReplacement) {
+ replacementForHyphenInIdentifier = hyphenReplacement;
+ }
+
+ /**
+ * Returns the replaced hyphen value.
+ *
+ * @return replaced hyphen
+ */
+ public String getReplacementForHyphen() {
+ return replacementForHyphenInIdentifier;
+ }
+
+ /**
+ * Sets the replacement value for an underscore.
+ *
+ * @param underscoreReplacement replacement value for underscore
+ */
+ public void setReplacementForUnderscore(String underscoreReplacement) {
+ replacementForUnderscoreInIdentifier = underscoreReplacement;
+ }
+
+ /**
+ * Returns the replaced underscore value.
+ *
+ * @return replaced underscore
+ */
+ public String getReplacementForUnderscore() {
+ return replacementForUnderscoreInIdentifier;
+ }
+
+ /**
+ * Sets the prefix value for adding with the identifier.
+ *
+ * @param prefix prefix for identifier
+ */
+ public void setPrefixForIdentifier(String prefix) {
+ prefixForIdentifier = prefix;
+ }
+
+ /**
+ * Returns the prefix for identifier.
+ *
+ * @return prefix for identifier
+ */
+ public String getPrefixForIdentifier() {
+ return prefixForIdentifier;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java
new file mode 100644
index 0000000..709e704
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Translator's utils for YANG plugin.
+ */
+package org.onosproject.yangutils.translator.tojava.utils;