Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +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.yangutils.datamodel; |
| 18 | |
| 19 | import java.io.Serializable; |
| 20 | import java.util.LinkedList; |
| 21 | import java.util.List; |
| 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 23 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
| 25 | |
| 26 | /* |
| 27 | * Reference RFC 6020. |
| 28 | * |
| 29 | * The "feature" statement is used to define a mechanism by which |
| 30 | * portions of the schema are marked as conditional. A feature name is |
| 31 | * defined that can later be referenced using the "if-feature" statement. |
| 32 | * Schema nodes tagged with a feature are ignored by the device unless |
| 33 | * the device supports the given feature. This allows portions of the |
| 34 | * YANG module to be conditional based on conditions on the device. |
| 35 | * The model can represent the abilities of the device within the model, |
| 36 | * giving a richer model that allows for differing device abilities and roles. |
| 37 | * |
| 38 | * The argument to the "feature" statement is the name of the new |
| 39 | * feature, and follows the rules for identifiers. This name is used by the |
| 40 | * "if-feature" statement to tie the schema nodes to the feature. |
| 41 | * |
| 42 | * The feature's Substatements |
| 43 | * |
| 44 | * +--------------+---------+-------------+------------------+ |
| 45 | * | substatement | section | cardinality |data model mapping| |
| 46 | * +--------------+---------+-------------+------------------+ |
| 47 | * | description | 7.19.3 | 0..1 | -string | |
| 48 | * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
| 49 | * | reference | 7.19.4 | 0..1 | -string | |
| 50 | * | status | 7.19.2 | 0..1 | -YangStatus | |
| 51 | * +--------------+---------+-------------+------------------+ |
| 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * Represents data model node to maintain information defined in YANG feature. |
| 56 | */ |
| 57 | public class YangFeature implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable { |
| 58 | |
| 59 | private static final long serialVersionUID = 806201635L; |
| 60 | |
| 61 | /** |
| 62 | * Name of the feature. |
| 63 | */ |
| 64 | private String name; |
| 65 | |
| 66 | /** |
| 67 | * Description of feature. |
| 68 | */ |
| 69 | private String description; |
| 70 | |
| 71 | /** |
| 72 | * Reference of the feature. |
| 73 | */ |
| 74 | private String reference; |
| 75 | |
| 76 | /** |
| 77 | * Status of feature. |
| 78 | */ |
| 79 | private YangStatusType statusType; |
| 80 | |
| 81 | /** |
| 82 | * List of if-feature. |
| 83 | */ |
| 84 | private List<YangIfFeature> ifFeatureList; |
| 85 | |
| 86 | @Override |
| 87 | public String getDescription() { |
| 88 | return description; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void setDescription(String description) { |
| 93 | this.description = description; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public String getReference() { |
| 98 | return reference; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void setReference(String reference) { |
| 103 | this.reference = reference; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public YangStatusType getStatus() { |
| 108 | return statusType; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void setStatus(YangStatusType status) { |
| 113 | this.statusType = status; |
| 114 | } |
| 115 | |
| 116 | public String getName() { |
| 117 | return name; |
| 118 | } |
| 119 | |
| 120 | public void setName(String name) { |
| 121 | this.name = name; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public YangConstructType getYangConstructType() { |
| 126 | return YangConstructType.FEATURE_DATA; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void validateDataOnEntry() throws DataModelException { |
| 131 | //TODO : To be implemented |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void validateDataOnExit() throws DataModelException { |
| 136 | //TODO : To be implemented |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public List<YangIfFeature> getIfFeatureList() { |
| 141 | return ifFeatureList; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void addIfFeatureList(YangIfFeature ifFeature) { |
| 146 | if (getIfFeatureList() == null) { |
| 147 | setIfFeatureList(new LinkedList<>()); |
| 148 | } |
| 149 | getIfFeatureList().add(ifFeature); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
| 154 | this.ifFeatureList = ifFeatureList; |
| 155 | } |
| 156 | } |