blob: 0c707478b03974c8580b19179af08ed81906fcf4 [file] [log] [blame]
Bharat saraswal870c56f2016-02-20 21:57:16 +05301/*
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
17package org.onosproject.yangutils.translator.tojava;
18
19import java.io.IOException;
20
21import org.onosproject.yangutils.datamodel.YangNode;
22
23/**
24 * Implementation of Java code generator based on application schema.
25 */
26public 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 saraswal4bf8b152016-02-25 02:26:43 +053045 if (curTraversal != TraversalType.PARENT) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053046 curNode.generateJavaCodeEntry();
47 }
Bharat saraswal4bf8b152016-02-25 02:26:43 +053048 if (curTraversal != TraversalType.PARENT && (curNode.getChild() != null)) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053049 curTraversal = TraversalType.CHILD;
50 curNode = curNode.getChild();
Bharat saraswal4bf8b152016-02-25 02:26:43 +053051 } else if ((curNode.getNextSibling() != null)) {
Bharat saraswal594bc6d2016-02-22 22:15:21 +053052 curNode.generateJavaCodeExit();
Bharat saraswal870c56f2016-02-20 21:57:16 +053053 curTraversal = TraversalType.SIBILING;
54 curNode = curNode.getNextSibling();
55 } else {
Bharat saraswal594bc6d2016-02-22 22:15:21 +053056 curTraversal = TraversalType.PARENT;
Bharat saraswal4bf8b152016-02-25 02:26:43 +053057 curNode.generateJavaCodeExit();
Bharat saraswal870c56f2016-02-20 21:57:16 +053058 curNode = curNode.getParent();
59 }
60 }
Bharat saraswal4bf8b152016-02-25 02:26:43 +053061
Bharat saraswal870c56f2016-02-20 21:57:16 +053062 }
63}