Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +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 | package org.onosproject.yangutils.datamodel; |
| 17 | |
| 18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 19 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Reference:RFC 6020. |
| 24 | * The "import" statement makes definitions from one module available |
| 25 | * inside another module or submodule. The argument is the name of the |
| 26 | * module to import, and the statement is followed by a block of |
| 27 | * sub statements that holds detailed import information. |
| 28 | * When a module is imported, the importing module may: |
| 29 | * o use any grouping and typedef defined at the top level in the |
| 30 | * imported module or its submodules. |
| 31 | * |
| 32 | * o use any extension, feature, and identity defined in the imported |
| 33 | * module or its submodules. |
| 34 | * |
| 35 | * o use any node in the imported module's schema tree in "must", |
| 36 | * "path", and "when" statements, or as the target node in "augment" |
| 37 | * and "deviation" statements. |
| 38 | * |
| 39 | * The mandatory "prefix" sub statement assigns a prefix for the imported |
| 40 | * module that is scoped to the importing module or submodule. Multiple |
| 41 | * "import" statements may be specified to import from different |
| 42 | * modules. |
| 43 | * When the optional "revision-date" sub-statement is present, any |
| 44 | * typedef, grouping, extension, feature, and identity referenced by |
| 45 | * definitions in the local module are taken from the specified revision |
| 46 | * of the imported module. It is an error if the specified revision of |
| 47 | * the imported module does not exist. If no "revision-date" |
| 48 | * sub-statement is present, it is undefined from which revision of the |
| 49 | * module they are taken. |
| 50 | * |
| 51 | * Multiple revisions of the same module MUST NOT be imported. |
| 52 | * |
| 53 | * The import's Substatements |
| 54 | * |
| 55 | * +---------------+---------+-------------+------------------+ |
| 56 | * | substatement | section | cardinality |data model mapping| |
| 57 | * +---------------+---------+-------------+------------------+ |
| 58 | * | prefix | 7.1.4 | 1 | string | |
| 59 | * | revision-date | 7.1.5.1 | 0..1 | string | |
| 60 | * +---------------+---------+-------------+------------------+ |
| 61 | */ |
| 62 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 63 | * Represents the information about the imported modules. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 64 | */ |
| 65 | public class YangImport implements Parsable { |
| 66 | |
| 67 | /** |
| 68 | * Name of the module that is being imported. |
| 69 | */ |
| 70 | private String name; |
| 71 | |
| 72 | /** |
| 73 | * Prefix used to identify the entities from the imported module. |
| 74 | */ |
| 75 | private String prefixId; |
| 76 | |
| 77 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 78 | * Resolution information root node which is also the data model root node. |
| 79 | */ |
| 80 | private HasResolutionInfo resolutionInfoNode; |
| 81 | |
| 82 | /** |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 83 | * Reference:RFC 6020. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 84 | * |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 85 | * The import's "revision-date" statement is used to specify the exact |
| 86 | * version of the module to import. The "revision-date" statement MUST match |
| 87 | * the most recent "revision" statement in the imported module. organization |
| 88 | * which defined the YANG module. |
| 89 | */ |
| 90 | private String revision; |
| 91 | |
| 92 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 93 | * Creates a YANG import. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 94 | */ |
| 95 | public YangImport() { |
| 96 | |
| 97 | } |
| 98 | |
| 99 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 100 | * Returns the imported module name. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 101 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 102 | * @return the module name |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 103 | */ |
| 104 | public String getModuleName() { |
| 105 | return name; |
| 106 | } |
| 107 | |
| 108 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 109 | * Sets module name. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 110 | * |
| 111 | * @param moduleName the module name to set |
| 112 | */ |
| 113 | public void setModuleName(String moduleName) { |
| 114 | name = moduleName; |
| 115 | } |
| 116 | |
| 117 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 118 | * Returns the prefix used to identify the entities from the imported module. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 119 | * |
| 120 | * @return the prefix used to identify the entities from the imported |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 121 | * module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 122 | */ |
| 123 | public String getPrefixId() { |
| 124 | return prefixId; |
| 125 | } |
| 126 | |
| 127 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 128 | * Sets prefix identifier. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 129 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 130 | * @param prefixId set the prefix identifier of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 131 | */ |
| 132 | public void setPrefixId(String prefixId) { |
| 133 | this.prefixId = prefixId; |
| 134 | } |
| 135 | |
| 136 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 137 | * Returns the revision of the imported module. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 138 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 139 | * @return the revision of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 140 | */ |
| 141 | public String getRevision() { |
| 142 | return revision; |
| 143 | } |
| 144 | |
| 145 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 146 | * Sets the revision of the imported module. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 147 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 148 | * @param rev set the revision of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 149 | */ |
| 150 | public void setRevision(String rev) { |
| 151 | revision = rev; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Returns the type of the parsed data. |
| 156 | * |
| 157 | * @return returns IMPORT_DATA |
| 158 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 159 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 160 | public YangConstructType getYangConstructType() { |
| 161 | return YangConstructType.IMPORT_DATA; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 165 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 166 | * |
| 167 | * @throws DataModelException a violation of data model rules |
| 168 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 169 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 170 | public void validateDataOnEntry() throws DataModelException { |
| 171 | // TODO auto-generated method stub, to be implemented by parser |
| 172 | |
| 173 | } |
| 174 | |
| 175 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 176 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 177 | * |
| 178 | * @throws DataModelException a violation of data model rules |
| 179 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 180 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 181 | public void validateDataOnExit() throws DataModelException { |
| 182 | // TODO auto-generated method stub, to be implemented by parser |
| 183 | |
| 184 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 185 | |
| 186 | /** |
| 187 | * Returns the resolution information node. |
| 188 | * |
| 189 | * @return the resolution information node |
| 190 | */ |
| 191 | public HasResolutionInfo getResolutionInfoNode() { |
| 192 | return resolutionInfoNode; |
| 193 | } |
| 194 | |
| 195 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 196 | * Sets the dresolution information node. |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 197 | * |
| 198 | * @param resolutionInfoNode the resolution information node |
| 199 | */ |
| 200 | public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) { |
| 201 | this.resolutionInfoNode = resolutionInfoNode; |
| 202 | } |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 203 | } |