[ONOS-4350] Inter Jar dependency implementation and code restructuring.
Change-Id: Iacac75e4187aed93ce1754c170a9c19707e5b8c3
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;