blob: 40e4f1e1c33e19d485f6e222647d27f7b4446ef9 [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 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053037 * @param rootNode root node of the data model tree
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053038 * @param codeGenDir code generation directory
39 * @throws IOException when fails to generate java code file the current node
Bharat saraswal870c56f2016-02-20 21:57:16 +053040 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053041 public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
Bharat saraswal870c56f2016-02-20 21:57:16 +053042 YangNode curNode = rootNode;
43 TraversalType curTraversal = TraversalType.ROOT;
44
45 while (!(curNode == null)) {
Bharat saraswal4bf8b152016-02-25 02:26:43 +053046 if (curTraversal != TraversalType.PARENT) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +053047 curNode.generateJavaCodeEntry(codeGenDir);
Bharat saraswal870c56f2016-02-20 21:57:16 +053048 }
Vinod Kumar Sc4216002016-03-03 19:55:30 +053049 if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053050 curTraversal = TraversalType.CHILD;
51 curNode = curNode.getChild();
Vinod Kumar Sc4216002016-03-03 19:55:30 +053052 } else if (curNode.getNextSibling() != null) {
Bharat saraswal594bc6d2016-02-22 22:15:21 +053053 curNode.generateJavaCodeExit();
Bharat saraswal870c56f2016-02-20 21:57:16 +053054 curTraversal = TraversalType.SIBILING;
55 curNode = curNode.getNextSibling();
56 } else {
Bharat saraswal4bf8b152016-02-25 02:26:43 +053057 curNode.generateJavaCodeExit();
Vinod Kumar S71cba682016-02-25 15:52:16 +053058 curTraversal = TraversalType.PARENT;
Bharat saraswal870c56f2016-02-20 21:57:16 +053059 curNode = curNode.getParent();
60 }
61 }
Bharat saraswal870c56f2016-02-20 21:57:16 +053062 }
63}