Gaurav Agrawal
Committed by Thomas Vachuska

[ONOS-4302] RPC translator implementation

Change-Id: I457f12a2b0edaadee5ff888e0297b40854d53096
Showing 29 changed files with 710 additions and 161 deletions
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
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.datamodel;
18 +
19 +/**
20 + * Represents class having rpc and notification.
21 + */
22 +public interface HasRpcNotification {
23 +}
...@@ -17,7 +17,6 @@ package org.onosproject.yangutils.datamodel; ...@@ -17,7 +17,6 @@ package org.onosproject.yangutils.datamodel;
17 17
18 import java.util.LinkedList; 18 import java.util.LinkedList;
19 import java.util.List; 19 import java.util.List;
20 -
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
...@@ -69,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi ...@@ -69,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
69 * Represents data model node to maintain information defined in YANG module. 68 * Represents data model node to maintain information defined in YANG module.
70 */ 69 */
71 public class YangModule extends YangNode 70 public class YangModule extends YangNode
72 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo { 71 + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo,
72 + HasRpcNotification {
73 73
74 /** 74 /**
75 * Name of the module. 75 * Name of the module.
......
...@@ -17,7 +17,6 @@ package org.onosproject.yangutils.datamodel; ...@@ -17,7 +17,6 @@ package org.onosproject.yangutils.datamodel;
17 17
18 import java.util.LinkedList; 18 import java.util.LinkedList;
19 import java.util.List; 19 import java.util.List;
20 -
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
...@@ -72,11 +71,13 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi ...@@ -72,11 +71,13 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
72 * | YANG-version | 7.1.2 | 0..1 | - int | 71 * | YANG-version | 7.1.2 | 0..1 | - int |
73 * +--------------+---------+-------------+------------------+ 72 * +--------------+---------+-------------+------------------+
74 */ 73 */
74 +
75 /** 75 /**
76 * Represents data model node to maintain information defined in YANG sub-module. 76 * Represents data model node to maintain information defined in YANG sub-module.
77 */ 77 */
78 public class YangSubModule extends YangNode 78 public class YangSubModule extends YangNode
79 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo { 79 + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo,
80 + HasRpcNotification {
80 81
81 /** 82 /**
82 * Name of sub module. 83 * Name of sub module.
...@@ -183,6 +184,7 @@ public class YangSubModule extends YangNode ...@@ -183,6 +184,7 @@ public class YangSubModule extends YangNode
183 * sub-statements of each ancestor statement. 184 * sub-statements of each ancestor statement.
184 */ 185 */
185 private List<YangResolutionInfo> unresolvedResolutionList; 186 private List<YangResolutionInfo> unresolvedResolutionList;
187 +
186 /** 188 /**
187 * Creates a sub module node. 189 * Creates a sub module node.
188 */ 190 */
......
...@@ -31,10 +31,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc ...@@ -31,10 +31,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
34 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; 37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
37 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
39 import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; 39 import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
40 40
...@@ -65,7 +65,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; ...@@ -65,7 +65,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
65 */ 65 */
66 public final class InputListener { 66 public final class InputListener {
67 67
68 - private static final String INPUT_KEYWORD = "Input"; 68 + private static final String INPUT_KEYWORD = "_input";
69 69
70 /** 70 /**
71 * Creates a new input listener. 71 * Creates a new input listener.
...@@ -78,10 +78,10 @@ public final class InputListener { ...@@ -78,10 +78,10 @@ public final class InputListener {
78 * (input), performs validation and updates the data model tree. 78 * (input), performs validation and updates the data model tree.
79 * 79 *
80 * @param listener listener's object 80 * @param listener listener's object
81 - * @param ctx context object of the grammar rule 81 + * @param ctx context object of the grammar rule
82 */ 82 */
83 public static void processInputEntry(TreeWalkListener listener, 83 public static void processInputEntry(TreeWalkListener listener,
84 - GeneratedYangParser.InputStatementContext ctx) { 84 + GeneratedYangParser.InputStatementContext ctx) {
85 85
86 // Check for stack to be non empty. 86 // Check for stack to be non empty.
87 checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY); 87 checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY);
...@@ -110,10 +110,10 @@ public final class InputListener { ...@@ -110,10 +110,10 @@ public final class InputListener {
110 * validations and updates the data model tree. 110 * validations and updates the data model tree.
111 * 111 *
112 * @param listener listener's object 112 * @param listener listener's object
113 - * @param ctx context object of the grammar rule 113 + * @param ctx context object of the grammar rule
114 */ 114 */
115 public static void processInputExit(TreeWalkListener listener, 115 public static void processInputExit(TreeWalkListener listener,
116 - GeneratedYangParser.InputStatementContext ctx) { 116 + GeneratedYangParser.InputStatementContext ctx) {
117 117
118 // Check for stack to be non empty. 118 // Check for stack to be non empty.
119 checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", EXIT); 119 checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", EXIT);
......
...@@ -31,7 +31,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc ...@@ -31,7 +31,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
34 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*; 34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
36 import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; 39 import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
37 40
...@@ -62,7 +65,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; ...@@ -62,7 +65,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
62 */ 65 */
63 public final class OutputListener { 66 public final class OutputListener {
64 67
65 - private static final String OUTPUT_KEYWORD = "Output"; 68 + private static final String OUTPUT_KEYWORD = "_output";
66 69
67 /** 70 /**
68 * Creates a new output listener. 71 * Creates a new output listener.
...@@ -75,10 +78,10 @@ public final class OutputListener { ...@@ -75,10 +78,10 @@ public final class OutputListener {
75 * (output), performs validation and updates the data model tree. 78 * (output), performs validation and updates the data model tree.
76 * 79 *
77 * @param listener listener's object 80 * @param listener listener's object
78 - * @param ctx context object of the grammar rule 81 + * @param ctx context object of the grammar rule
79 */ 82 */
80 public static void processOutputEntry(TreeWalkListener listener, 83 public static void processOutputEntry(TreeWalkListener listener,
81 - GeneratedYangParser.OutputStatementContext ctx) { 84 + GeneratedYangParser.OutputStatementContext ctx) {
82 85
83 // Check for stack to be non empty. 86 // Check for stack to be non empty.
84 checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY); 87 checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY);
...@@ -107,10 +110,10 @@ public final class OutputListener { ...@@ -107,10 +110,10 @@ public final class OutputListener {
107 * validations and updates the data model tree. 110 * validations and updates the data model tree.
108 * 111 *
109 * @param listener listener's object 112 * @param listener listener's object
110 - * @param ctx context object of the grammar rule 113 + * @param ctx context object of the grammar rule
111 */ 114 */
112 public static void processOutputExit(TreeWalkListener listener, 115 public static void processOutputExit(TreeWalkListener listener,
113 - GeneratedYangParser.OutputStatementContext ctx) { 116 + GeneratedYangParser.OutputStatementContext ctx) {
114 117
115 // Check for stack to be non empty. 118 // Check for stack to be non empty.
116 checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", EXIT); 119 checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", EXIT);
......
...@@ -47,14 +47,16 @@ public final class GeneratedJavaFileType { ...@@ -47,14 +47,16 @@ public final class GeneratedJavaFileType {
47 public static final int GENERATE_INTERFACE_WITH_BUILDER = 15; 47 public static final int GENERATE_INTERFACE_WITH_BUILDER = 15;
48 48
49 /** 49 /**
50 - * Java class corresponding to typedef. 50 + * Java interface corresponding to rpc.
51 */ 51 */
52 - public static final int GENERATE_TYPEDEF_CLASS = 16; 52 + public static final int GENERATE_RPC_INTERFACE = 16;
53 53
54 /** 54 /**
55 - * Java class corresponding to union. 55 + * Interface, class file and rpc.
56 */ 56 */
57 - public static final int GENERATE_UNION_CLASS = 32; 57 + public static final int GENERATE_MANAGER_WITH_RPC = 31;
58 +
59 + // TODO RPC implementation to be integrated with notification.
58 60
59 /** 61 /**
60 * Java class corresponding to YANG enumeration. 62 * Java class corresponding to YANG enumeration.
...@@ -62,6 +64,16 @@ public final class GeneratedJavaFileType { ...@@ -62,6 +64,16 @@ public final class GeneratedJavaFileType {
62 public static final int GENERATE_ENUM_CLASS = 64; 64 public static final int GENERATE_ENUM_CLASS = 64;
63 65
64 /** 66 /**
67 + * Java class corresponding to typedef.
68 + */
69 + public static final int GENERATE_TYPEDEF_CLASS = 1024;
70 +
71 + /**
72 + * Java class corresponding to union.
73 + */
74 + public static final int GENERATE_UNION_CLASS = 2048;
75 +
76 + /**
65 * Creates an instance of generate java file type. 77 * Creates an instance of generate java file type.
66 */ 78 */
67 private GeneratedJavaFileType() { 79 private GeneratedJavaFileType() {
......
...@@ -79,7 +79,7 @@ public final class GeneratedTempFileType { ...@@ -79,7 +79,7 @@ public final class GeneratedTempFileType {
79 /** 79 /**
80 * From string implementation of class. 80 * From string implementation of class.
81 */ 81 */
82 - public static final int UNION_FROM_STRING_IMPL_MASK = 2048; 82 + public static final int FROM_STRING_IMPL_MASK = 2048;
83 83
84 /** 84 /**
85 * Enum implementation of class. 85 * Enum implementation of class.
...@@ -87,6 +87,11 @@ public final class GeneratedTempFileType { ...@@ -87,6 +87,11 @@ public final class GeneratedTempFileType {
87 public static final int ENUM_IMPL_MASK = 4096; 87 public static final int ENUM_IMPL_MASK = 4096;
88 88
89 /** 89 /**
90 + * Rpc implementation of class.
91 + */
92 + public static final int RPC_IMPL_MASK = 8192;
93 +
94 + /**
90 * Creates an instance of generated temp file type. 95 * Creates an instance of generated temp file type.
91 */ 96 */
92 private GeneratedTempFileType() { 97 private GeneratedTempFileType() {
......
...@@ -127,11 +127,11 @@ public final class JavaAttributeInfo { ...@@ -127,11 +127,11 @@ public final class JavaAttributeInfo {
127 * Creates an attribute info object corresponding to the passed enumeration attribute 127 * Creates an attribute info object corresponding to the passed enumeration attribute
128 * information and return it. 128 * information and return it.
129 * 129 *
130 - * @param curNode current data model node for which the java file is being 130 + * @param curNode current data model node for which the java file is being
131 - * generated 131 + * generated
132 * @param attributeName attribute name 132 * @param attributeName attribute name
133 * @return AttributeInfo attribute details required to add in temporary 133 * @return AttributeInfo attribute details required to add in temporary
134 - * files 134 + * files
135 */ 135 */
136 public static JavaAttributeInfo getAttributeInfoOfEnumAttribute(YangNode curNode, String attributeName) { 136 public static JavaAttributeInfo getAttributeInfoOfEnumAttribute(YangNode curNode, String attributeName) {
137 137
...@@ -146,6 +146,7 @@ public final class JavaAttributeInfo { ...@@ -146,6 +146,7 @@ public final class JavaAttributeInfo {
146 146
147 return getAttributeInfoForTheData(qualifiedTypeInfo, attributeName, null, curNode, false); 147 return getAttributeInfoForTheData(qualifiedTypeInfo, attributeName, null, curNode, false);
148 } 148 }
149 +
149 /** 150 /**
150 * Returns the data type info of attribute. 151 * Returns the data type info of attribute.
151 * 152 *
...@@ -302,6 +303,30 @@ public final class JavaAttributeInfo { ...@@ -302,6 +303,30 @@ public final class JavaAttributeInfo {
302 } 303 }
303 304
304 /** 305 /**
306 + * Creates an attribute info object corresponding to a data model node and
307 + * return it.
308 + *
309 + * @param parentNode parent node in which the current node is an attribute
310 + * @param isListNode is the current added attribute needs to be a list
311 + * @param curNodeName is the current added attribute needs to be a list
312 + * @return AttributeInfo attribute details required to add in temporary
313 + * files
314 + */
315 + public static JavaAttributeInfo getCurNodeAsAttributeInParent(YangNode parentNode, boolean isListNode,
316 + String curNodeName) {
317 +
318 + /*
319 + * Get the import info corresponding to the attribute for import in
320 + * generated java files or qualified access
321 + */
322 + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
323 + curNodeName, isListNode);
324 +
325 + return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, parentNode, isListNode);
326 + }
327 +
328 +
329 + /**
305 * Returns java attribute info. 330 * Returns java attribute info.
306 * 331 *
307 * @param importInfo java qualified type info 332 * @param importInfo java qualified type info
......
...@@ -169,7 +169,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> ...@@ -169,7 +169,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
169 } 169 }
170 170
171 /** 171 /**
172 - * Get the java qualified type information for the wrapper classes. 172 + * Returns the java qualified type information for the wrapper classes.
173 * 173 *
174 * @param referredTypesAttrInfo attribute of referred type 174 * @param referredTypesAttrInfo attribute of referred type
175 * @return return the import info for this attribute 175 * @return return the import info for this attribute
......
...@@ -21,7 +21,6 @@ import java.io.IOException; ...@@ -21,7 +21,6 @@ import java.io.IOException;
21 import java.util.ArrayList; 21 import java.util.ArrayList;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Set; 23 import java.util.Set;
24 -
25 import org.onosproject.yangutils.datamodel.HasType; 24 import org.onosproject.yangutils.datamodel.HasType;
26 import org.onosproject.yangutils.datamodel.YangEnum; 25 import org.onosproject.yangutils.datamodel.YangEnum;
27 import org.onosproject.yangutils.datamodel.YangEnumeration; 26 import org.onosproject.yangutils.datamodel.YangEnumeration;
...@@ -36,6 +35,7 @@ import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; ...@@ -36,6 +35,7 @@ import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
38 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -45,14 +45,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -45,14 +45,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
48 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; 51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; 52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
53 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
52 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; 54 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
53 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 55 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
54 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 56 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
55 -import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
56 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute; 57 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute;
57 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; 58 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf;
58 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType; 59 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType;
...@@ -66,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato ...@@ -66,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
66 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; 67 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
67 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; 68 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
68 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; 69 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
70 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateRpcInterfaceFile;
69 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; 71 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
70 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; 72 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
71 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; 73 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
...@@ -85,6 +87,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -85,6 +87,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
85 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; 87 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
86 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; 88 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
87 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; 89 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
90 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcStringMethod;
88 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; 91 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
89 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; 92 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
90 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; 93 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
...@@ -109,9 +112,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; ...@@ -109,9 +112,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
109 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 112 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
110 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 113 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
111 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; 114 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
112 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
113 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 115 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
114 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; 116 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
117 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
118 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
115 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; 119 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
116 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 120 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
117 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; 121 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
...@@ -226,7 +230,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -226,7 +230,7 @@ public class TempJavaCodeFragmentFiles {
226 /** 230 /**
227 * File name for from string method. 231 * File name for from string method.
228 */ 232 */
229 - private static final String UNION_FROM_STRING_METHOD_FILE_NAME = "UnionFromString"; 233 + private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
230 234
231 /** 235 /**
232 * File name for interface java file name suffix. 236 * File name for interface java file name suffix.
...@@ -259,6 +263,16 @@ public class TempJavaCodeFragmentFiles { ...@@ -259,6 +263,16 @@ public class TempJavaCodeFragmentFiles {
259 private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; 263 private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
260 264
261 /** 265 /**
266 + * File name for rpc method.
267 + */
268 + private static final String RPC_FILE_NAME = "Rpc";
269 +
270 + /**
271 + * File name for generated class file for special type like union, typedef suffix.
272 + */
273 + private static final String RPC_INTERFACE_FILE_NAME_SUFFIX = "Service";
274 +
275 + /**
262 * File name for generated class file for special type like union, typedef suffix. 276 * File name for generated class file for special type like union, typedef suffix.
263 */ 277 */
264 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; 278 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
...@@ -354,9 +368,19 @@ public class TempJavaCodeFragmentFiles { ...@@ -354,9 +368,19 @@ public class TempJavaCodeFragmentFiles {
354 private File constructorForTypeTempFileHandle; 368 private File constructorForTypeTempFileHandle;
355 369
356 /** 370 /**
357 - * Temporary file handle for union's from string method of class. 371 + * Temporary file handle for from string method of class.
372 + */
373 + private File fromStringImplTempFileHandle;
374 +
375 + /**
376 + * Temporary file handle for rpc interface.
377 + */
378 + private File rpcInterfaceImplTempFileHandle;
379 +
380 + /**
381 + * Java file handle for rpc interface file.
358 */ 382 */
359 - private File unionFromStringImplTempFileHandle; 383 + private File rpcInterfaceJavaFileHandle;
360 384
361 /** 385 /**
362 * Java attribute info. 386 * Java attribute info.
...@@ -439,6 +463,10 @@ public class TempJavaCodeFragmentFiles { ...@@ -439,6 +463,10 @@ public class TempJavaCodeFragmentFiles {
439 generatedTempFiles |= TO_STRING_IMPL_MASK; 463 generatedTempFiles |= TO_STRING_IMPL_MASK;
440 } 464 }
441 465
466 + if ((genFileType & GENERATE_RPC_INTERFACE) != 0) {
467 + generatedTempFiles |= RPC_IMPL_MASK;
468 + }
469 +
442 /** 470 /**
443 * Initialize getterImpl, attributes, hash code, equals and 471 * Initialize getterImpl, attributes, hash code, equals and
444 * to strings when generation file type matches to typeDef class mask. 472 * to strings when generation file type matches to typeDef class mask.
...@@ -451,11 +479,12 @@ public class TempJavaCodeFragmentFiles { ...@@ -451,11 +479,12 @@ public class TempJavaCodeFragmentFiles {
451 generatedTempFiles |= TO_STRING_IMPL_MASK; 479 generatedTempFiles |= TO_STRING_IMPL_MASK;
452 generatedTempFiles |= OF_STRING_IMPL_MASK; 480 generatedTempFiles |= OF_STRING_IMPL_MASK;
453 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; 481 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
482 + generatedTempFiles |= FROM_STRING_IMPL_MASK;
454 } 483 }
455 484
456 /** 485 /**
457 * Initialize getterImpl, attributes, hash code, equals, of string, 486 * Initialize getterImpl, attributes, hash code, equals, of string,
458 - * constructor, union's to string, union's from string when generation 487 + * constructor, union's to string, from string when generation
459 * file type matches to union class mask. 488 * file type matches to union class mask.
460 */ 489 */
461 if ((genFileType & GENERATE_UNION_CLASS) != 0) { 490 if ((genFileType & GENERATE_UNION_CLASS) != 0) {
...@@ -466,7 +495,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -466,7 +495,7 @@ public class TempJavaCodeFragmentFiles {
466 generatedTempFiles |= OF_STRING_IMPL_MASK; 495 generatedTempFiles |= OF_STRING_IMPL_MASK;
467 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; 496 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
468 generatedTempFiles |= TO_STRING_IMPL_MASK; 497 generatedTempFiles |= TO_STRING_IMPL_MASK;
469 - generatedTempFiles |= UNION_FROM_STRING_IMPL_MASK; 498 + generatedTempFiles |= FROM_STRING_IMPL_MASK;
470 } 499 }
471 /** 500 /**
472 * Initialize enum when generation file type matches to enum class mask. 501 * Initialize enum when generation file type matches to enum class mask.
...@@ -523,8 +552,12 @@ public class TempJavaCodeFragmentFiles { ...@@ -523,8 +552,12 @@ public class TempJavaCodeFragmentFiles {
523 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); 552 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
524 } 553 }
525 554
526 - if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { 555 + if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
527 - setUnionFromStringImplTempFileHandle(getTemporaryFileHandle(UNION_FROM_STRING_METHOD_FILE_NAME)); 556 + setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
557 + }
558 +
559 + if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
560 + setRpcInterfaceImplTempFileHandle(getTemporaryFileHandle(RPC_FILE_NAME));
528 } 561 }
529 } 562 }
530 563
...@@ -800,6 +833,42 @@ public class TempJavaCodeFragmentFiles { ...@@ -800,6 +833,42 @@ public class TempJavaCodeFragmentFiles {
800 } 833 }
801 834
802 /** 835 /**
836 + * Returns rpc method's temporary file handle.
837 + *
838 + * @return temporary file handle
839 + */
840 + public File getRpcInterfaceImplTempFileHandle() {
841 + return rpcInterfaceImplTempFileHandle;
842 + }
843 +
844 + /**
845 + * Sets rpc method's temporary file handle.
846 + *
847 + * @param rpcInterfaceImplTempFileHandle file handle for to rpc method
848 + */
849 + public void setRpcInterfaceImplTempFileHandle(File rpcInterfaceImplTempFileHandle) {
850 + this.rpcInterfaceImplTempFileHandle = rpcInterfaceImplTempFileHandle;
851 + }
852 +
853 + /**
854 + * Returns rpc method's java file handle.
855 + *
856 + * @return java file handle
857 + */
858 + public File getRpcInterfaceJavaFileHandle() {
859 + return rpcInterfaceJavaFileHandle;
860 + }
861 +
862 + /**
863 + * Sets rpc method's java file handle.
864 + *
865 + * @param rpcInterfaceJavaFileHandle file handle for to rpc method
866 + */
867 + public void setRpcInterfaceJavaFileHandle(File rpcInterfaceJavaFileHandle) {
868 + this.rpcInterfaceJavaFileHandle = rpcInterfaceJavaFileHandle;
869 + }
870 +
871 + /**
803 * Returns to string method's temporary file handle. 872 * Returns to string method's temporary file handle.
804 * 873 *
805 * @return temporary file handle 874 * @return temporary file handle
...@@ -873,21 +942,21 @@ public class TempJavaCodeFragmentFiles { ...@@ -873,21 +942,21 @@ public class TempJavaCodeFragmentFiles {
873 } 942 }
874 943
875 /** 944 /**
876 - * Returns union's from string method's temporary file handle. 945 + * Returns from string method's temporary file handle.
877 * 946 *
878 - * @return union's from string method's temporary file handle 947 + * @return from string method's temporary file handle
879 */ 948 */
880 - public File getUnionFromStringImplTempFileHandle() { 949 + public File getFromStringImplTempFileHandle() {
881 - return unionFromStringImplTempFileHandle; 950 + return fromStringImplTempFileHandle;
882 } 951 }
883 952
884 /** 953 /**
885 - * Sets union's from string method's temporary file handle. 954 + * Sets from string method's temporary file handle.
886 * 955 *
887 - * @param unionFromStringImplTempFileHandle union's from string method's temporary file handle 956 + * @param fromStringImplTempFileHandle from string method's temporary file handle
888 */ 957 */
889 - private void setUnionFromStringImplTempFileHandle(File unionFromStringImplTempFileHandle) { 958 + private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
890 - this.unionFromStringImplTempFileHandle = unionFromStringImplTempFileHandle; 959 + this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
891 } 960 }
892 961
893 /** 962 /**
...@@ -1158,13 +1227,35 @@ public class TempJavaCodeFragmentFiles { ...@@ -1158,13 +1227,35 @@ public class TempJavaCodeFragmentFiles {
1158 * @param fromStringAttributeInfo from string attribute info 1227 * @param fromStringAttributeInfo from string attribute info
1159 * @throws IOException when fails to append to temporary file 1228 * @throws IOException when fails to append to temporary file
1160 */ 1229 */
1161 - private void addUnionFromStringMethod(JavaAttributeInfo javaAttributeInfo, 1230 + private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
1162 - JavaAttributeInfo fromStringAttributeInfo) throws IOException { 1231 + JavaAttributeInfo fromStringAttributeInfo) throws IOException {
1163 - appendToFile(getUnionFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, 1232 + appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
1164 fromStringAttributeInfo) + NEW_LINE); 1233 fromStringAttributeInfo) + NEW_LINE);
1165 } 1234 }
1166 1235
1167 /** 1236 /**
1237 + * Adds rpc string information to applicable temp file.
1238 + *
1239 + * @param javaAttributeInfoOfInput rpc's input node attribute info
1240 + * @param javaAttributeInfoOfOutput rpc's output node attribute info
1241 + * @param rpcName name of the rpc function
1242 + * @throws IOException IO operation fail
1243 + */
1244 + private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
1245 + String rpcName) throws IOException {
1246 + String rpcInput = "";
1247 + String rpcOutput = "void";
1248 + if (javaAttributeInfoOfInput != null) {
1249 + rpcInput = javaAttributeInfoOfInput.getAttributeName();
1250 + }
1251 + if (javaAttributeInfoOfOutput != null) {
1252 + rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
1253 + }
1254 + appendToFile(getRpcInterfaceImplTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
1255 + getRpcStringMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
1256 + }
1257 +
1258 + /**
1168 * Returns a temporary file handle for the specific file type. 1259 * Returns a temporary file handle for the specific file type.
1169 * 1260 *
1170 * @param fileName file name 1261 * @param fileName file name
...@@ -1416,13 +1507,29 @@ public class TempJavaCodeFragmentFiles { ...@@ -1416,13 +1507,29 @@ public class TempJavaCodeFragmentFiles {
1416 1507
1417 JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo); 1508 JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo);
1418 1509
1419 - if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { 1510 + if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1420 - addUnionFromStringMethod(javaAttributeInfo, fromStringAttributeInfo); 1511 + addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
1421 } 1512 }
1422 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 1513 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1423 } 1514 }
1424 1515
1425 /** 1516 /**
1517 + * Adds the JAVA rpc snippet information.
1518 + *
1519 + * @param javaAttributeInfoOfInput rpc's input node attribute info
1520 + * @param javaAttributeInfoOfOutput rpc's output node attribute info
1521 + * @param rpcName name of the rpc function
1522 + * @throws IOException IO operation fail
1523 + */
1524 + public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
1525 + JavaAttributeInfo javaAttributeInfoOfOutput,
1526 + String rpcName) throws IOException {
1527 + if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1528 + addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
1529 + }
1530 + }
1531 +
1532 + /**
1426 * Adds the new attribute info to the target generated temporary files. 1533 * Adds the new attribute info to the target generated temporary files.
1427 * 1534 *
1428 * @param newAttrInfo the attribute info that needs to be added to temporary 1535 * @param newAttrInfo the attribute info that needs to be added to temporary
...@@ -1642,6 +1749,14 @@ public class TempJavaCodeFragmentFiles { ...@@ -1642,6 +1749,14 @@ public class TempJavaCodeFragmentFiles {
1642 } 1749 }
1643 1750
1644 /** 1751 /**
1752 + * Creates rpc interface file.
1753 + */
1754 + if ((fileType & GENERATE_RPC_INTERFACE) != 0) {
1755 + setRpcInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(RPC_INTERFACE_FILE_NAME_SUFFIX)));
1756 + setRpcInterfaceJavaFileHandle(generateRpcInterfaceFile(getRpcInterfaceJavaFileHandle(), curNode, imports));
1757 + }
1758 +
1759 + /**
1645 * Close all the file handles. 1760 * Close all the file handles.
1646 */ 1761 */
1647 close(false); 1762 close(false);
...@@ -1681,6 +1796,9 @@ public class TempJavaCodeFragmentFiles { ...@@ -1681,6 +1796,9 @@ public class TempJavaCodeFragmentFiles {
1681 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) { 1796 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) {
1682 closeFile(getTypeClassJavaFileHandle(), isError); 1797 closeFile(getTypeClassJavaFileHandle(), isError);
1683 } 1798 }
1799 + if ((generatedJavaFiles & GENERATE_RPC_INTERFACE) != 0) {
1800 + closeFile(getRpcInterfaceJavaFileHandle(), isError);
1801 + }
1684 1802
1685 /** 1803 /**
1686 * Close all temporary file handles and delete the files. 1804 * Close all temporary file handles and delete the files.
...@@ -1721,11 +1839,13 @@ public class TempJavaCodeFragmentFiles { ...@@ -1721,11 +1839,13 @@ public class TempJavaCodeFragmentFiles {
1721 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { 1839 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1722 closeFile(getOfStringImplTempFileHandle(), true); 1840 closeFile(getOfStringImplTempFileHandle(), true);
1723 } 1841 }
1724 - if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { 1842 + if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1725 - closeFile(getUnionFromStringImplTempFileHandle(), true); 1843 + closeFile(getFromStringImplTempFileHandle(), true);
1844 + }
1845 + if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1846 + closeFile(getRpcInterfaceImplTempFileHandle(), true);
1726 } 1847 }
1727 clean(getTempDirPath()); 1848 clean(getTempDirPath());
1728 generatedTempFiles = 0; 1849 generatedTempFiles = 0;
1729 } 1850 }
1730 -
1731 } 1851 }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
17 package org.onosproject.yangutils.translator.tojava.javamodel; 17 package org.onosproject.yangutils.translator.tojava.javamodel;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 -
21 import org.onosproject.yangutils.datamodel.YangEnumeration; 20 import org.onosproject.yangutils.datamodel.YangEnumeration;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 21 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 22 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
...@@ -27,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -27,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
27 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 27
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
30 -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType; 29 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
31 30
32 /** 31 /**
33 * Represents YANG java enumeration information extended to support java code generation. 32 * Represents YANG java enumeration information extended to support java code generation.
...@@ -101,7 +100,7 @@ public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGene ...@@ -101,7 +100,7 @@ public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGene
101 * Sets the data of java imports to be included in generated file. 100 * Sets the data of java imports to be included in generated file.
102 * 101 *
103 * @param javaImportData data of java imports to be included in generated 102 * @param javaImportData data of java imports to be included in generated
104 - * file 103 + * file
105 */ 104 */
106 @Override 105 @Override
107 public void setJavaImportData(JavaImportData javaImportData) { 106 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -140,7 +139,7 @@ public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGene ...@@ -140,7 +139,7 @@ public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGene
140 */ 139 */
141 @Override 140 @Override
142 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 141 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
143 - generateCodeOfType(this, yangPlugin, false); 142 + generateCodeOfNode(this, yangPlugin);
144 } 143 }
145 144
146 /** 145 /**
......
...@@ -68,7 +68,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J ...@@ -68,7 +68,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
68 @Override 68 @Override
69 public JavaFileInfo getJavaFileInfo() { 69 public JavaFileInfo getJavaFileInfo() {
70 if (javaFileInfo == null) { 70 if (javaFileInfo == null) {
71 - throw new TranslatorException("Missing java info in java datamodel node"); 71 + throw new TranslatorException("missing java info in java datamodel node");
72 } 72 }
73 return javaFileInfo; 73 return javaFileInfo;
74 } 74 }
...@@ -97,7 +97,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J ...@@ -97,7 +97,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
97 * Sets the data of java imports to be included in generated file. 97 * Sets the data of java imports to be included in generated file.
98 * 98 *
99 * @param javaImportData data of java imports to be included in generated 99 * @param javaImportData data of java imports to be included in generated
100 - * file 100 + * file
101 */ 101 */
102 @Override 102 @Override
103 public void setJavaImportData(JavaImportData javaImportData) { 103 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -133,7 +133,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J ...@@ -133,7 +133,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
133 */ 133 */
134 @Override 134 @Override
135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
136 - generateCodeOfNode(this, yangPlugin, false); 136 + generateCodeOfNode(this, yangPlugin);
137 } 137 }
138 138
139 /** 139 /**
......
...@@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; 25 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 26 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 27
28 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
30 30
31 /** 31 /**
...@@ -57,7 +57,7 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, ...@@ -57,7 +57,7 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
57 super(); 57 super();
58 setJavaFileInfo(new JavaFileInfo()); 58 setJavaFileInfo(new JavaFileInfo());
59 setJavaImportData(new JavaImportData()); 59 setJavaImportData(new JavaImportData());
60 - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); 60 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
61 } 61 }
62 62
63 /** 63 /**
...@@ -97,7 +97,7 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, ...@@ -97,7 +97,7 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
97 * Sets the data of java imports to be included in generated file. 97 * Sets the data of java imports to be included in generated file.
98 * 98 *
99 * @param javaImportData data of java imports to be included in generated 99 * @param javaImportData data of java imports to be included in generated
100 - * file 100 + * file
101 */ 101 */
102 @Override 102 @Override
103 public void setJavaImportData(JavaImportData javaImportData) { 103 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -141,6 +141,6 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, ...@@ -141,6 +141,6 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
141 */ 141 */
142 @Override 142 @Override
143 public void generateCodeExit() throws IOException { 143 public void generateCodeExit() throws IOException {
144 - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); 144 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_MANAGER_WITH_RPC, this);
145 } 145 }
146 } 146 }
......
...@@ -68,7 +68,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, ...@@ -68,7 +68,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
68 @Override 68 @Override
69 public JavaFileInfo getJavaFileInfo() { 69 public JavaFileInfo getJavaFileInfo() {
70 if (javaFileInfo == null) { 70 if (javaFileInfo == null) {
71 - throw new TranslatorException("Missing java info in java datamodel node"); 71 + throw new TranslatorException("missing java info in java datamodel node");
72 } 72 }
73 return javaFileInfo; 73 return javaFileInfo;
74 } 74 }
...@@ -97,7 +97,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, ...@@ -97,7 +97,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
97 * Sets the data of java imports to be included in generated file. 97 * Sets the data of java imports to be included in generated file.
98 * 98 *
99 * @param javaImportData data of java imports to be included in generated 99 * @param javaImportData data of java imports to be included in generated
100 - * file 100 + * file
101 */ 101 */
102 @Override 102 @Override
103 public void setJavaImportData(JavaImportData javaImportData) { 103 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -133,7 +133,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, ...@@ -133,7 +133,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
133 */ 133 */
134 @Override 134 @Override
135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
136 - generateCodeOfNode(this, yangPlugin, false); 136 + generateCodeOfNode(this, yangPlugin);
137 } 137 }
138 138
139 /** 139 /**
......
...@@ -17,40 +17,132 @@ ...@@ -17,40 +17,132 @@
17 package org.onosproject.yangutils.translator.tojava.javamodel; 17 package org.onosproject.yangutils.translator.tojava.javamodel;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 +import org.onosproject.yangutils.datamodel.HasRpcNotification;
21 +import org.onosproject.yangutils.datamodel.YangInput;
22 +import org.onosproject.yangutils.datamodel.YangNode;
23 +import org.onosproject.yangutils.datamodel.YangOutput;
20 import org.onosproject.yangutils.datamodel.YangRpc; 24 import org.onosproject.yangutils.datamodel.YangRpc;
25 +import org.onosproject.yangutils.translator.exception.TranslatorException;
26 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
27 +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
28 +import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
21 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 29 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
30 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
22 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 31 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
23 32
33 +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
35 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
36 +
24 /** 37 /**
25 * Represents rpc information extended to support java code generation. 38 * Represents rpc information extended to support java code generation.
26 */ 39 */
27 -public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { 40 +public class YangJavaRpc extends YangRpc implements JavaCodeGenerator, HasJavaFileInfo {
41 +
42 + /**
43 + * Contains the information of the java file being generated.
44 + */
45 + private JavaFileInfo javaFileInfo;
28 46
29 /** 47 /**
30 - * Creates an instance of java Rpc. 48 + * Creates an instance of YANG java rpc.
31 */ 49 */
32 public YangJavaRpc() { 50 public YangJavaRpc() {
51 + super();
52 + setJavaFileInfo(new JavaFileInfo());
33 } 53 }
34 54
35 /** 55 /**
36 * Prepares the information for java code generation corresponding to YANG 56 * Prepares the information for java code generation corresponding to YANG
37 - * RPC info. 57 + * rpc info.
38 * 58 *
39 * @param yangPlugin YANG plugin config 59 * @param yangPlugin YANG plugin config
40 - * @throws IOException IO operation fail 60 + * @throws IOException IO operations fails
41 */ 61 */
42 @Override 62 @Override
43 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 63 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
44 - // TODO 64 +
65 + if (!(this instanceof YangNode)) {
66 + // TODO:throw exception
67 + }
68 +
69 + // Add package information for rpc and create corresponding folder.
70 + updatePackageInfo(this, yangPlugin);
71 +
72 + // Get the parent module/sub-module.
73 + YangNode parent = getParentNodeInGenCode((YangNode) this);
74 +
75 + // Parent should be holder of rpc or notification.
76 + if (!(parent instanceof HasRpcNotification)) {
77 + throw new TranslatorException("parent node of rpc can only be module or sub-module");
78 + }
79 +
80 + /*
81 + * Create attribute info for input and output of rpc and add it to the
82 + * parent import list.
83 + */
84 +
85 + JavaAttributeInfo javaAttributeInfoOfInput = null;
86 + JavaAttributeInfo javaAttributeInfoOfOutput = null;
87 +
88 + // Get the child input and output node and obtain create java attribute info.
89 + YangNode yangNode = this.getChild();
90 + while (yangNode != null) {
91 + if (yangNode instanceof YangInput) {
92 + javaAttributeInfoOfInput = getCurNodeAsAttributeInParent(parent, false, yangNode.getName());
93 + } else if (yangNode instanceof YangOutput) {
94 + javaAttributeInfoOfOutput = getCurNodeAsAttributeInParent(parent, false, yangNode.getName());
95 + } else {
96 + // TODO throw exception
97 + }
98 + yangNode = yangNode.getNextSibling();
99 + }
100 +
101 + if (!(parent instanceof HasTempJavaCodeFragmentFiles)) {
102 + throw new TranslatorException("missing parent temp file handle");
103 + }
104 +
105 + /*
106 + * Add the rpc information to the parent's service temp file.
107 + */
108 + ((HasTempJavaCodeFragmentFiles) parent)
109 + .getTempJavaCodeFragmentFiles()
110 + .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
111 + ((YangNode) this).getName());
45 } 112 }
46 113
47 /** 114 /**
48 - * Creates a java file using the YANG RPC info. 115 + * Creates a java file using the YANG rpc info.
49 * 116 *
50 - * @throws IOException IO operation fail 117 + * @throws IOException IO operations fails
51 */ 118 */
52 @Override 119 @Override
53 public void generateCodeExit() throws IOException { 120 public void generateCodeExit() throws IOException {
54 - // TODO 121 + // No file will be generated during RPC exit.
122 + }
123 +
124 + /**
125 + * Returns the generated java file information.
126 + *
127 + * @return generated java file information
128 + */
129 + @Override
130 + public JavaFileInfo getJavaFileInfo() {
131 +
132 + if (javaFileInfo == null) {
133 + throw new TranslatorException("missing java info in java datamodel node");
134 + }
135 + return javaFileInfo;
136 + }
137 +
138 + /**
139 + * Sets the java file info object.
140 + *
141 + * @param javaInfo java file info object
142 + */
143 + @Override
144 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
145 + javaFileInfo = javaInfo;
55 } 146 }
56 } 147 }
148 +
......
...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; 26 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
27 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 27 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 28
29 -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
31 31
32 /** 32 /**
...@@ -58,7 +58,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato ...@@ -58,7 +58,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
58 super(); 58 super();
59 setJavaFileInfo(new JavaFileInfo()); 59 setJavaFileInfo(new JavaFileInfo());
60 setJavaImportData(new JavaImportData()); 60 setJavaImportData(new JavaImportData());
61 - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); 61 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
62 } 62 }
63 63
64 /** 64 /**
...@@ -98,7 +98,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato ...@@ -98,7 +98,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
98 * Sets the data of java imports to be included in generated file. 98 * Sets the data of java imports to be included in generated file.
99 * 99 *
100 * @param javaImportData data of java imports to be included in generated 100 * @param javaImportData data of java imports to be included in generated
101 - * file 101 + * file
102 */ 102 */
103 @Override 103 @Override
104 public void setJavaImportData(JavaImportData javaImportData) { 104 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -129,7 +129,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato ...@@ -129,7 +129,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
129 * Returns the name space of the module to which the sub module belongs to. 129 * Returns the name space of the module to which the sub module belongs to.
130 * 130 *
131 * @param belongsToInfo Information of the module to which the sub module 131 * @param belongsToInfo Information of the module to which the sub module
132 - * belongs 132 + * belongs
133 * @return the name space string of the module. 133 * @return the name space string of the module.
134 */ 134 */
135 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { 135 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
...@@ -138,7 +138,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato ...@@ -138,7 +138,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
138 } 138 }
139 139
140 /** 140 /**
141 - * Prepare the information for java code generation corresponding to YANG 141 + * Prepares the information for java code generation corresponding to YANG
142 * submodule info. 142 * submodule info.
143 * 143 *
144 * @param yangPlugin YANG plugin config 144 * @param yangPlugin YANG plugin config
......
...@@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 25 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 26
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
28 -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType; 28 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
29 29
30 /** 30 /**
31 * Represents type define information extended to support java code generation. 31 * Represents type define information extended to support java code generation.
...@@ -133,7 +133,7 @@ public class YangJavaTypeDef extends YangTypeDef implements JavaCodeGeneratorInf ...@@ -133,7 +133,7 @@ public class YangJavaTypeDef extends YangTypeDef implements JavaCodeGeneratorInf
133 */ 133 */
134 @Override 134 @Override
135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
136 - generateCodeOfType(this, yangPlugin, false); 136 + generateCodeOfNode(this, yangPlugin, false);
137 } 137 }
138 138
139 /** 139 /**
......
...@@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
24 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 24 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 25
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
27 -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType; 27 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
28 28
29 /** 29 /**
30 * Represents union information extended to support java code generation. 30 * Represents union information extended to support java code generation.
...@@ -135,7 +135,7 @@ public class YangJavaUnion extends YangUnion implements JavaCodeGeneratorInfo, J ...@@ -135,7 +135,7 @@ public class YangJavaUnion extends YangUnion implements JavaCodeGeneratorInfo, J
135 */ 135 */
136 @Override 136 @Override
137 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 137 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
138 - generateCodeOfType(this, yangPlugin, false); 138 + generateCodeOfNode(this, yangPlugin);
139 } 139 }
140 140
141 /** 141 /**
......
...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
21 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 21 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
22 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
22 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 24 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
24 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 25 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -63,7 +64,7 @@ public final class ClassDefinitionGenerator { ...@@ -63,7 +64,7 @@ public final class ClassDefinitionGenerator {
63 public static String generateClassDefinition(int genFileTypes, String yangName) { 64 public static String generateClassDefinition(int genFileTypes, String yangName) {
64 65
65 /** 66 /**
66 - * based on the file type and the YANG name of the file, generate the 67 + * Based on the file type and the YANG name of the file, generate the
67 * class / interface definition start. 68 * class / interface definition start.
68 */ 69 */
69 if ((genFileTypes & INTERFACE_MASK) != 0) { 70 if ((genFileTypes & INTERFACE_MASK) != 0) {
...@@ -80,6 +81,8 @@ public final class ClassDefinitionGenerator { ...@@ -80,6 +81,8 @@ public final class ClassDefinitionGenerator {
80 return getTypeClassDefinition(yangName); 81 return getTypeClassDefinition(yangName);
81 } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) { 82 } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
82 return getEnumClassDefinition(yangName); 83 return getEnumClassDefinition(yangName);
84 + } else if ((genFileTypes & GENERATE_RPC_INTERFACE) != 0) {
85 + return getRpcInterfaceDefinition(yangName);
83 } 86 }
84 return null; 87 return null;
85 } 88 }
...@@ -88,7 +91,7 @@ public final class ClassDefinitionGenerator { ...@@ -88,7 +91,7 @@ public final class ClassDefinitionGenerator {
88 * Returns enum file class definition. 91 * Returns enum file class definition.
89 * 92 *
90 * @param yangName class name 93 * @param yangName class name
91 - * @return enum file class definiton 94 + * @return enum file class definition
92 */ 95 */
93 private static String getEnumClassDefinition(String yangName) { 96 private static String getEnumClassDefinition(String yangName) {
94 return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 97 return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
...@@ -155,4 +158,14 @@ public final class ClassDefinitionGenerator { ...@@ -155,4 +158,14 @@ public final class ClassDefinitionGenerator {
155 private static String getTypeClassDefinition(String yangName) { 158 private static String getTypeClassDefinition(String yangName) {
156 return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 159 return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
157 } 160 }
161 +
162 + /**
163 + * Returns rpc file interface definition.
164 + *
165 + * @param yangName file name
166 + * @return definition
167 + */
168 + private static String getRpcInterfaceDefinition(String yangName) {
169 + return INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
170 + }
158 } 171 }
......
...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; ...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
31 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -37,14 +38,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -37,14 +38,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
41 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
46 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
47 -import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
48 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; 50 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute;
49 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; 51 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
50 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute; 52 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
...@@ -78,9 +80,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; ...@@ -78,9 +80,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
78 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 80 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
79 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 81 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
80 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 82 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
81 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; 83 +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
82 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 84 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
83 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 85 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
86 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
84 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 87 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
85 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; 88 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString;
86 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 89 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
...@@ -180,7 +183,7 @@ public final class JavaFileGenerator { ...@@ -180,7 +183,7 @@ public final class JavaFileGenerator {
180 } 183 }
181 184
182 /** 185 /**
183 - * Return generated builder interface file for current node. 186 + * Returns generated builder interface file for current node.
184 * 187 *
185 * @param file file 188 * @param file file
186 * @param curNode current YANG node 189 * @param curNode current YANG node
...@@ -468,6 +471,13 @@ public final class JavaFileGenerator { ...@@ -468,6 +471,13 @@ public final class JavaFileGenerator {
468 methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) 471 methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode)
469 + getToStringMethodClose()); 472 + getToStringMethodClose());
470 473
474 + /**
475 + * From string method.
476 + */
477 + methods.add(getFromStringMethodSignature(className)
478 + + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, curNode)
479 + + getFromStringMethodClose());
480 +
471 } catch (IOException e) { 481 } catch (IOException e) {
472 throw new IOException("No data found in temporary java code fragment files for " + className 482 throw new IOException("No data found in temporary java code fragment files for " + className
473 + " while type def class file generation"); 483 + " while type def class file generation");
...@@ -557,7 +567,7 @@ public final class JavaFileGenerator { ...@@ -557,7 +567,7 @@ public final class JavaFileGenerator {
557 * From string method. 567 * From string method.
558 */ 568 */
559 methods.add(getFromStringMethodSignature(className) 569 methods.add(getFromStringMethodSignature(className)
560 - + getDataFromTempFileHandle(UNION_FROM_STRING_IMPL_MASK, curNode) 570 + + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, curNode)
561 + getFromStringMethodClose()); 571 + getFromStringMethodClose());
562 572
563 } catch (IOException e) { 573 } catch (IOException e) {
...@@ -576,11 +586,11 @@ public final class JavaFileGenerator { ...@@ -576,11 +586,11 @@ public final class JavaFileGenerator {
576 /** 586 /**
577 * Generates class file for type enum. 587 * Generates class file for type enum.
578 * 588 *
579 - * @param file generated file 589 + * @param file generated file
580 * @param curNode current YANG node 590 * @param curNode current YANG node
581 * @return class file for type enum 591 * @return class file for type enum
582 * @throws IOException when fails to generate class file 592 * @throws IOException when fails to generate class file
583 - */ 593 + */
584 public static File generateEnumClassFile(File file, YangNode curNode) throws IOException { 594 public static File generateEnumClassFile(File file, YangNode curNode) throws IOException {
585 595
586 JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); 596 JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
...@@ -624,4 +634,44 @@ public final class JavaFileGenerator { ...@@ -624,4 +634,44 @@ public final class JavaFileGenerator {
624 634
625 return file; 635 return file;
626 } 636 }
637 +
638 + /**
639 + * Generates interface file for rpc.
640 + *
641 + * @param file generated file
642 + * @param curNode current YANG node
643 + * @param imports imports for file
644 + * @return type def class file
645 + * @throws IOException when fails to generate class file
646 + */
647 + public static File generateRpcInterfaceFile(File file, YangNode curNode, List<String> imports) throws IOException {
648 +
649 + JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
650 +
651 + String className = getCaptialCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
652 + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
653 +
654 + initiateJavaFileGeneration(file, className, GENERATE_RPC_INTERFACE, imports, path);
655 +
656 + List<String> methods = new ArrayList<>();
657 +
658 + try {
659 +
660 + /**
661 + * Rpc methods
662 + */
663 + methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, curNode));
664 +
665 + } catch (IOException e) {
666 + throw new IOException("No data found in temporary java code fragment files for " + className
667 + + " while rpc class file generation");
668 + }
669 +
670 + for (String method : methods) {
671 + insertDataIntoJavaFile(file, method);
672 + }
673 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
674 +
675 + return file;
676 + }
627 } 677 }
......
...@@ -29,6 +29,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; ...@@ -29,6 +29,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -42,10 +43,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -42,10 +43,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
46 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
48 -import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; 50 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
49 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; 51 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
50 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; 52 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
51 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 53 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
...@@ -58,12 +60,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; ...@@ -58,12 +60,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
58 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 60 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
59 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 61 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
60 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 62 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
61 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
62 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; 63 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
63 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; 64 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
64 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; 65 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
65 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 66 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
66 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 67 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
68 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
69 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
67 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 70 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
68 71
69 /** 72 /**
...@@ -138,12 +141,15 @@ public final class JavaFileGeneratorUtils { ...@@ -138,12 +141,15 @@ public final class JavaFileGeneratorUtils {
138 } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { 141 } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
139 return tempJavaCodeFragmentFiles 142 return tempJavaCodeFragmentFiles
140 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getOfStringImplTempFileHandle()); 143 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getOfStringImplTempFileHandle());
141 - } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { 144 + } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
142 return tempJavaCodeFragmentFiles 145 return tempJavaCodeFragmentFiles
143 - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle()); 146 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getFromStringImplTempFileHandle());
144 } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { 147 } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
145 return tempJavaCodeFragmentFiles 148 return tempJavaCodeFragmentFiles
146 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEnumClassTempFileHandle()); 149 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEnumClassTempFileHandle());
150 + } else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
151 + return tempJavaCodeFragmentFiles
152 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getRpcInterfaceImplTempFileHandle());
147 } 153 }
148 return null; 154 return null;
149 } 155 }
...@@ -203,6 +209,9 @@ public final class JavaFileGeneratorUtils { ...@@ -203,6 +209,9 @@ public final class JavaFileGeneratorUtils {
203 } else if ((type & GENERATE_ENUM_CLASS) != 0) { 209 } else if ((type & GENERATE_ENUM_CLASS) != 0) {
204 appendHeaderContents(file, pkgString, importsList); 210 appendHeaderContents(file, pkgString, importsList);
205 write(file, fileName, type, ENUM_CLASS); 211 write(file, fileName, type, ENUM_CLASS);
212 + } else if ((type & GENERATE_RPC_INTERFACE) != 0) {
213 + appendHeaderContents(file, pkgString, importsList);
214 + write(file, fileName, type, RPC_INTERFACE);
206 } 215 }
207 } 216 }
208 217
......
...@@ -72,6 +72,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; ...@@ -72,6 +72,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
72 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 72 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
73 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; 73 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
74 import static org.onosproject.yangutils.utils.UtilConstants.RETURN; 74 import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
75 +import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
75 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 76 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
76 import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; 77 import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
77 import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; 78 import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
...@@ -87,15 +88,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY; ...@@ -87,15 +88,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY;
87 import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; 88 import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
88 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 89 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
89 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 90 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
90 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
91 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; 91 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
92 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; 92 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
93 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; 93 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
94 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
94 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 95 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
95 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; 96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; 97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 98 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
98 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD; 99 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
99 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 100 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
100 101
101 /** 102 /**
...@@ -425,6 +426,24 @@ public final class MethodsGenerator { ...@@ -425,6 +426,24 @@ public final class MethodsGenerator {
425 } 426 }
426 427
427 /** 428 /**
429 + * Returns the rpc strings for service interface.
430 + *
431 + * @param rpcName name of the rpc
432 + * @param inputName name of input
433 + * @param outputName name of output
434 + * @return rpc method string
435 + */
436 + public static String getRpcStringMethod(String rpcName, String inputName, String outputName) {
437 +
438 + rpcName = getSmallCase(getCamelCase(rpcName, null));
439 + inputName = getCaptialCase(inputName);
440 + outputName = getCaptialCase(outputName);
441 +
442 + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS
443 + + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
444 + }
445 +
446 + /**
428 * Returns the build method strings for class file. 447 * Returns the build method strings for class file.
429 * 448 *
430 * @param yangName class name 449 * @param yangName class name
...@@ -499,7 +518,7 @@ public final class MethodsGenerator { ...@@ -499,7 +518,7 @@ public final class MethodsGenerator {
499 * @return from string method's open string 518 * @return from string method's open string
500 */ 519 */
501 public static String getFromStringMethodSignature(String className) { 520 public static String getFromStringMethodSignature(String className) {
502 - return getJavaDoc(UNION_FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE 521 + return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
503 + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE 522 + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
504 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 523 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
505 } 524 }
......
...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangList; ...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangList;
28 import org.onosproject.yangutils.datamodel.YangNode; 28 import org.onosproject.yangutils.datamodel.YangNode;
29 import org.onosproject.yangutils.datamodel.YangNotification; 29 import org.onosproject.yangutils.datamodel.YangNotification;
30 import org.onosproject.yangutils.datamodel.YangOutput; 30 import org.onosproject.yangutils.datamodel.YangOutput;
31 +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
31 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 32 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
32 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; 33 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
33 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; 34 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
...@@ -54,19 +55,19 @@ public final class YangJavaModelUtils { ...@@ -54,19 +55,19 @@ public final class YangJavaModelUtils {
54 /** 55 /**
55 * Updates YANG java file package information. 56 * Updates YANG java file package information.
56 * 57 *
57 - * @param javaCodeGeneratorInfo YANG java file info node 58 + * @param hasJavaFileInfo YANG java file info node
58 - * @param yangPlugin YANG plugin config 59 + * @param yangPlugin YANG plugin config
59 * @throws IOException IO operations fails 60 * @throws IOException IO operations fails
60 */ 61 */
61 - private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin) 62 + public static void updatePackageInfo(HasJavaFileInfo hasJavaFileInfo, YangPluginConfig yangPlugin)
62 throws IOException { 63 throws IOException {
63 - javaCodeGeneratorInfo.getJavaFileInfo() 64 + hasJavaFileInfo.getJavaFileInfo()
64 .setJavaName(getCaptialCase( 65 .setJavaName(getCaptialCase(
65 - getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver()))); 66 + getCamelCase(((YangNode) hasJavaFileInfo).getName(), yangPlugin.getConflictResolver())));
66 - javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo)); 67 + hasJavaFileInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) hasJavaFileInfo));
67 - javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( 68 + hasJavaFileInfo.getJavaFileInfo().setPackageFilePath(
68 - getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); 69 + getPackageDirPathFromJavaJPackage(hasJavaFileInfo.getJavaFileInfo().getPackage()));
69 - javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir()); 70 + hasJavaFileInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
70 } 71 }
71 72
72 /** 73 /**
...@@ -155,7 +156,7 @@ public final class YangJavaModelUtils { ...@@ -155,7 +156,7 @@ public final class YangJavaModelUtils {
155 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 156 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
156 // TODO:throw exception 157 // TODO:throw exception
157 } 158 }
158 - updatePackageInfo(javaCodeGeneratorInfo, yangPlugin); 159 + updatePackageInfo((HasJavaFileInfo) javaCodeGeneratorInfo, yangPlugin);
159 generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir()); 160 generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
160 161
161 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 162 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
...@@ -182,15 +183,14 @@ public final class YangJavaModelUtils { ...@@ -182,15 +183,14 @@ public final class YangJavaModelUtils {
182 * 183 *
183 * @param javaCodeGeneratorInfo YANG java file info node 184 * @param javaCodeGeneratorInfo YANG java file info node
184 * @param yangPlugin YANG plugin config 185 * @param yangPlugin YANG plugin config
185 - * @param isMultiInstance flag to indicate whether it's a list
186 * @throws IOException IO operations fails 186 * @throws IOException IO operations fails
187 */ 187 */
188 - public static void generateCodeOfType(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, 188 + public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
189 - boolean isMultiInstance) throws IOException { 189 + throws IOException {
190 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 190 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
191 // TODO:throw exception 191 // TODO:throw exception
192 } 192 }
193 - updatePackageInfo(javaCodeGeneratorInfo, yangPlugin); 193 + updatePackageInfo((HasJavaFileInfo) javaCodeGeneratorInfo, yangPlugin);
194 generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir()); 194 generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
195 } 195 }
196 196
......
...@@ -138,6 +138,21 @@ public final class UtilConstants { ...@@ -138,6 +138,21 @@ public final class UtilConstants {
138 public static final String BUILDER_OBJECT = "builder object of "; 138 public static final String BUILDER_OBJECT = "builder object of ";
139 139
140 /** 140 /**
141 + * JavaDocs's statement for rpc method.
142 + */
143 + public static final String JAVA_DOC_RPC = " * Service interface of ";
144 +
145 + /**
146 + * JavaDocs's statement for rpc's input string.
147 + */
148 + public static final String RPC_INPUT_STRING = "input of service interface ";
149 +
150 + /**
151 + * JavaDocs's statement for rpc's output string.
152 + */
153 + public static final String RPC_OUTPUT_STRING = "output of service interface ";
154 +
155 + /**
141 * Static attribute for new line. 156 * Static attribute for new line.
142 */ 157 */
143 public static final String NEW_LINE = "\n"; 158 public static final String NEW_LINE = "\n";
...@@ -218,6 +233,11 @@ public final class UtilConstants { ...@@ -218,6 +233,11 @@ public final class UtilConstants {
218 public static final String INPUT = "input"; 233 public static final String INPUT = "input";
219 234
220 /** 235 /**
236 + * Static attribute for output variable of rpc.
237 + */
238 + public static final String RPC_INPUT_VAR_NAME = "inputVar";
239 +
240 + /**
221 * Static attribute for new line. 241 * Static attribute for new line.
222 */ 242 */
223 public static final String EQUAL = "="; 243 public static final String EQUAL = "=";
...@@ -723,6 +743,11 @@ public final class UtilConstants { ...@@ -723,6 +743,11 @@ public final class UtilConstants {
723 public static final String EXTEND = "extends"; 743 public static final String EXTEND = "extends";
724 744
725 /** 745 /**
746 + * Static attribute for service interface suffix syntax.
747 + */
748 + public static final String SERVICE_METHOD_STRING = "Service";
749 +
750 + /**
726 * Static attribute for impl syntax. 751 * Static attribute for impl syntax.
727 */ 752 */
728 public static final String IMPL = "Impl"; 753 public static final String IMPL = "Impl";
......
...@@ -18,6 +18,8 @@ package org.onosproject.yangutils.utils.io.impl; ...@@ -18,6 +18,8 @@ package org.onosproject.yangutils.utils.io.impl;
18 18
19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
20 20
21 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
22 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
21 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 25 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
...@@ -40,6 +42,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS; ...@@ -40,6 +42,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
40 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF; 42 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
41 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM; 43 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM;
42 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN; 44 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN;
45 +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RPC;
43 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS; 46 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
44 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON; 47 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
45 import static org.onosproject.yangutils.utils.UtilConstants.LIST; 48 import static org.onosproject.yangutils.utils.UtilConstants.LIST;
...@@ -49,6 +52,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; ...@@ -49,6 +52,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
49 import static org.onosproject.yangutils.utils.UtilConstants.OF; 52 import static org.onosproject.yangutils.utils.UtilConstants.OF;
50 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; 53 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
51 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 54 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
55 +import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING;
56 +import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING;
52 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 57 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
53 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 58 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
54 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 59 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
...@@ -100,6 +105,11 @@ public final class JavaDocGen { ...@@ -100,6 +105,11 @@ public final class JavaDocGen {
100 GETTER_METHOD, 105 GETTER_METHOD,
101 106
102 /** 107 /**
108 + * For rpc.
109 + */
110 + RPC_INTERFACE,
111 +
112 + /**
103 * For setters. 113 * For setters.
104 */ 114 */
105 SETTER_METHOD, 115 SETTER_METHOD,
...@@ -125,9 +135,9 @@ public final class JavaDocGen { ...@@ -125,9 +135,9 @@ public final class JavaDocGen {
125 CONSTRUCTOR, 135 CONSTRUCTOR,
126 136
127 /** 137 /**
128 - * For union's from method. 138 + * For from method.
129 */ 139 */
130 - UNION_FROM_METHOD, 140 + FROM_METHOD,
131 141
132 /** 142 /**
133 * For type constructor. 143 * For type constructor.
...@@ -160,42 +170,60 @@ public final class JavaDocGen { ...@@ -160,42 +170,60 @@ public final class JavaDocGen {
160 */ 170 */
161 public static String getJavaDoc(JavaDocType type, String name, boolean isList) { 171 public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
162 172
163 - name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name, null)); 173 + name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, null));
164 - String javaDoc; 174 + switch (type) {
165 - if (type.equals(JavaDocType.IMPL_CLASS)) { 175 + case IMPL_CLASS: {
166 - javaDoc = generateForImplClass(name); 176 + return generateForImplClass(name);
167 - } else if (type.equals(JavaDocType.BUILDER_CLASS)) { 177 + }
168 - javaDoc = generateForBuilderClass(name); 178 + case BUILDER_CLASS: {
169 - } else if (type.equals(JavaDocType.INTERFACE)) { 179 + return generateForBuilderClass(name);
170 - javaDoc = generateForInterface(name); 180 + }
171 - } else if (type.equals(JavaDocType.BUILDER_INTERFACE)) { 181 + case INTERFACE: {
172 - javaDoc = generateForBuilderInterface(name); 182 + return generateForInterface(name);
173 - } else if (type.equals(JavaDocType.PACKAGE_INFO)) { 183 + }
174 - javaDoc = generateForPackage(name); 184 + case BUILDER_INTERFACE: {
175 - } else if (type.equals(JavaDocType.GETTER_METHOD)) { 185 + return generateForBuilderInterface(name);
176 - javaDoc = generateForGetters(name, isList); 186 + }
177 - } else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) { 187 + case PACKAGE_INFO: {
178 - javaDoc = generateForTypeDefSetter(name); 188 + return generateForPackage(name);
179 - } else if (type.equals(JavaDocType.SETTER_METHOD)) { 189 + }
180 - javaDoc = generateForSetters(name, isList); 190 + case GETTER_METHOD: {
181 - } else if (type.equals(JavaDocType.OF_METHOD)) { 191 + return generateForGetters(name, isList);
182 - javaDoc = generateForOf(name); 192 + }
183 - } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { 193 + case TYPE_DEF_SETTER_METHOD: {
184 - javaDoc = generateForDefaultConstructors(name); 194 + return generateForTypeDefSetter(name);
185 - } else if (type.equals(JavaDocType.BUILD_METHOD)) { 195 + }
186 - javaDoc = generateForBuild(name); 196 + case SETTER_METHOD: {
187 - } else if (type.equals(JavaDocType.TYPE_CONSTRUCTOR)) { 197 + return generateForSetters(name, isList);
188 - javaDoc = generateForTypeConstructor(name); 198 + }
189 - } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) { 199 + case OF_METHOD: {
190 - javaDoc = generateForUnionFrom(name); 200 + return generateForOf(name);
191 - } else if (type.equals(JavaDocType.ENUM_CLASS)) { 201 + }
192 - javaDoc = generateForEnum(name); 202 + case DEFAULT_CONSTRUCTOR: {
193 - } else if (type.equals(JavaDocType.ENUM_ATTRIBUTE)) { 203 + return generateForDefaultConstructors(name);
194 - javaDoc = generateForEnumAttr(name); 204 + }
195 - } else { 205 + case BUILD_METHOD: {
196 - javaDoc = generateForConstructors(name); 206 + return generateForBuild(name);
207 + }
208 + case TYPE_CONSTRUCTOR: {
209 + return generateForTypeConstructor(name);
210 + }
211 + case FROM_METHOD: {
212 + return generateForFromString(name);
213 + }
214 + case ENUM_CLASS: {
215 + return generateForEnum(name);
216 + }
217 + case ENUM_ATTRIBUTE: {
218 + return generateForEnumAttr(name);
219 + }
220 + case RPC_INTERFACE: {
221 + return generateForRpcInterface(name);
222 + }
223 + default: {
224 + return generateForConstructors(name);
225 + }
197 } 226 }
198 - return javaDoc;
199 } 227 }
200 228
201 /** 229 /**
...@@ -210,6 +238,62 @@ public final class JavaDocGen { ...@@ -210,6 +238,62 @@ public final class JavaDocGen {
210 } 238 }
211 239
212 /** 240 /**
241 + * Generates javaDocs for rpc method.
242 + *
243 + * @param rpcName name of the rpc
244 + * @param inputName name of input
245 + * @param outputName name of output
246 + * @return javaDocs of rpc method
247 + */
248 + public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) {
249 + rpcName = getCamelCase(rpcName, null);
250 + inputName = getCaptialCase(inputName);
251 + outputName = getCaptialCase(outputName);
252 +
253 + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
254 + + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
255 + + getInputString(inputName, rpcName) + getOutputString(outputName, rpcName) + FOUR_SPACE_INDENTATION
256 + + JAVA_DOC_END_LINE;
257 + }
258 +
259 + /**
260 + * Returns output string of rpc.
261 + *
262 + * @param outputName name of output
263 + * @param rpcName name of rpc
264 + * @return javaDocs for output string of rpc
265 + */
266 + private static String getOutputString(String outputName, String rpcName) {
267 + return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + outputName + SPACE + RPC_OUTPUT_STRING + rpcName + NEW_LINE;
268 + }
269 +
270 + /**
271 + * Returns input string of rpc.
272 + *
273 + * @param inputName name of input
274 + * @param rpcName name of rpc
275 + * @return javaDocs for input string of rpc
276 + */
277 + private static String getInputString(String inputName, String rpcName) {
278 + if (inputName.equals("")) {
279 + return null;
280 + } else {
281 + return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + inputName + SPACE + RPC_INPUT_STRING + rpcName + NEW_LINE;
282 + }
283 + }
284 +
285 + /**
286 + * Generates javaDoc for the interface.
287 + *
288 + * @param interfaceName interface name
289 + * @return javaDocs
290 + */
291 + private static String generateForRpcInterface(String interfaceName) {
292 + return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
293 + + JAVA_DOC_END_LINE;
294 + }
295 +
296 + /**
213 * Generates javaDocs for getter method. 297 * Generates javaDocs for getter method.
214 * 298 *
215 * @param attribute attribute 299 * @param attribute attribute
...@@ -275,7 +359,7 @@ public final class JavaDocGen { ...@@ -275,7 +359,7 @@ public final class JavaDocGen {
275 * @param attribute attribute 359 * @param attribute attribute
276 * @return javaDocs 360 * @return javaDocs
277 */ 361 */
278 - private static String generateForUnionFrom(String attribute) { 362 + private static String generateForFromString(String attribute) {
279 363
280 return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF 364 return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
281 + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD 365 + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
......
...@@ -61,7 +61,7 @@ public class InputListenerTest { ...@@ -61,7 +61,7 @@ public class InputListenerTest {
61 assertThat(yangRpc.getName(), is("activate-software-image")); 61 assertThat(yangRpc.getName(), is("activate-software-image"));
62 62
63 YangInput yangInput = (YangInput) yangRpc.getChild(); 63 YangInput yangInput = (YangInput) yangRpc.getChild();
64 - assertThat(yangInput.getName(), is("activate-software-imageInput")); 64 + assertThat(yangInput.getName(), is("activate-software-image_input"));
65 ListIterator<YangLeaf> leafIterator = yangInput.getListOfLeaf().listIterator(); 65 ListIterator<YangLeaf> leafIterator = yangInput.getListOfLeaf().listIterator();
66 YangLeaf leafInfo = leafIterator.next(); 66 YangLeaf leafInfo = leafIterator.next();
67 67
...@@ -102,7 +102,7 @@ public class InputListenerTest { ...@@ -102,7 +102,7 @@ public class InputListenerTest {
102 assertThat(yangRpc.getName(), is("activate-software-image")); 102 assertThat(yangRpc.getName(), is("activate-software-image"));
103 103
104 YangInput yangInput = (YangInput) yangRpc.getChild(); 104 YangInput yangInput = (YangInput) yangRpc.getChild();
105 - assertThat(yangInput.getName(), is("activate-software-imageInput")); 105 + assertThat(yangInput.getName(), is("activate-software-image_input"));
106 YangTypeDef typeDef = (YangTypeDef) yangInput.getChild(); 106 YangTypeDef typeDef = (YangTypeDef) yangInput.getChild();
107 assertThat(typeDef.getName(), is("my-type")); 107 assertThat(typeDef.getName(), is("my-type"));
108 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED)); 108 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
......
...@@ -19,18 +19,17 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -19,18 +19,17 @@ package org.onosproject.yangutils.parser.impl.listeners;
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 import org.junit.Test; 21 import org.junit.Test;
22 - 22 +import org.onosproject.yangutils.datamodel.YangContainer;
23 +import org.onosproject.yangutils.datamodel.YangDataTypes;
24 +import org.onosproject.yangutils.datamodel.YangLeaf;
25 +import org.onosproject.yangutils.datamodel.YangList;
23 import org.onosproject.yangutils.datamodel.YangModule; 26 import org.onosproject.yangutils.datamodel.YangModule;
24 import org.onosproject.yangutils.datamodel.YangNode; 27 import org.onosproject.yangutils.datamodel.YangNode;
25 import org.onosproject.yangutils.datamodel.YangNodeType; 28 import org.onosproject.yangutils.datamodel.YangNodeType;
26 -import org.onosproject.yangutils.datamodel.YangRpc;
27 import org.onosproject.yangutils.datamodel.YangOutput; 29 import org.onosproject.yangutils.datamodel.YangOutput;
28 -import org.onosproject.yangutils.datamodel.YangLeaf; 30 +import org.onosproject.yangutils.datamodel.YangRpc;
29 -import org.onosproject.yangutils.datamodel.YangList;
30 -import org.onosproject.yangutils.datamodel.YangContainer;
31 -import org.onosproject.yangutils.datamodel.YangTypeDef;
32 import org.onosproject.yangutils.datamodel.YangStatusType; 31 import org.onosproject.yangutils.datamodel.YangStatusType;
33 -import org.onosproject.yangutils.datamodel.YangDataTypes; 32 +import org.onosproject.yangutils.datamodel.YangTypeDef;
34 import org.onosproject.yangutils.parser.exceptions.ParserException; 33 import org.onosproject.yangutils.parser.exceptions.ParserException;
35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 34 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
36 35
...@@ -61,7 +60,7 @@ public class OutputListenerTest { ...@@ -61,7 +60,7 @@ public class OutputListenerTest {
61 assertThat(yangRpc.getName(), is("activate-software-image")); 60 assertThat(yangRpc.getName(), is("activate-software-image"));
62 61
63 YangOutput yangOutput = (YangOutput) yangRpc.getChild(); 62 YangOutput yangOutput = (YangOutput) yangRpc.getChild();
64 - assertThat(yangOutput.getName(), is("activate-software-imageOutput")); 63 + assertThat(yangOutput.getName(), is("activate-software-image_output"));
65 ListIterator<YangLeaf> leafIterator = yangOutput.getListOfLeaf().listIterator(); 64 ListIterator<YangLeaf> leafIterator = yangOutput.getListOfLeaf().listIterator();
66 YangLeaf leafInfo = leafIterator.next(); 65 YangLeaf leafInfo = leafIterator.next();
67 66
...@@ -102,7 +101,7 @@ public class OutputListenerTest { ...@@ -102,7 +101,7 @@ public class OutputListenerTest {
102 assertThat(yangRpc.getName(), is("activate-software-image")); 101 assertThat(yangRpc.getName(), is("activate-software-image"));
103 102
104 YangOutput yangOutput = (YangOutput) yangRpc.getChild(); 103 YangOutput yangOutput = (YangOutput) yangRpc.getChild();
105 - assertThat(yangOutput.getName(), is("activate-software-imageOutput")); 104 + assertThat(yangOutput.getName(), is("activate-software-image_output"));
106 YangTypeDef typeDef = (YangTypeDef) yangOutput.getChild(); 105 YangTypeDef typeDef = (YangTypeDef) yangOutput.getChild();
107 assertThat(typeDef.getName(), is("my-type")); 106 assertThat(typeDef.getName(), is("my-type"));
108 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED)); 107 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
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.utils;
18 +
19 +import java.io.IOException;
20 +import org.junit.Test;
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +import org.onosproject.yangutils.parser.exceptions.ParserException;
23 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
24 +
25 +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
26 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
27 +
28 +/**
29 + * Unit tests for rpc translator.
30 + */
31 +public final class RpcTranslatorTest {
32 +
33 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
34 +
35 + /**
36 + * Checks rpc translation should not result in any exception.
37 + */
38 + @Test
39 + public void processRpcTranslator() throws IOException, ParserException {
40 +
41 + String userDir = System.getProperty("user.dir");
42 + YangNode node = manager.getDataModel("src/test/resources/RpcTranslator.yang");
43 +
44 + YangPluginConfig yangPluginConfig = new YangPluginConfig();
45 + yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
46 +
47 + generateJavaCode(node, yangPluginConfig);
48 +
49 + clean(userDir + "/target/RpcTestGenFile/");
50 + }
51 + // TODO enhance the test cases, after having a framework of translator test.
52 +}
1 +module Sfc {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + rpc SFP {
6 + input {
7 + leaf port {
8 + type string;
9 + }
10 + }
11 + output {
12 + leaf path {
13 + type string;
14 + }
15 + }
16 + }
17 +}