Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | |
| 23 | /** |
| 24 | * Implementation of Java code generator based on application schema. |
| 25 | */ |
| 26 | public final class JavaCodeGenerator { |
| 27 | |
| 28 | /** |
| 29 | * Default constructor. |
| 30 | */ |
| 31 | private JavaCodeGenerator() { |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Generate Java code files corresponding to the YANG schema. |
| 36 | * |
| 37 | * @param rootNode root node of the data model tree. |
| 38 | * @throws IOException when fails to generate java code file the current node. |
| 39 | */ |
| 40 | public static void generateJavaCode(YangNode rootNode) throws IOException { |
| 41 | YangNode curNode = rootNode; |
| 42 | TraversalType curTraversal = TraversalType.ROOT; |
| 43 | |
| 44 | while (!(curNode == null)) { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 45 | if (curTraversal != TraversalType.PARENT) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 46 | curNode.generateJavaCodeEntry(); |
| 47 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 48 | if (curTraversal != TraversalType.PARENT && (curNode.getChild() != null)) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 49 | curTraversal = TraversalType.CHILD; |
| 50 | curNode = curNode.getChild(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 51 | } else if ((curNode.getNextSibling() != null)) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 52 | curNode.generateJavaCodeExit(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 53 | curTraversal = TraversalType.SIBILING; |
| 54 | curNode = curNode.getNextSibling(); |
| 55 | } else { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 56 | curNode.generateJavaCodeExit(); |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 57 | curTraversal = TraversalType.PARENT; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 58 | curNode = curNode.getParent(); |
| 59 | } |
| 60 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 61 | } |
| 62 | } |