Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yms.app.yob; |
| 18 | |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.datamodel.YangSchemaNode; |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 20 | import org.onosproject.yms.app.ydt.YdtExtendedContext; |
| 21 | import org.onosproject.yms.app.ysr.YangSchemaRegistry; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 25 | import static org.onosproject.yms.app.ydt.AppType.YOB; |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 26 | import static org.onosproject.yms.app.yob.YobUtils.getQualifiedDefaultClass; |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Represents a YANG object builder handler to process the ydt content and |
| 30 | * build yang object. |
| 31 | */ |
| 32 | abstract class YobHandler { |
| 33 | |
| 34 | private static final Logger log = LoggerFactory.getLogger(YobHandler.class); |
| 35 | |
| 36 | /** |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 37 | * Creates a YANG builder object. |
| 38 | * |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 39 | * @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-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 44 | */ |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 45 | public void createBuilder(YdtExtendedContext curNode, |
| 46 | YdtExtendedContext rootNode, |
| 47 | YangSchemaRegistry registry) { |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 48 | String setterName = null; |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 49 | YangSchemaNode node = curNode.getYangSchemaNode(); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 50 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 51 | String qualName = getQualifiedDefaultClass(node); |
| 52 | ClassLoader classLoader = YobUtils.getClassLoader(registry, qualName, |
| 53 | curNode, rootNode); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 54 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 55 | if (curNode != rootNode) { |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 56 | setterName = node.getJavaAttributeName(); |
| 57 | } |
| 58 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 59 | Object workBench = new YobWorkBench(node, classLoader, qualName, |
| 60 | setterName); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 61 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 62 | curNode.addAppInfo(YOB, workBench); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 63 | } |
| 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-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 72 | public void setInParent(YdtExtendedContext ydtNode, |
| 73 | YangSchemaRegistry schemaRegistry) { |
| 74 | YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB); |
| 75 | yobWorkBench.setObjectInParent(ydtNode); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 76 | } |
| 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-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 87 | public void buildObject(YdtExtendedContext ydtNode, |
| 88 | YdtExtendedContext ydtRootNode, |
| 89 | YangSchemaRegistry schemaRegistry) { |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 90 | YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB); |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 91 | yobWorkBench.buildObject(ydtNode); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 92 | } |
| 93 | } |