Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30: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 |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30: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 | package org.onosproject.yangutils.translator.tojava.javamodel; |
| 17 | |
| 18 | import java.io.IOException; |
| 19 | |
| 20 | import org.onosproject.yangutils.datamodel.YangAugment; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
| 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
| 25 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
| 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 27 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 29 | |
| 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 35 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 36 | |
| 37 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 38 | * Represents augment information extended to support java code generation. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 39 | */ |
| 40 | public class YangJavaAugment extends YangAugment |
| 41 | implements JavaCodeGenerator, HasJavaFileInfo, |
| 42 | HasJavaImportData, HasTempJavaCodeFragmentFiles { |
| 43 | |
| 44 | /** |
| 45 | * Contains the information of the java file being generated. |
| 46 | */ |
| 47 | private JavaFileInfo javaFileInfo; |
| 48 | |
| 49 | /** |
| 50 | * Contains information of the imports to be inserted in the java file |
| 51 | * generated. |
| 52 | */ |
| 53 | private JavaImportData javaImportData; |
| 54 | |
| 55 | /** |
| 56 | * File handle to maintain temporary java code fragments as per the code |
| 57 | * snippet types. |
| 58 | */ |
| 59 | private TempJavaCodeFragmentFiles tempFileHandle; |
| 60 | |
| 61 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 62 | * Creates a YANG java augment object. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 63 | */ |
| 64 | public YangJavaAugment() { |
| 65 | super(); |
| 66 | setJavaFileInfo(new JavaFileInfo()); |
| 67 | setJavaImportData(new JavaImportData()); |
| 68 | getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); |
| 69 | } |
| 70 | |
| 71 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 72 | * Returns the generated java file information. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 73 | * |
| 74 | * @return generated java file information |
| 75 | */ |
| 76 | @Override |
| 77 | public JavaFileInfo getJavaFileInfo() { |
| 78 | |
| 79 | if (javaFileInfo == null) { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 80 | throw new TranslatorException("Missing java info in java datamodel node"); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 81 | } |
| 82 | return javaFileInfo; |
| 83 | } |
| 84 | |
| 85 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 86 | * Sets the java file info object. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 87 | * |
| 88 | * @param javaInfo java file info object |
| 89 | */ |
| 90 | @Override |
| 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 92 | javaFileInfo = javaInfo; |
| 93 | } |
| 94 | |
| 95 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 96 | * Returns the data of java imports to be included in generated file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 97 | * |
| 98 | * @return data of java imports to be included in generated file |
| 99 | */ |
| 100 | @Override |
| 101 | public JavaImportData getJavaImportData() { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 102 | return javaImportData; |
| 103 | } |
| 104 | |
| 105 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 106 | * Sets the data of java imports to be included in generated file. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 107 | * |
| 108 | * @param javaImportData data of java imports to be included in generated |
| 109 | * file |
| 110 | */ |
| 111 | @Override |
| 112 | public void setJavaImportData(JavaImportData javaImportData) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 113 | this.javaImportData = javaImportData; |
| 114 | } |
| 115 | |
| 116 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 117 | * Returns the temporary file handle. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 118 | * |
| 119 | * @return temporary file handle |
| 120 | */ |
| 121 | @Override |
| 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 123 | return tempFileHandle; |
| 124 | } |
| 125 | |
| 126 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 127 | * Sets temporary file handle. |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 128 | * |
| 129 | * @param fileHandle temporary file handle |
| 130 | */ |
| 131 | @Override |
| 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 133 | tempFileHandle = fileHandle; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Prepare the information for java code generation corresponding to YANG |
| 138 | * augment info. |
| 139 | * |
| 140 | * @param codeGenDir code generation directory |
| 141 | * @throws IOException IO operation fail |
| 142 | */ |
| 143 | @Override |
| 144 | public void generateCodeEntry(String codeGenDir) throws IOException { |
| 145 | |
| 146 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
| 147 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
| 148 | getJavaFileInfo().setPackageFilePath( |
| 149 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
| 150 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); |
| 151 | |
| 152 | String absloutePath = getAbsolutePackagePath( |
| 153 | getJavaFileInfo().getBaseCodeGenPath(), |
| 154 | getJavaFileInfo().getPackageFilePath()); |
| 155 | |
| 156 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( |
| 157 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, |
| 158 | getJavaFileInfo().getJavaName())); |
| 159 | |
| 160 | getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); |
| 161 | |
| 162 | getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Create a java file using the YANG grouping info. |
| 167 | */ |
| 168 | @Override |
| 169 | public void generateCodeExit() { |
| 170 | // TODO Auto-generated method stub |
| 171 | |
| 172 | } |
| 173 | } |