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