blob: 83e9f3be4d670add84887406a45def69ebcd2ff9 [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;
janani bde4ffab2016-04-15 16:18:30 +053030import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053031
32import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
33import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
34import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
35import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
36import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
37import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
38
39/**
Bharat saraswald9822e92016-04-05 15:13:44 +053040 * Represents notification information extended to support java code generation.
Vidyashree Rama506cbe12016-03-28 11:59:27 +053041 */
42public class YangJavaNotification extends YangNotification
43 implements JavaCodeGenerator, HasJavaFileInfo,
44 HasJavaImportData, HasTempJavaCodeFragmentFiles {
45
46 /**
47 * Contains information of the java file being generated.
48 */
49 private JavaFileInfo javaFileInfo;
50
51 /**
52 * Contains information of the imports to be inserted in the java file
53 * generated.
54 */
55 private JavaImportData javaImportData;
56
57 /**
58 * File handle to maintain temporary java code fragments as per the code
59 * snippet types.
60 */
61 private TempJavaCodeFragmentFiles tempFileHandle;
62
63 /**
64 * Creates an instance of java Notification.
65 */
66 public YangJavaNotification() {
67 super();
68 setJavaFileInfo(new JavaFileInfo());
69 setJavaImportData(new JavaImportData());
70 getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
71 }
72
73 /**
74 * Returns the generated java file information.
75 *
76 * @return generated java file information
77 */
78 @Override
79 public JavaFileInfo getJavaFileInfo() {
80
81 if (javaFileInfo == null) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +053082 throw new TranslatorException("Missing java info in java datamodel node");
Vidyashree Rama506cbe12016-03-28 11:59:27 +053083 }
84 return javaFileInfo;
85 }
86
87 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053088 * Sets the java file info object.
Vidyashree Rama506cbe12016-03-28 11:59:27 +053089 *
90 * @param javaInfo java file info object
91 */
92 @Override
93 public void setJavaFileInfo(JavaFileInfo javaInfo) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +053094 javaFileInfo = javaInfo;
95 }
96
97 /**
98 * Returns the data of java imports to be included in generated file.
99 *
100 * @return data of java imports to be included in generated file
101 */
102 @Override
103 public JavaImportData getJavaImportData() {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530104 return javaImportData;
105 }
106
107 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530108 * Sets the data of java imports to be included in generated file.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530109 *
110 * @param javaImportData data of java imports to be included in generated
111 * file
112 */
113 @Override
114 public void setJavaImportData(JavaImportData javaImportData) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530115 this.javaImportData = javaImportData;
116 }
117
118 /**
119 * Returns the temporary file handle.
120 *
121 * @return temporary file handle
122 */
123 @Override
124 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530125 return tempFileHandle;
126 }
127
128 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * Sets temporary file handle.
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530130 *
131 * @param fileHandle temporary file handle
132 */
133 @Override
134 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530135 tempFileHandle = fileHandle;
136 }
137
138 /**
139 * Prepare the information for java code generation corresponding to YANG
140 * notification info.
141 *
janani bde4ffab2016-04-15 16:18:30 +0530142 * @param yangPlugin YANG plugin config
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530143 * @throws IOException IO operation fail
144 */
145 @Override
janani bde4ffab2016-04-15 16:18:30 +0530146 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530147
janani bde4ffab2016-04-15 16:18:30 +0530148 getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530149 getJavaFileInfo().setPackage(getCurNodePackage(this));
150 getJavaFileInfo().setPackageFilePath(
151 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
janani bde4ffab2016-04-15 16:18:30 +0530152 getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
Vidyashree Rama506cbe12016-03-28 11:59:27 +0530153
154 String absolutePath = getAbsolutePackagePath(
155 getJavaFileInfo().getBaseCodeGenPath(),
156 getJavaFileInfo().getPackageFilePath());
157
158 setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
159 getJavaFileInfo().getGeneratedFileTypes(), absolutePath,
160 getJavaFileInfo().getJavaName()));
161
162 getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
163
164 getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
165 }
166
167 /**
168 * Create a java file using the YANG notification info.
169 */
170 @Override
171 public void generateCodeExit() {
172 // TODO Auto-generated method stub
173
174 }
175}