Vidyashree Rama | 506cbe1 | 2016-03-28 11:59: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 |
Vidyashree Rama | 506cbe1 | 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 | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 20 | |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.YangNotification; |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
| 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
janani b | de4ffab | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 27 | |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 31 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 32 | |
| 33 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 34 | * Represents notification information extended to support java code generation. |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 35 | */ |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 36 | public class YangJavaNotification |
| 37 | extends YangNotification |
| 38 | implements JavaCodeGenerator, JavaCodeGeneratorInfo { |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Contains information of the java file being generated. |
| 42 | */ |
| 43 | private JavaFileInfo javaFileInfo; |
| 44 | |
| 45 | /** |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 46 | * File handle to maintain temporary java code fragments as per the code |
| 47 | * snippet types. |
| 48 | */ |
| 49 | private TempJavaCodeFragmentFiles tempFileHandle; |
| 50 | |
| 51 | /** |
| 52 | * Creates an instance of java Notification. |
| 53 | */ |
| 54 | public YangJavaNotification() { |
| 55 | super(); |
| 56 | setJavaFileInfo(new JavaFileInfo()); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 57 | getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER |
| 58 | | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE); |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the generated java file information. |
| 63 | * |
| 64 | * @return generated java file information |
| 65 | */ |
| 66 | @Override |
| 67 | public JavaFileInfo getJavaFileInfo() { |
| 68 | |
| 69 | if (javaFileInfo == null) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 70 | throw new TranslatorException("Missing java info in java datamodel node"); |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 71 | } |
| 72 | return javaFileInfo; |
| 73 | } |
| 74 | |
| 75 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 76 | * Sets the java file info object. |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 77 | * |
| 78 | * @param javaInfo java file info object |
| 79 | */ |
| 80 | @Override |
| 81 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 82 | javaFileInfo = javaInfo; |
| 83 | } |
| 84 | |
| 85 | /** |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 86 | * Returns the temporary file handle. |
| 87 | * |
| 88 | * @return temporary file handle |
| 89 | */ |
| 90 | @Override |
| 91 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 92 | return tempFileHandle; |
| 93 | } |
| 94 | |
| 95 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 96 | * Sets temporary file handle. |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 97 | * |
| 98 | * @param fileHandle temporary file handle |
| 99 | */ |
| 100 | @Override |
| 101 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 102 | tempFileHandle = fileHandle; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Prepare the information for java code generation corresponding to YANG |
| 107 | * notification info. |
| 108 | * |
janani b | de4ffab | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 109 | * @param yangPlugin YANG plugin config |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 110 | * @throws IOException IO operation fail |
| 111 | */ |
| 112 | @Override |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 113 | public void generateCodeEntry(YangPluginConfig yangPlugin) |
| 114 | throws IOException { |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 115 | |
Ray Milkey | 994c498 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 116 | /** |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 117 | * As part of the notification support the following files needs to be generated. |
| 118 | * 1) Subject of the notification(event), this is simple interface with builder class. |
| 119 | * 2) Event class extending "AbstractEvent" and defining event type enum. |
| 120 | * 3) Event listener interface extending "EventListener". |
| 121 | * |
| 122 | * The manager class needs to extend the ListenerRegistry. |
| 123 | */ |
Ray Milkey | 994c498 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 124 | |
| 125 | |
| 126 | // Generate subject of the notification(event), this is simple interface with builder class. |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 127 | generateCodeOfNode(this, yangPlugin); |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 131 | * Creates a java file using the YANG notification info. |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 132 | */ |
| 133 | @Override |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 134 | public void generateCodeExit() |
| 135 | throws IOException { |
Ray Milkey | 994c498 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 136 | /** |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 137 | * As part of the notification support the following files needs to be generated. |
| 138 | * 1) Subject of the notification(event), this is simple interface with builder class. |
| 139 | * 2) Event class extending "AbstractEvent" and defining event type enum. |
| 140 | * 3) Event listener interface extending "EventListener". |
| 141 | * |
| 142 | * The manager class needs to extend the "ListenerRegistry". |
| 143 | */ |
| 144 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER |
| 145 | | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this); |
Vidyashree Rama | 506cbe1 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 146 | |
| 147 | } |
| 148 | } |