Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 3804650 | 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 | |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 18 | import java.io.IOException; |
| 19 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.YangGrouping; |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 27 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 29 | |
| 30 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 31 | * Represents grouping information extended to support java code generation. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 32 | */ |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 33 | public class YangJavaGrouping |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 34 | extends YangGrouping |
| 35 | implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 36 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 37 | private static final long serialVersionUID = 806201628L; |
| 38 | |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 39 | /** |
| 40 | * Contains the information of the java file being generated. |
| 41 | */ |
| 42 | private JavaFileInfo javaFileInfo; |
| 43 | |
| 44 | /** |
| 45 | * File handle to maintain temporary java code fragments as per the code |
| 46 | * snippet types. |
| 47 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 48 | private transient TempJavaCodeFragmentFiles tempFileHandle; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 49 | |
| 50 | /** |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 51 | * Creates YANG Java grouping object. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 52 | */ |
| 53 | public YangJavaGrouping() { |
| 54 | super(); |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 55 | setJavaFileInfo(new JavaFileInfo()); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 56 | } |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Returns the generated java file information. |
| 60 | * |
| 61 | * @return generated java file information |
| 62 | */ |
| 63 | @Override |
| 64 | public JavaFileInfo getJavaFileInfo() { |
| 65 | if (javaFileInfo == null) { |
| 66 | throw new TranslatorException("Missing java info in java datamodel node"); |
| 67 | } |
| 68 | return javaFileInfo; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sets the java file info object. |
| 73 | * |
| 74 | * @param javaInfo java file info object |
| 75 | */ |
| 76 | @Override |
| 77 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
| 78 | javaFileInfo = javaInfo; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the temporary file handle. |
| 83 | * |
| 84 | * @return temporary file handle |
| 85 | */ |
| 86 | @Override |
| 87 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
| 88 | return tempFileHandle; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets temporary file handle. |
| 93 | * |
| 94 | * @param fileHandle temporary file handle |
| 95 | */ |
| 96 | @Override |
| 97 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
| 98 | tempFileHandle = fileHandle; |
| 99 | } |
| 100 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 101 | |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 102 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 103 | public void generateCodeEntry(YangPluginConfig yangPlugin) |
| 104 | throws TranslatorException { |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 105 | try { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 106 | updatePackageInfo(this, yangPlugin); |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 107 | } catch (IOException e) { |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 108 | throw new TranslatorException(e.getCause()); |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 112 | @Override |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 113 | public void generateCodeExit() |
| 114 | throws TranslatorException { |
| 115 | /* |
| 116 | * Do nothing. |
| 117 | */ |
Bharat saraswal | cad0e65 | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 118 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 119 | } |