Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +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 | 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 | /** |
| 63 | * Maintains the information about the imported modules. |
| 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 | /** |
| 78 | * Reference:RFC 6020. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 79 | * |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 80 | * The import's "revision-date" statement is used to specify the exact |
| 81 | * version of the module to import. The "revision-date" statement MUST match |
| 82 | * the most recent "revision" statement in the imported module. organization |
| 83 | * which defined the YANG module. |
| 84 | */ |
| 85 | private String revision; |
| 86 | |
| 87 | /** |
| 88 | * Default constructor. |
| 89 | */ |
| 90 | public YangImport() { |
| 91 | |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get the imported module name. |
| 96 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 97 | * @return the module name |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 98 | */ |
| 99 | public String getModuleName() { |
| 100 | return name; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Set module name. |
| 105 | * |
| 106 | * @param moduleName the module name to set |
| 107 | */ |
| 108 | public void setModuleName(String moduleName) { |
| 109 | name = moduleName; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get the prefix used to identify the entities from the imported module. |
| 114 | * |
| 115 | * @return the prefix used to identify the entities from the imported |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 116 | * module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 117 | */ |
| 118 | public String getPrefixId() { |
| 119 | return prefixId; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Set prefix identifier. |
| 124 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 125 | * @param prefixId set the prefix identifier of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 126 | */ |
| 127 | public void setPrefixId(String prefixId) { |
| 128 | this.prefixId = prefixId; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get the revision of the imported module. |
| 133 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 134 | * @return the revision of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 135 | */ |
| 136 | public String getRevision() { |
| 137 | return revision; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Set the revision of the imported module. |
| 142 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 143 | * @param rev set the revision of the imported module |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 144 | */ |
| 145 | public void setRevision(String rev) { |
| 146 | revision = rev; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns the type of the parsed data. |
| 151 | * |
| 152 | * @return returns IMPORT_DATA |
| 153 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 154 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 155 | public YangConstructType getYangConstructType() { |
| 156 | return YangConstructType.IMPORT_DATA; |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Validate the data on entering the corresponding parse tree node. |
| 161 | * |
| 162 | * @throws DataModelException a violation of data model rules |
| 163 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 164 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 165 | public void validateDataOnEntry() throws DataModelException { |
| 166 | // TODO auto-generated method stub, to be implemented by parser |
| 167 | |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Validate the data on exiting the corresponding parse tree node. |
| 172 | * |
| 173 | * @throws DataModelException a violation of data model rules |
| 174 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 175 | @Override |
Vinod Kumar S | 6a33667 | 2016-02-09 20:12:31 +0530 | [diff] [blame] | 176 | public void validateDataOnExit() throws DataModelException { |
| 177 | // TODO auto-generated method stub, to be implemented by parser |
| 178 | |
| 179 | } |
| 180 | } |