Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +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.yangutils.datamodel; |
| 18 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 19 | import java.io.Serializable; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 20 | import java.util.HashSet; |
| 21 | import java.util.Set; |
| 22 | |
| 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 25 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Reference RFC 6020. |
| 29 | * |
| 30 | * The bits built-in type represents a bit set. That is, a bits value |
| 31 | * is a set of flags identified by small integer position numbers |
| 32 | * starting at 0. Each bit number has an assigned name. |
| 33 | */ |
| 34 | |
| 35 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 36 | * Represents the bits data type information. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 37 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 38 | public class YangBits implements Parsable, Serializable { |
| 39 | |
| 40 | private static final long serialVersionUID = 806201641L; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 41 | |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 42 | // Bits information set. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 43 | private Set<YangBit> bitSet; |
| 44 | |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 45 | // BITS name. |
| 46 | private String bitsName; |
| 47 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 48 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 49 | * Creates a YANG bits type object. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 50 | */ |
| 51 | public YangBits() { |
| 52 | setBitSet(new HashSet<YangBit>()); |
| 53 | } |
| 54 | |
| 55 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 56 | * Returns the bit set. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 57 | * |
| 58 | * @return the bit set |
| 59 | */ |
| 60 | public Set<YangBit> getBitSet() { |
| 61 | return bitSet; |
| 62 | } |
| 63 | |
| 64 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 65 | * Sets the bit set. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 66 | * |
| 67 | * @param bitSet the bit set |
| 68 | */ |
| 69 | private void setBitSet(Set<YangBit> bitSet) { |
| 70 | this.bitSet = bitSet; |
| 71 | } |
| 72 | |
| 73 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 74 | * Adds bit info. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 75 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 76 | * @param bitInfo the bit information to be added |
| 77 | * @throws DataModelException due to violation in data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 78 | */ |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 79 | public void addBitInfo(YangBit bitInfo) throws DataModelException { |
| 80 | if (!getBitSet().add(bitInfo)) { |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 81 | throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \"" |
| 82 | + bitInfo.getBitName() + "\""); |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 83 | } |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the type of the data. |
| 88 | * |
| 89 | * @return ParsedDataType returns BITS_DATA |
| 90 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 91 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 92 | public YangConstructType getYangConstructType() { |
| 93 | return YangConstructType.BITS_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 97 | * Returns the bits name. |
| 98 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 99 | * @return name of the bits |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 100 | */ |
| 101 | public String getBitsName() { |
| 102 | return bitsName; |
| 103 | } |
| 104 | |
| 105 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 106 | * Sets bits name. |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 107 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 108 | * @param bitsName bit name to be set |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 109 | */ |
| 110 | public void setBitsName(String bitsName) { |
| 111 | this.bitsName = bitsName; |
| 112 | } |
| 113 | |
| 114 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 115 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 116 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 117 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 118 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 119 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 120 | public void validateDataOnEntry() throws DataModelException { |
| 121 | // TODO auto-generated method stub, to be implemented by parser |
| 122 | } |
| 123 | |
| 124 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 125 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 126 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 127 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 128 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 129 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 130 | public void validateDataOnExit() throws DataModelException { |
| 131 | // TODO auto-generated method stub, to be implemented by parser |
| 132 | } |
| 133 | } |