Ai Hamano | bd51cdd | 2018-10-18 11:30:07 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.odtn.utils.openconfig; |
| 17 | |
| 18 | import org.onosproject.yang.gen.v1.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.components.DefaultComponent; |
| 19 | import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.components.component.DefaultAugmentedOcPlatformComponent; |
| 20 | |
| 21 | import org.onosproject.yang.model.KeyLeaf; |
| 22 | |
| 23 | /** |
| 24 | * Utility class to deal with OPENCONFIG Componet ModelObject & Annotation. |
| 25 | */ |
| 26 | public final class OpenConfigComponentHandler |
| 27 | extends OpenConfigObjectHandler<DefaultComponent> { |
| 28 | |
| 29 | private static final String OPENCONFIG_NAME = "component"; |
| 30 | private static final String KEY_LEAF_NAME = "name"; |
| 31 | private static final String NAME_SPACE = "http://openconfig.net/yang/platform"; |
| 32 | |
| 33 | private DefaultAugmentedOcPlatformComponent augmentedOcPlatformComponent; |
| 34 | |
| 35 | /** |
| 36 | * OpenConfigComponentHandler Constructor. |
| 37 | * |
| 38 | * @param keyValue String of target OPENCONFIG's key |
| 39 | * @param parent OpenConfigComponentsHandler of parent OPENCONFIG(components) |
| 40 | */ |
| 41 | public OpenConfigComponentHandler(String keyValue, OpenConfigComponentsHandler parent) { |
| 42 | modelObject = new DefaultComponent(); |
| 43 | modelObject.name(keyValue); |
| 44 | setResourceId(OPENCONFIG_NAME, NAME_SPACE, |
| 45 | new KeyLeaf(KEY_LEAF_NAME, NAME_SPACE, keyValue), |
| 46 | parent.getResourceIdBuilder()); |
| 47 | annotatedNodeInfos = parent.getAnnotatedNodeInfoList(); |
| 48 | augmentedOcPlatformComponent = new DefaultAugmentedOcPlatformComponent(); |
| 49 | |
| 50 | parent.addComponent(this); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Add Transceiver to modelObject of target OPENCONFIG. |
| 55 | * |
| 56 | * @param transceiver OpenConfigTransceiverHandler having Transceiver to be set for modelObject |
| 57 | * @return OpenConfigComponentHandler of target OPENCONFIG |
| 58 | */ |
| 59 | public OpenConfigComponentHandler addTransceiver(OpenConfigTransceiverHandler transceiver) { |
| 60 | augmentedOcPlatformComponent.transceiver(transceiver.getModelObject()); |
| 61 | modelObject.addAugmentation(augmentedOcPlatformComponent); |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Add Config to modelObject of target OPENCONFIG. |
| 67 | * |
| 68 | * @param config OpenConfigConfigOfComponentHandler having Config to be set for modelObject |
| 69 | * @return OpenConfigComponentHandler of target OPENCONFIG |
| 70 | */ |
| 71 | public OpenConfigComponentHandler addConfig(OpenConfigConfigOfComponentHandler config) { |
| 72 | modelObject.config(config.getModelObject()); |
| 73 | return this; |
| 74 | } |
| 75 | } |