blob: bfa9dc19b082c3cc08fa3954948f3abad689ade6 [file] [log] [blame]
Vidyashree Rama506cbe12016-03-28 11:59:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vidyashree Rama506cbe12016-03-28 11:59:27 +05303 *
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;
Bharat saraswald9822e92016-04-05 15:13:44 +053020
Vidyashree Rama506cbe12016-03-28 11:59:27 +053021import org.onosproject.yangutils.datamodel.YangNotification;
Bharat saraswald9822e92016-04-05 15:13:44 +053022import org.onosproject.yangutils.translator.exception.TranslatorException;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053023import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
24import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
25import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
26import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
27import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
28import org.onosproject.yangutils.translator.tojava.JavaImportData;
29import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
30
31import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
32import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
33import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
34import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
35import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
36import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
37
38/**
Bharat saraswald9822e92016-04-05 15:13:44 +053039 * Represents notification information extended to support java code generation.
Vidyashree Rama506cbe12016-03-28 11:59:27 +053040 */
41public class YangJavaNotification extends YangNotification
42 implements JavaCodeGenerator, HasJavaFileInfo,
43 HasJavaImportData, HasTempJavaCodeFragmentFiles {
44
45 /**
46 * Contains information of the java file being generated.
47 */
48 private JavaFileInfo javaFileInfo;
49
50 /**
51 * Contains information of the imports to be inserted in the java file
52 * generated.
53 */
54 private JavaImportData javaImportData;
55
56 /**
57 * File handle to maintain temporary java code fragments as per the code
58 * snippet types.
59 */
60 private TempJavaCodeFragmentFiles tempFileHandle;
61
62 /**
63 * Creates an instance of java Notification.
64 */
65 public YangJavaNotification() {
66 super();
67 setJavaFileInfo(new JavaFileInfo());
68 setJavaImportData(new JavaImportData());
69 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
70 }
71
72 /**
73 * Returns the generated java file information.
74 *
75 * @return generated java file information
76 */
77 @Override
78 public JavaFileInfo getJavaFileInfo() {
79
80 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053081 throw new TranslatorException("Missing java info in java datamodel node");
Vidyashree Rama506cbe12016-03-28 11:59:27 +053082 }
83 return javaFileInfo;
84 }
85
86 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * Sets the java file info object.
Vidyashree Rama506cbe12016-03-28 11:59:27 +053088 *
89 * @param javaInfo java file info object
90 */
91 @Override
92 public void setJavaFileInfo(JavaFileInfo javaInfo) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +053093 javaFileInfo = javaInfo;
94 }
95
96 /**
97 * Returns the data of java imports to be included in generated file.
98 *
99 * @return data of java imports to be included in generated file
100 */
101 @Override
102 public JavaImportData getJavaImportData() {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530103 return javaImportData;
104 }
105
106 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530107 * Sets the data of java imports to be included in generated file.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530108 *
109 * @param javaImportData data of java imports to be included in generated
110 * file
111 */
112 @Override
113 public void setJavaImportData(JavaImportData javaImportData) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530114 this.javaImportData = javaImportData;
115 }
116
117 /**
118 * Returns the temporary file handle.
119 *
120 * @return temporary file handle
121 */
122 @Override
123 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530124 return tempFileHandle;
125 }
126
127 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530128 * Sets temporary file handle.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530129 *
130 * @param fileHandle temporary file handle
131 */
132 @Override
133 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530134 tempFileHandle = fileHandle;
135 }
136
137 /**
138 * Prepare the information for java code generation corresponding to YANG
139 * notification info.
140 *
141 * @param codeGenDir code generation directory
142 * @throws IOException IO operation fail
143 */
144 @Override
145 public void generateCodeEntry(String codeGenDir) throws IOException {
146
147 getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
148 getJavaFileInfo().setPackage(getCurNodePackage(this));
149 getJavaFileInfo().setPackageFilePath(
150 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
151 getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
152
153 String absolutePath = getAbsolutePackagePath(
154 getJavaFileInfo().getBaseCodeGenPath(),
155 getJavaFileInfo().getPackageFilePath());
156
157 setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
158 getJavaFileInfo().getGeneratedFileTypes(), absolutePath,
159 getJavaFileInfo().getJavaName()));
160
161 getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
162
163 getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
164 }
165
166 /**
167 * Create a java file using the YANG notification info.
168 */
169 @Override
170 public void generateCodeExit() {
171 // TODO Auto-generated method stub
172
173 }
174}