Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 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(); |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 50 | while (node.getReferredSchema() != null) { |
| 51 | node = node.getReferredSchema(); |
| 52 | } |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 53 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 54 | String qualName = getQualifiedDefaultClass(node); |
| 55 | ClassLoader classLoader = YobUtils.getClassLoader(registry, qualName, |
| 56 | curNode, rootNode); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 57 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 58 | if (curNode != rootNode) { |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 59 | setterName = node.getJavaAttributeName(); |
| 60 | } |
| 61 | |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 62 | Object workBench = new YobWorkBench(curNode.getYangSchemaNode(), classLoader, qualName, |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 63 | setterName); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 64 | |
VinodKumarS-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 65 | curNode.addAppInfo(YOB, workBench); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 66 | } |
| 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-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 75 | public void setInParent(YdtExtendedContext ydtNode, |
| 76 | YangSchemaRegistry schemaRegistry) { |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 77 | YdtExtendedContext parentNode = (YdtExtendedContext) ydtNode.getParent(); |
| 78 | YobWorkBench parentWorkbench = (YobWorkBench) parentNode.getAppInfo(YOB); |
| 79 | parentWorkbench.setObject(ydtNode, schemaRegistry); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 80 | } |
| 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-Huawei | 7b1733c | 2016-10-25 13:44:26 +0530 | [diff] [blame] | 91 | public void buildObject(YdtExtendedContext ydtNode, |
| 92 | YdtExtendedContext ydtRootNode, |
| 93 | YangSchemaRegistry schemaRegistry) { |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 94 | YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB); |
Vidyashree Rama | 6160be1 | 2016-11-24 13:43:31 +0530 | [diff] [blame] | 95 | yobWorkBench.buildObject(ydtNode.getYdtContextOperationType(), schemaRegistry); |
Rama-Huawei | b711e5c | 2016-08-31 07:55:46 +0530 | [diff] [blame] | 96 | } |
| 97 | } |