blob: a11fb2c91ebbf5457df07e4cbb5f1cac0b6e48ee [file] [log] [blame]
Bharat saraswald72411a2016-04-19 01:00:16 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.translator.tojava.javamodel;
18
19import java.io.IOException;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053020
Bharat saraswald72411a2016-04-19 01:00:16 +053021import org.onosproject.yangutils.datamodel.YangEnumeration;
22import org.onosproject.yangutils.translator.exception.TranslatorException;
23import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
24import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
Bharat saraswald72411a2016-04-19 01:00:16 +053025import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27
28import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Gaurav Agrawal56527662016-04-20 15:49:17 +053029import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
Bharat saraswald72411a2016-04-19 01:00:16 +053030
31/**
32 * Represents YANG java enumeration information extended to support java code generation.
33 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053034public class YangJavaEnumeration
35 extends YangEnumeration
36 implements JavaCodeGenerator, JavaCodeGeneratorInfo {
Bharat saraswald72411a2016-04-19 01:00:16 +053037
38 /**
39 * Contains the information of the java file being generated.
40 */
41 private JavaFileInfo javaFileInfo;
42
43 /**
Bharat saraswald72411a2016-04-19 01:00:16 +053044 * File handle to maintain temporary java code fragments as per the code
45 * snippet types.
46 */
47 private TempJavaCodeFragmentFiles tempFileHandle;
48
49 /**
50 * Creates YANG java enumeration object.
51 */
52 public YangJavaEnumeration() {
53 super();
54 setJavaFileInfo(new JavaFileInfo());
Bharat saraswald72411a2016-04-19 01:00:16 +053055 getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
56 }
57
58 /**
59 * Returns the generated java file information.
60 *
61 * @return generated java file information
62 */
63 @Override
64 public JavaFileInfo getJavaFileInfo() {
65
66 if (javaFileInfo == null) {
67 throw new TranslatorException("Missing java info in java datamodel node");
68 }
69 return javaFileInfo;
70 }
71
72 /**
73 * Sets the java file info object.
74 *
75 * @param javaInfo java file info object
76 */
77 @Override
78 public void setJavaFileInfo(JavaFileInfo javaInfo) {
79
80 javaFileInfo = javaInfo;
81 }
82
83 /**
Bharat saraswald72411a2016-04-19 01:00:16 +053084 * Returns the temporary file handle.
85 *
86 * @return temporary file handle
87 */
88 @Override
89 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
90
91 return tempFileHandle;
92 }
93
94 /**
95 * Sets temporary file handle.
96 *
97 * @param fileHandle temporary file handle
98 */
99 @Override
100 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
101
102 tempFileHandle = fileHandle;
103 }
104
105 /**
106 * Prepare the information for java code generation corresponding to YANG
107 * enumeration info.
108 *
109 * @param yangPlugin YANG plugin config
110 * @throws IOException IO operations fails
111 */
112 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530113 public void generateCodeEntry(YangPluginConfig yangPlugin)
114 throws IOException {
Gaurav Agrawal56527662016-04-20 15:49:17 +0530115 generateCodeOfNode(this, yangPlugin);
Bharat saraswald72411a2016-04-19 01:00:16 +0530116 }
117
118 /**
119 * Creates a java file using the YANG enumeration info.
120 *
121 * @throws IOException IO operation fail
122 */
123 @Override
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530124 public void generateCodeExit()
125 throws IOException {
Bharat saraswald72411a2016-04-19 01:00:16 +0530126 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
127 }
128
129}