blob: 1f5fc08993c46c7c742b821e7bfa06ce07f0853f [file] [log] [blame]
Rama-Huaweib711e5c2016-08-31 07:55:46 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Rama-Huaweib711e5c2016-08-31 07:55:46 +05303 *
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();
Vidyashree Rama6160be12016-11-24 13:43:31 +053050 while (node.getReferredSchema() != null) {
51 node = node.getReferredSchema();
52 }
Rama-Huaweib711e5c2016-08-31 07:55:46 +053053
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053054 String qualName = getQualifiedDefaultClass(node);
55 ClassLoader classLoader = YobUtils.getClassLoader(registry, qualName,
56 curNode, rootNode);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053057
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053058 if (curNode != rootNode) {
Rama-Huaweib711e5c2016-08-31 07:55:46 +053059 setterName = node.getJavaAttributeName();
60 }
61
Vidyashree Rama6160be12016-11-24 13:43:31 +053062 Object workBench = new YobWorkBench(curNode.getYangSchemaNode(), classLoader, qualName,
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053063 setterName);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053064
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053065 curNode.addAppInfo(YOB, workBench);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053066 }
67
68 /**
69 * Sets the YANG built object in corresponding parent class method.
70 *
71 * @param ydtNode ydtExtendedContext is used to get application
72 * related information maintained in YDT
73 * @param schemaRegistry YANG schema registry
74 */
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053075 public void setInParent(YdtExtendedContext ydtNode,
76 YangSchemaRegistry schemaRegistry) {
Vidyashree Rama6160be12016-11-24 13:43:31 +053077 YdtExtendedContext parentNode = (YdtExtendedContext) ydtNode.getParent();
78 YobWorkBench parentWorkbench = (YobWorkBench) parentNode.getAppInfo(YOB);
79 parentWorkbench.setObject(ydtNode, schemaRegistry);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053080 }
81
82 /**
83 * Builds the object.
84 *
85 * @param ydtNode ydtExtendedContext is used to get
86 * application related
87 * information maintained in YDT
88 * @param ydtRootNode ydtRootNode
89 * @param schemaRegistry YANG schema registry
90 */
VinodKumarS-Huawei7b1733c2016-10-25 13:44:26 +053091 public void buildObject(YdtExtendedContext ydtNode,
92 YdtExtendedContext ydtRootNode,
93 YangSchemaRegistry schemaRegistry) {
Rama-Huaweib711e5c2016-08-31 07:55:46 +053094 YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
Vidyashree Rama6160be12016-11-24 13:43:31 +053095 yobWorkBench.buildObject(ydtNode.getYdtContextOperationType(), schemaRegistry);
Rama-Huaweib711e5c2016-08-31 07:55:46 +053096 }
97}