blob: abb6248f3a2a68b2747d43f12a3b0ecadef68425 [file] [log] [blame]
Rama-Huaweib711e5c2016-08-31 07:55:46 +05301/*
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
17package org.onosproject.yms.app.yob;
18
Rama-Huaweib711e5c2016-08-31 07:55:46 +053019import org.onosproject.yangutils.datamodel.YangSchemaNode;
Rama-Huaweib711e5c2016-08-31 07:55:46 +053020import org.onosproject.yms.app.ydt.YdtExtendedContext;
21import org.onosproject.yms.app.ysr.YangSchemaRegistry;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
Rama-Huaweib711e5c2016-08-31 07:55:46 +053025import static org.onosproject.yms.app.ydt.AppType.YOB;
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053026import static org.onosproject.yms.app.yob.YobUtils.getQualifiedDefaultClass;
Rama-Huaweib711e5c2016-08-31 07:55:46 +053027
28/**
29 * Represents a YANG object builder handler to process the ydt content and
30 * build yang object.
31 */
32abstract class YobHandler {
33
34 private static final Logger log = LoggerFactory.getLogger(YobHandler.class);
35
36 /**
Rama-Huaweib711e5c2016-08-31 07:55:46 +053037 * Creates a YANG builder object.
38 *
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053039 * @param curNode ydtExtendedContext is used to get
40 * application related information maintained
41 * in YDT
42 * @param rootNode ydtRootNode is refers to module node
43 * @param registry registry
Rama-Huaweib711e5c2016-08-31 07:55:46 +053044 */
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053045 public void createBuilder(YdtExtendedContext curNode,
46 YdtExtendedContext rootNode,
47 YangSchemaRegistry registry) {
Rama-Huaweib711e5c2016-08-31 07:55:46 +053048 String setterName = null;
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053049 YangSchemaNode node = curNode.getYangSchemaNode();
Rama-Huaweib711e5c2016-08-31 07:55:46 +053050
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053051 String qualName = getQualifiedDefaultClass(node);
52 ClassLoader classLoader = YobUtils.getClassLoader(registry, qualName,
53 curNode, rootNode);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053054
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053055 if (curNode != rootNode) {
Rama-Huaweib711e5c2016-08-31 07:55:46 +053056 setterName = node.getJavaAttributeName();
57 }
58
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053059 Object workBench = new YobWorkBench(node, classLoader, qualName,
60 setterName);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053061
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053062 curNode.addAppInfo(YOB, workBench);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053063 }
64
65 /**
66 * Sets the YANG built object in corresponding parent class method.
67 *
68 * @param ydtNode ydtExtendedContext is used to get application
69 * related information maintained in YDT
70 * @param schemaRegistry YANG schema registry
71 */
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053072 public void setInParent(YdtExtendedContext ydtNode,
73 YangSchemaRegistry schemaRegistry) {
74 YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
75 yobWorkBench.setObjectInParent(ydtNode);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053076 }
77
78 /**
79 * Builds the object.
80 *
81 * @param ydtNode ydtExtendedContext is used to get
82 * application related
83 * information maintained in YDT
84 * @param ydtRootNode ydtRootNode
85 * @param schemaRegistry YANG schema registry
86 */
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053087 public void buildObject(YdtExtendedContext ydtNode,
88 YdtExtendedContext ydtRootNode,
89 YangSchemaRegistry schemaRegistry) {
Rama-Huaweib711e5c2016-08-31 07:55:46 +053090 YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053091 yobWorkBench.buildObject(ydtNode);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053092 }
93}