Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
| 18 | |
| 19 | import java.io.IOException; |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 20 | |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.YangNotification; |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 24 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
| 25 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
| 26 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
| 27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 28 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 31 | |
| 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 37 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 38 | |
| 39 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 40 | * Represents notification information extended to support java code generation. |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 41 | */ |
| 42 | public 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 saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 82 | throw new TranslatorException("Missing java info in java datamodel node"); |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 83 | } |
| 84 | return javaFileInfo; |
| 85 | } |
| 86 | |
| 87 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 88 | * Sets the java file info object. |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 89 | * |
| 90 | * @param javaInfo java file info object |
| 91 | */ |
| 92 | @Override |
| 93 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 94 | 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 Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 104 | return javaImportData; |
| 105 | } |
| 106 | |
| 107 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 108 | * Sets the data of java imports to be included in generated file. |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 109 | * |
| 110 | * @param javaImportData data of java imports to be included in generated |
| 111 | * file |
| 112 | */ |
| 113 | @Override |
| 114 | public void setJavaImportData(JavaImportData javaImportData) { |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 115 | 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 Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 125 | return tempFileHandle; |
| 126 | } |
| 127 | |
| 128 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 129 | * Sets temporary file handle. |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 130 | * |
| 131 | * @param fileHandle temporary file handle |
| 132 | */ |
| 133 | @Override |
| 134 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 135 | tempFileHandle = fileHandle; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Prepare the information for java code generation corresponding to YANG |
| 140 | * notification info. |
| 141 | * |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 142 | * @param yangPlugin YANG plugin config |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 143 | * @throws IOException IO operation fail |
| 144 | */ |
| 145 | @Override |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 146 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 147 | |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 148 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver()))); |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 149 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
| 150 | getJavaFileInfo().setPackageFilePath( |
| 151 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 152 | getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 153 | |
| 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 | } |