Vinod Kumar S | cf04442 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.parser.Parsable; |
| 21 | import org.onosproject.yangutils.parser.ParsableDataType; |
| 22 | |
| 23 | /* |
| 24 | * Reference:RFC 6020. |
| 25 | * The "type" statement takes as an argument a string that is the name |
| 26 | * of a YANG built-in type or a derived type, followed by an optional |
| 27 | * block of sub-statements that are used to put further restrictions |
| 28 | * on the type. |
| 29 | * |
| 30 | * The restrictions that can be applied depend on the type being restricted. |
| 31 | * The type's sub-statements |
| 32 | * |
| 33 | * +------------------+---------+-------------+------------------------------------+ |
| 34 | * | substatement | section | cardinality | mapped data type | |
| 35 | * +------------------+---------+-------------+------------------------------------+ |
| 36 | * | bit | 9.7.4 | 0..n | - YangBit used in YangBits | |
| 37 | * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration | |
| 38 | * | length | 9.4.4 | 0..1 | - used for string | |
| 39 | * | path | 9.9.2 | 0..1 | - TODO leaf-ref | |
| 40 | * | pattern | 9.4.6 | 0..n | - used for string | |
| 41 | * | range | 9.2.4 | 0..1 | - used for integer data type | |
| 42 | * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier | |
| 43 | * | type | 7.4 | 0..n | - TODO union | |
| 44 | * +------------------+---------+-------------+------------------------------------+ |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Maintains the data type information. |
| 49 | * |
| 50 | * @param <T> YANG data type info. |
| 51 | */ |
| 52 | public class YangType<T> implements Parsable { |
| 53 | |
| 54 | /** |
| 55 | * YANG data type name. |
| 56 | */ |
| 57 | private String dataTypeName; |
| 58 | |
| 59 | /** |
| 60 | * YANG data type. |
| 61 | */ |
| 62 | private YangDataTypes dataType; |
| 63 | |
| 64 | private T dataTypeInfo; |
| 65 | |
| 66 | /** |
| 67 | * Default constructor. |
| 68 | */ |
| 69 | public YangType() { |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get the name of data type. |
| 74 | * |
| 75 | * @return the name of data type. |
| 76 | */ |
| 77 | public String getDataTypeName() { |
| 78 | return dataTypeName; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Set the name of the data type. |
| 83 | * |
| 84 | * @param typeName the name to set |
| 85 | */ |
| 86 | public void setDataTypeName(String typeName) { |
| 87 | dataTypeName = typeName; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get the type of data. |
| 92 | * |
| 93 | * @return the data type. |
| 94 | */ |
| 95 | public YangDataTypes getDataType() { |
| 96 | return dataType; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Set the type of data. |
| 101 | * |
| 102 | * @param dataType data type. |
| 103 | */ |
| 104 | public void setDataType(YangDataTypes dataType) { |
| 105 | this.dataType = dataType; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the data type meta data. |
| 110 | * |
| 111 | * @return the data type meta data. |
| 112 | */ |
| 113 | public T getDataTypeInfo() { |
| 114 | return dataTypeInfo; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Set the data type meta data. |
| 119 | * |
| 120 | * @param dataTypeInfo the meta data to set |
| 121 | */ |
| 122 | public void setDataTypeInfo(T dataTypeInfo) { |
| 123 | this.dataTypeInfo = dataTypeInfo; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns the type of the parsed data. |
| 128 | * |
| 129 | * @return returns TYPE_DATA. |
| 130 | */ |
| 131 | public ParsableDataType getParsableDataType() { |
| 132 | return ParsableDataType.TYPE_DATA; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Validate the data on entering the corresponding parse tree node. |
| 137 | * |
| 138 | * @throws DataModelException a violation of data model rules. |
| 139 | */ |
| 140 | public void validateDataOnEntry() throws DataModelException { |
| 141 | // TODO auto-generated method stub, to be implemented by parser |
| 142 | |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Validate the data on exiting the corresponding parse tree node. |
| 147 | * |
| 148 | * @throws DataModelException a violation of data model rules. |
| 149 | */ |
| 150 | public void validateDataOnExit() throws DataModelException { |
| 151 | // TODO auto-generated method stub, to be implemented by parser |
| 152 | |
| 153 | } |
| 154 | } |