Committed by
Gerrit Code Review
[ONOS-3898/4069] Yang Utils Extension to support RPC/Notification/Choice/Case/Union
Change-Id: I405852caff3464719e8e586fa8e9ae9b6ed043ff
Showing
27 changed files
with
2275 additions
and
6 deletions
| 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 java.util.LinkedList; | ||
| 20 | +import java.util.List; | ||
| 21 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 22 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 23 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
| 24 | + | ||
| 25 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | + * Reference RFC 6020. | ||
| 29 | + * | ||
| 30 | + * The "input" statement, which is optional, is used to define input | ||
| 31 | + * parameters to the RPC operation. It does not take an argument. The | ||
| 32 | + * substatements to "input" define nodes under the RPC's input node. | ||
| 33 | + * | ||
| 34 | + * If a leaf in the input tree has a "mandatory" statement with the | ||
| 35 | + * value "true", the leaf MUST be present in a NETCONF RPC invocation. | ||
| 36 | + * Otherwise, the server MUST return a "missing-element" error. | ||
| 37 | + * | ||
| 38 | + * If a leaf in the input tree has a default value, the NETCONF server | ||
| 39 | + * MUST use this value in the same cases as described in Section 7.6.1. | ||
| 40 | + * In these cases, the server MUST operationally behave as if the leaf | ||
| 41 | + * was present in the NETCONF RPC invocation with the default value as | ||
| 42 | + * its value. | ||
| 43 | + * | ||
| 44 | + * If a "config" statement is present for any node in the input tree, | ||
| 45 | + * the "config" statement is ignored. | ||
| 46 | + * | ||
| 47 | + * If any node has a "when" statement that would evaluate to false, then | ||
| 48 | + * this node MUST NOT be present in the input tree. | ||
| 49 | + * | ||
| 50 | + * The input substatements | ||
| 51 | + * | ||
| 52 | + * +--------------+---------+-------------+------------------+ | ||
| 53 | + * | substatement | section | cardinality |data model mapping| | ||
| 54 | + * +--------------+---------+-------------+------------------+ | ||
| 55 | + * | anyxml | 7.10 | 0..n | -not supported | | ||
| 56 | + * | choice | 7.9 | 0..n | -child nodes | | ||
| 57 | + * | container | 7.5 | 0..n | -child nodes | | ||
| 58 | + * | grouping | 7.11 | 0..n | -child nodes | | ||
| 59 | + * | leaf | 7.6 | 0..n | -YangLeaf | | ||
| 60 | + * | leaf-list | 7.7 | 0..n | -YangLeafList | | ||
| 61 | + * | list | 7.8 | 0..n | -child nodes | | ||
| 62 | + * | typedef | 7.3 | 0..n | -child nodes | | ||
| 63 | + * | uses | 7.12 | 0..n | -child nodes | | ||
| 64 | + * +--------------+---------+-------------+------------------+ | ||
| 65 | + */ | ||
| 66 | + | ||
| 67 | +/** | ||
| 68 | + * Data model node to maintain information defined in YANG input. | ||
| 69 | + */ | ||
| 70 | +public class YangInput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector { | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Name of the input. | ||
| 74 | + */ | ||
| 75 | + private String name; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * List of leaves contained. | ||
| 79 | + */ | ||
| 80 | + private List<YangLeaf> listOfLeaf; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * List of leaf-lists contained. | ||
| 84 | + */ | ||
| 85 | + private List<YangLeafList> listOfLeafList; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Create a rpc input node. | ||
| 89 | + */ | ||
| 90 | + public YangInput() { | ||
| 91 | + super(YangNodeType.INPUT_NODE); | ||
| 92 | + listOfLeaf = new LinkedList<YangLeaf>(); | ||
| 93 | + listOfLeafList = new LinkedList<YangLeafList>(); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 98 | + // Detect colliding child. | ||
| 99 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 104 | + if (this.getName().equals(identifierName)) { | ||
| 105 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \"" | ||
| 106 | + + this.getName() + "\""); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public YangConstructType getYangConstructType() { | ||
| 112 | + return YangConstructType.INPUT_DATA; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + @Override | ||
| 116 | + public void validateDataOnEntry() throws DataModelException { | ||
| 117 | + //TODO: implement the method. | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public void validateDataOnExit() throws DataModelException { | ||
| 122 | + //TODO: implement the method. | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public List<YangLeaf> getListOfLeaf() { | ||
| 127 | + return listOfLeaf; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @Override | ||
| 131 | + public void addLeaf(YangLeaf leaf) { | ||
| 132 | + getListOfLeaf().add(leaf); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public List<YangLeafList> getListOfLeafList() { | ||
| 137 | + return listOfLeafList; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + @Override | ||
| 141 | + public void addLeafList(YangLeafList leafList) { | ||
| 142 | + getListOfLeafList().add(leafList); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public String getName() { | ||
| 147 | + return name; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Override | ||
| 151 | + public void setName(String name) { | ||
| 152 | + this.name = name; | ||
| 153 | + } | ||
| 154 | +} |
| ... | @@ -75,6 +75,26 @@ public enum YangNodeType { | ... | @@ -75,6 +75,26 @@ public enum YangNodeType { |
| 75 | CONTAINER_NODE, | 75 | CONTAINER_NODE, |
| 76 | 76 | ||
| 77 | /** | 77 | /** |
| 78 | + * Node contains "YANG's notification" information. | ||
| 79 | + */ | ||
| 80 | + NOTIFICATION_NODE, | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Node contains "YANG's input" information. | ||
| 84 | + */ | ||
| 85 | + INPUT_NODE, | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Node contains "YANG's output" information. | ||
| 89 | + */ | ||
| 90 | + OUTPUT_NODE, | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Node contains "YANG's rpc" information. | ||
| 94 | + */ | ||
| 95 | + RPC_NODE, | ||
| 96 | + | ||
| 97 | + /** | ||
| 78 | * Node contains "YANG's list" information. | 98 | * Node contains "YANG's list" information. |
| 79 | */ | 99 | */ |
| 80 | LIST_NODE | 100 | LIST_NODE | ... | ... |
| 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 java.util.LinkedList; | ||
| 20 | +import java.util.List; | ||
| 21 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 22 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 23 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
| 24 | + | ||
| 25 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | + * Reference RFC 6020. | ||
| 29 | + * | ||
| 30 | + * YANG allows the definition of notifications suitable for NETCONF. | ||
| 31 | + * YANG data definition statements are used to model the content of the | ||
| 32 | + * notification. | ||
| 33 | + * | ||
| 34 | + * The "notification" statement is used to define a NETCONF | ||
| 35 | + * notification. It takes one argument, which is an identifier, | ||
| 36 | + * followed by a block of substatements that holds detailed notification | ||
| 37 | + * information. The "notification" statement defines a notification | ||
| 38 | + * node in the schema tree. | ||
| 39 | + * | ||
| 40 | + * If a leaf in the notification tree has a "mandatory" statement with | ||
| 41 | + * the value "true", the leaf MUST be present in a NETCONF notification. | ||
| 42 | + * | ||
| 43 | + * If a leaf in the notification tree has a default value, the NETCONF | ||
| 44 | + * client MUST use this value in the same cases as described in | ||
| 45 | + * Section 7.6.1. In these cases, the client MUST operationally behave | ||
| 46 | + * as if the leaf was present in the NETCONF notification with the | ||
| 47 | + * default value as its value. | ||
| 48 | + * | ||
| 49 | + * If a "config" statement is present for any node in the notification | ||
| 50 | + * tree, the "config" statement is ignored. | ||
| 51 | + * | ||
| 52 | + * The notification's substatements | ||
| 53 | + * | ||
| 54 | + * +--------------+---------+-------------+------------------+ | ||
| 55 | + * | substatement | section | cardinality |data model mapping| | ||
| 56 | + * +--------------+---------+-------------+------------------+ | ||
| 57 | + * | anyxml | 7.10 | 0..n | -not supported | | ||
| 58 | + * | choice | 7.9 | 0..n | -child nodes | | ||
| 59 | + * | container | 7.5 | 0..n | -child nodes | | ||
| 60 | + * | description | 7.19.3 | 0..1 | -string | | ||
| 61 | + * | grouping | 7.11 | 0..n | -child nodes | | ||
| 62 | + * | if-feature | 7.18.2 | 0..n | -TODO | | ||
| 63 | + * | leaf | 7.6 | 0..n | -YangLeaf | | ||
| 64 | + * | leaf-list | 7.7 | 0..n | -YangLeafList | | ||
| 65 | + * | list | 7.8 | 0..n | -child nodes | | ||
| 66 | + * | reference | 7.19.4 | 0..1 | -string | | ||
| 67 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
| 68 | + * | typedef | 7.3 | 0..n | -child nodes | | ||
| 69 | + * | uses | 7.12 | 0..n | -child nodes | | ||
| 70 | + * +--------------+---------+-------------+------------------+ | ||
| 71 | + */ | ||
| 72 | + | ||
| 73 | +/** | ||
| 74 | + * Data model node to maintain information defined in YANG notification. | ||
| 75 | + */ | ||
| 76 | +public class YangNotification extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, | ||
| 77 | + CollisionDetector { | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * Name of the notification. | ||
| 81 | + */ | ||
| 82 | + private String name; | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * Description of notification. | ||
| 86 | + */ | ||
| 87 | + private String description; | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * List of leaves contained. | ||
| 91 | + */ | ||
| 92 | + private List<YangLeaf> listOfLeaf; | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * List of leaf-lists contained. | ||
| 96 | + */ | ||
| 97 | + private List<YangLeafList> listOfLeafList; | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Reference of the module. | ||
| 101 | + */ | ||
| 102 | + private String reference; | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Status of the node. | ||
| 106 | + */ | ||
| 107 | + private YangStatusType status = YangStatusType.CURRENT; | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Create a notification node. | ||
| 111 | + */ | ||
| 112 | + public YangNotification() { | ||
| 113 | + super(YangNodeType.NOTIFICATION_NODE); | ||
| 114 | + listOfLeaf = new LinkedList<YangLeaf>(); | ||
| 115 | + listOfLeafList = new LinkedList<YangLeafList>(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 120 | + // Detect colliding child. | ||
| 121 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 126 | + if (this.getName().equals(identifierName)) { | ||
| 127 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \"" | ||
| 128 | + + this.getName() + "\""); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public YangConstructType getYangConstructType() { | ||
| 134 | + return YangConstructType.NOTIFICATION_DATA; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public void validateDataOnEntry() throws DataModelException { | ||
| 139 | + //TODO: implement the method. | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public void validateDataOnExit() throws DataModelException { | ||
| 144 | + //TODO: implement the method. | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public String getDescription() { | ||
| 149 | + return description; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public void setDescription(String description) { | ||
| 154 | + this.description = description; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + @Override | ||
| 158 | + public List<YangLeaf> getListOfLeaf() { | ||
| 159 | + return listOfLeaf; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public void addLeaf(YangLeaf leaf) { | ||
| 164 | + getListOfLeaf().add(leaf); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + @Override | ||
| 168 | + public List<YangLeafList> getListOfLeafList() { | ||
| 169 | + return listOfLeafList; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + @Override | ||
| 173 | + public void addLeafList(YangLeafList leafList) { | ||
| 174 | + getListOfLeafList().add(leafList); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public String getName() { | ||
| 179 | + return name; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @Override | ||
| 183 | + public void setName(String name) { | ||
| 184 | + this.name = name; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + @Override | ||
| 188 | + public String getReference() { | ||
| 189 | + return reference; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + @Override | ||
| 193 | + public void setReference(String reference) { | ||
| 194 | + this.reference = reference; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + @Override | ||
| 198 | + public YangStatusType getStatus() { | ||
| 199 | + return status; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + @Override | ||
| 203 | + public void setStatus(YangStatusType status) { | ||
| 204 | + this.status = status; | ||
| 205 | + } | ||
| 206 | +} |
| 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 java.util.LinkedList; | ||
| 20 | +import java.util.List; | ||
| 21 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 22 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 23 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
| 24 | + | ||
| 25 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | + * Reference RFC 6020. | ||
| 29 | + * | ||
| 30 | + * The "output" statement, which is optional, is used to define output | ||
| 31 | + * parameters to the RPC operation. It does not take an argument. The | ||
| 32 | + * substatements to "output" define nodes under the RPC's output node. | ||
| 33 | + * | ||
| 34 | + * If a leaf in the output tree has a "mandatory" statement with the | ||
| 35 | + * value "true", the leaf MUST be present in a NETCONF RPC reply. | ||
| 36 | + * | ||
| 37 | + * If a leaf in the output tree has a default value, the NETCONF client | ||
| 38 | + * MUST use this value in the same cases as described in Section 7.6.1. | ||
| 39 | + * In these cases, the client MUST operationally behave as if the leaf | ||
| 40 | + * was present in the NETCONF RPC reply with the default value as its | ||
| 41 | + * value. | ||
| 42 | + * | ||
| 43 | + * If a "config" statement is present for any node in the output tree, | ||
| 44 | + * the "config" statement is ignored. | ||
| 45 | + * | ||
| 46 | + * If any node has a "when" statement that would evaluate to false, then | ||
| 47 | + * this node MUST NOT be present in the output tree. | ||
| 48 | + * | ||
| 49 | + * The output substatements | ||
| 50 | + * | ||
| 51 | + * +--------------+---------+-------------+------------------+ | ||
| 52 | + * | substatement | section | cardinality |data model mapping| | ||
| 53 | + * +--------------+---------+-------------+------------------+ | ||
| 54 | + * | anyxml | 7.10 | 0..n | -not supported | | ||
| 55 | + * | choice | 7.9 | 0..n | -child nodes | | ||
| 56 | + * | container | 7.5 | 0..n | -child nodes | | ||
| 57 | + * | grouping | 7.11 | 0..n | -child nodes | | ||
| 58 | + * | leaf | 7.6 | 0..n | -YangLeaf | | ||
| 59 | + * | leaf-list | 7.7 | 0..n | -YangLeafList | | ||
| 60 | + * | list | 7.8 | 0..n | -child nodes | | ||
| 61 | + * | typedef | 7.3 | 0..n | -child nodes | | ||
| 62 | + * | uses | 7.12 | 0..n | -child nodes | | ||
| 63 | + * +--------------+---------+-------------+------------------+ | ||
| 64 | + */ | ||
| 65 | + | ||
| 66 | +/** | ||
| 67 | + * Data model node to maintain information defined in YANG output. | ||
| 68 | + */ | ||
| 69 | +public class YangOutput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector { | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * Name of the output. | ||
| 73 | + */ | ||
| 74 | + private String name; | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * List of leaves contained. | ||
| 78 | + */ | ||
| 79 | + private List<YangLeaf> listOfLeaf; | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * List of leaf-lists contained. | ||
| 83 | + */ | ||
| 84 | + private List<YangLeafList> listOfLeafList; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Create a rpc output node. | ||
| 88 | + */ | ||
| 89 | + public YangOutput() { | ||
| 90 | + super(YangNodeType.OUTPUT_NODE); | ||
| 91 | + listOfLeaf = new LinkedList<YangLeaf>(); | ||
| 92 | + listOfLeafList = new LinkedList<YangLeafList>(); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 97 | + // Detect colliding child. | ||
| 98 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 103 | + if (this.getName().equals(identifierName)) { | ||
| 104 | + throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \"" | ||
| 105 | + + this.getName() + "\""); | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public YangConstructType getYangConstructType() { | ||
| 111 | + return YangConstructType.OUTPUT_DATA; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public void validateDataOnEntry() throws DataModelException { | ||
| 116 | + //TODO: implement the method. | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public void validateDataOnExit() throws DataModelException { | ||
| 121 | + //TODO: implement the method. | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public List<YangLeaf> getListOfLeaf() { | ||
| 126 | + return listOfLeaf; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @Override | ||
| 130 | + public void addLeaf(YangLeaf leaf) { | ||
| 131 | + getListOfLeaf().add(leaf); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public List<YangLeafList> getListOfLeafList() { | ||
| 136 | + return listOfLeafList; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public void addLeafList(YangLeafList leafList) { | ||
| 141 | + getListOfLeafList().add(leafList); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public String getName() { | ||
| 146 | + return name; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + @Override | ||
| 150 | + public void setName(String name) { | ||
| 151 | + this.name = name; | ||
| 152 | + } | ||
| 153 | +} |
| 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.utils.YangConstructType; | ||
| 22 | + | ||
| 23 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
| 24 | + | ||
| 25 | +/* | ||
| 26 | + * Reference RFC 6020. | ||
| 27 | + * | ||
| 28 | + * The "rpc" statement is used to define a NETCONF RPC operation. It | ||
| 29 | + * takes one argument, which is an identifier, followed by a block of | ||
| 30 | + * substatements that holds detailed rpc information. This argument is | ||
| 31 | + * the name of the RPC, and is used as the element name directly under | ||
| 32 | + * the <rpc> element, as designated by the substitution group | ||
| 33 | + * "rpcOperation" in [RFC4741]. | ||
| 34 | + * | ||
| 35 | + * The "rpc" statement defines an rpc node in the schema tree. Under | ||
| 36 | + * the rpc node, a schema node with the name "input", and a schema node | ||
| 37 | + * with the name "output" are also defined. The nodes "input" and | ||
| 38 | + * "output" are defined in the module's namespace. | ||
| 39 | + * | ||
| 40 | + * The rpc substatements | ||
| 41 | + * | ||
| 42 | + * +--------------+---------+-------------+------------------+ | ||
| 43 | + * | substatement | section | cardinality |data model mapping| | ||
| 44 | + * +--------------+---------+-------------+------------------+ | ||
| 45 | + * | description | 7.19.3 | 0..1 | -string | | ||
| 46 | + * | grouping | 7.11 | 0..n | -child nodes | | ||
| 47 | + * | if-feature | 7.18.2 | 0..n | -TODO | | ||
| 48 | + * | input | 7.13.2 | 0..1 | -child nodes | | ||
| 49 | + * | output | 7.13.3 | 0..1 | -child nodes | | ||
| 50 | + * | reference | 7.19.4 | 0..1 | -string | | ||
| 51 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
| 52 | + * | typedef | 7.3 | 0..n | -child nodes | | ||
| 53 | + * +--------------+---------+-------------+------------------+ | ||
| 54 | + */ | ||
| 55 | + | ||
| 56 | +/** | ||
| 57 | + * Data model node to maintain information defined in YANG rpc. | ||
| 58 | + */ | ||
| 59 | +public class YangRpc extends YangNode implements YangCommonInfo, Parsable, | ||
| 60 | + CollisionDetector { | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Name of the rpc. | ||
| 64 | + */ | ||
| 65 | + private String name; | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Description of rpc. | ||
| 69 | + */ | ||
| 70 | + private String description; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Reference of the module. | ||
| 74 | + */ | ||
| 75 | + private String reference; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Status of the node. | ||
| 79 | + */ | ||
| 80 | + private YangStatusType status = YangStatusType.CURRENT; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Create a rpc node. | ||
| 84 | + */ | ||
| 85 | + public YangRpc() { | ||
| 86 | + super(YangNodeType.RPC_NODE); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public String getName() { | ||
| 91 | + return name; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public void setName(String name) { | ||
| 96 | + this.name = name; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 101 | + // Detect colliding child. | ||
| 102 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
| 107 | + if (this.getName().equals(identifierName)) { | ||
| 108 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as rpc \"" | ||
| 109 | + + this.getName() + "\""); | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Override | ||
| 114 | + public YangConstructType getYangConstructType() { | ||
| 115 | + return YangConstructType.RPC_DATA; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public void validateDataOnEntry() throws DataModelException { | ||
| 120 | + //TODO: implement the method. | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + @Override | ||
| 124 | + public void validateDataOnExit() throws DataModelException { | ||
| 125 | + //TODO: implement the method. | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + @Override | ||
| 129 | + public String getDescription() { | ||
| 130 | + return description; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + @Override | ||
| 134 | + public void setDescription(String description) { | ||
| 135 | + this.description = description; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Override | ||
| 139 | + public String getReference() { | ||
| 140 | + return reference; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public void setReference(String reference) { | ||
| 145 | + this.reference = reference; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public YangStatusType getStatus() { | ||
| 150 | + return status; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + @Override | ||
| 154 | + public void setStatus(YangStatusType status) { | ||
| 155 | + this.status = status; | ||
| 156 | + } | ||
| 157 | +} |
| 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.utils.YangConstructType; | ||
| 22 | + | ||
| 23 | +import java.util.List; | ||
| 24 | + | ||
| 25 | +/* | ||
| 26 | + * Reference RFC 6020. | ||
| 27 | + * | ||
| 28 | + * The union built-in type represents a value that corresponds to one of | ||
| 29 | + * its member types. | ||
| 30 | + * | ||
| 31 | + * When the type is "union", the "type" statement (Section 7.4) MUST be | ||
| 32 | + * present. It is used to repeatedly specify each member type of the | ||
| 33 | + * union. It takes as an argument a string that is the name of a member | ||
| 34 | + * type. | ||
| 35 | + * | ||
| 36 | + * A member type can be of any built-in or derived type, except it MUST | ||
| 37 | + * NOT be one of the built-in types "empty" or "leafref". | ||
| 38 | + * | ||
| 39 | + * When a string representing a union data type is validated, the string | ||
| 40 | + * is validated against each member type, in the order they are | ||
| 41 | + * specified in the "type" statement, until a match is found. | ||
| 42 | + * | ||
| 43 | + * Any default value or "units" property defined in the member types is | ||
| 44 | + * not inherited by the union type. | ||
| 45 | + */ | ||
| 46 | + | ||
| 47 | +/** | ||
| 48 | + * Data model node to maintain information defined in YANG union. | ||
| 49 | + */ | ||
| 50 | +public class YangUnion implements Parsable { | ||
| 51 | + | ||
| 52 | + // List of YANG type. | ||
| 53 | + private List<YangType<?>> typeList; | ||
| 54 | + | ||
| 55 | + // Name of the union. | ||
| 56 | + private String unionName; | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Create a YANG union node. | ||
| 60 | + */ | ||
| 61 | + public YangUnion() { | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Returns list of YANG type. | ||
| 66 | + * | ||
| 67 | + * @return the list of YANG type | ||
| 68 | + */ | ||
| 69 | + public List<YangType<?>> getTypeList() { | ||
| 70 | + return typeList; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * Returns union name. | ||
| 75 | + * | ||
| 76 | + * @return the union name | ||
| 77 | + */ | ||
| 78 | + public String getUnionName() { | ||
| 79 | + return unionName; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Set the list of YANG type. | ||
| 84 | + * | ||
| 85 | + * @param typeList list of YANG type. | ||
| 86 | + */ | ||
| 87 | + public void setTypeList(List<YangType<?>> typeList) { | ||
| 88 | + this.typeList = typeList; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * Set the union name. | ||
| 93 | + * | ||
| 94 | + * @param unionName name of the union. | ||
| 95 | + */ | ||
| 96 | + public void setUnionName(String unionName) { | ||
| 97 | + this.unionName = unionName; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Override | ||
| 101 | + public YangConstructType getYangConstructType() { | ||
| 102 | + return YangConstructType.UNION_DATA; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void validateDataOnEntry() throws DataModelException { | ||
| 107 | + //TODO: implement the method. | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public void validateDataOnExit() throws DataModelException { | ||
| 112 | + //TODO: implement the method. | ||
| 113 | + } | ||
| 114 | +} |
| ... | @@ -29,6 +29,8 @@ import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener; | ... | @@ -29,6 +29,8 @@ import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener; |
| 29 | import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener; | 29 | import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener; |
| 30 | import org.onosproject.yangutils.parser.impl.listeners.BitListener; | 30 | import org.onosproject.yangutils.parser.impl.listeners.BitListener; |
| 31 | import org.onosproject.yangutils.parser.impl.listeners.BitsListener; | 31 | import org.onosproject.yangutils.parser.impl.listeners.BitsListener; |
| 32 | +import org.onosproject.yangutils.parser.impl.listeners.CaseListener; | ||
| 33 | +import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener; | ||
| 32 | import org.onosproject.yangutils.parser.impl.listeners.ConfigListener; | 34 | import org.onosproject.yangutils.parser.impl.listeners.ConfigListener; |
| 33 | import org.onosproject.yangutils.parser.impl.listeners.ContactListener; | 35 | import org.onosproject.yangutils.parser.impl.listeners.ContactListener; |
| 34 | import org.onosproject.yangutils.parser.impl.listeners.ContainerListener; | 36 | import org.onosproject.yangutils.parser.impl.listeners.ContainerListener; |
| ... | @@ -54,6 +56,7 @@ import org.onosproject.yangutils.parser.impl.listeners.PresenceListener; | ... | @@ -54,6 +56,7 @@ import org.onosproject.yangutils.parser.impl.listeners.PresenceListener; |
| 54 | import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener; | 56 | import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener; |
| 55 | import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener; | 57 | import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener; |
| 56 | import org.onosproject.yangutils.parser.impl.listeners.RevisionListener; | 58 | import org.onosproject.yangutils.parser.impl.listeners.RevisionListener; |
| 59 | +import org.onosproject.yangutils.parser.impl.listeners.ShortCaseListener; | ||
| 57 | import org.onosproject.yangutils.parser.impl.listeners.StatusListener; | 60 | import org.onosproject.yangutils.parser.impl.listeners.StatusListener; |
| 58 | import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; | 61 | import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; |
| 59 | import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener; | 62 | import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener; |
| ... | @@ -914,32 +917,32 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -914,32 +917,32 @@ public class TreeWalkListener implements GeneratedYangListener { |
| 914 | 917 | ||
| 915 | @Override | 918 | @Override |
| 916 | public void enterChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) { | 919 | public void enterChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) { |
| 917 | - // TODO: implement the method. | 920 | + ChoiceListener.processChoiceEntry(this, ctx); |
| 918 | } | 921 | } |
| 919 | 922 | ||
| 920 | @Override | 923 | @Override |
| 921 | public void exitChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) { | 924 | public void exitChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) { |
| 922 | - // TODO: implement the method. | 925 | + ChoiceListener.processChoiceExit(this, ctx); |
| 923 | } | 926 | } |
| 924 | 927 | ||
| 925 | @Override | 928 | @Override |
| 926 | public void enterShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) { | 929 | public void enterShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) { |
| 927 | - // TODO: implement the method. | 930 | + ShortCaseListener.processShortCaseEntry(this, ctx); |
| 928 | } | 931 | } |
| 929 | 932 | ||
| 930 | @Override | 933 | @Override |
| 931 | public void exitShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) { | 934 | public void exitShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) { |
| 932 | - // TODO: implement the method. | 935 | + ShortCaseListener.processShortCaseExit(this, ctx); |
| 933 | } | 936 | } |
| 934 | 937 | ||
| 935 | @Override | 938 | @Override |
| 936 | public void enterCaseStatement(GeneratedYangParser.CaseStatementContext ctx) { | 939 | public void enterCaseStatement(GeneratedYangParser.CaseStatementContext ctx) { |
| 937 | - // TODO: implement the method. | 940 | + CaseListener.processCaseEntry(this, ctx); |
| 938 | } | 941 | } |
| 939 | 942 | ||
| 940 | @Override | 943 | @Override |
| 941 | public void exitCaseStatement(GeneratedYangParser.CaseStatementContext ctx) { | 944 | public void exitCaseStatement(GeneratedYangParser.CaseStatementContext ctx) { |
| 942 | - // TODO: implement the method. | 945 | + CaseListener.processCaseExit(this, ctx); |
| 943 | } | 946 | } |
| 944 | 947 | ||
| 945 | @Override | 948 | @Override | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CaseListener.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2014-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.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
| 20 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 23 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 24 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
| 25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 26 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
| 27 | + | ||
| 28 | +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | ||
| 29 | +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangCaseNode; | ||
| 30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
| 31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
| 32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
| 33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
| 34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 35 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 36 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
| 37 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 38 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
| 39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
| 40 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
| 41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | ||
| 42 | +import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ||
| 43 | +import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | ||
| 44 | +import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | ||
| 45 | +import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ||
| 46 | +import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA; | ||
| 47 | + | ||
| 48 | +/* | ||
| 49 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
| 50 | + * | ||
| 51 | + * ABNF grammar as per RFC6020 | ||
| 52 | + * case-stmt = case-keyword sep identifier-arg-str optsep | ||
| 53 | + * (";" / | ||
| 54 | + * "{" stmtsep | ||
| 55 | + * ;; these stmts can appear in any order | ||
| 56 | + * [when-stmt stmtsep] | ||
| 57 | + * *(if-feature-stmt stmtsep) | ||
| 58 | + * [status-stmt stmtsep] | ||
| 59 | + * [description-stmt stmtsep] | ||
| 60 | + * [reference-stmt stmtsep] | ||
| 61 | + * *(data-def-stmt stmtsep) | ||
| 62 | + * "}") | ||
| 63 | + * | ||
| 64 | + * ANTLR grammar rule | ||
| 65 | + * caseStatement : CASE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | ||
| 66 | + * | statusStatement | descriptionStatement | referenceStatement | dataDefStatement)* RIGHT_CURLY_BRACE); | ||
| 67 | + */ | ||
| 68 | + | ||
| 69 | +/** | ||
| 70 | + * Implements listener based call back function corresponding to the "case" rule | ||
| 71 | + * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
| 72 | + */ | ||
| 73 | +public final class CaseListener { | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * Create a new case listener. | ||
| 77 | + */ | ||
| 78 | + private CaseListener() { | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * It is called when parser enters grammar rule (case), it perform | ||
| 83 | + * validations and updates the data model tree. | ||
| 84 | + * | ||
| 85 | + * @param listener listener's object | ||
| 86 | + * @param ctx context object of the grammar rule | ||
| 87 | + */ | ||
| 88 | + public static void processCaseEntry(TreeWalkListener listener, | ||
| 89 | + GeneratedYangParser.CaseStatementContext ctx) { | ||
| 90 | + | ||
| 91 | + // Check for stack to be non empty. | ||
| 92 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CASE_DATA, ctx.identifier().getText(), ENTRY); | ||
| 93 | + | ||
| 94 | + // Check validity of identifier and remove double quotes. | ||
| 95 | + String identifier = getValidIdentifier(ctx.identifier().getText(), CASE_DATA, ctx); | ||
| 96 | + | ||
| 97 | + // Validate sub statement cardinality. | ||
| 98 | + validateSubStatementsCardinality(ctx); | ||
| 99 | + | ||
| 100 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
| 101 | + | ||
| 102 | + // Check for identifier collision | ||
| 103 | + int line = ctx.getStart().getLine(); | ||
| 104 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
| 105 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CASE_DATA); | ||
| 106 | + | ||
| 107 | + if (curData instanceof YangChoice) { | ||
| 108 | + YangCase caseNode = getYangCaseNode(JAVA_GENERATION); | ||
| 109 | + caseNode.setName(identifier); | ||
| 110 | + YangNode curNode = (YangNode) curData; | ||
| 111 | + try { | ||
| 112 | + curNode.addChild(caseNode); | ||
| 113 | + } catch (DataModelException e) { | ||
| 114 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
| 115 | + CASE_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); | ||
| 116 | + } | ||
| 117 | + listener.getParsedDataStack().push(caseNode); | ||
| 118 | + } else { | ||
| 119 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CASE_DATA, | ||
| 120 | + ctx.identifier().getText(), ENTRY)); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * It is called when parser exits from grammar rule (case), it perform | ||
| 126 | + * validations and update the data model tree. | ||
| 127 | + * | ||
| 128 | + * @param listener Listener's object | ||
| 129 | + * @param ctx context object of the grammar rule | ||
| 130 | + */ | ||
| 131 | + public static void processCaseExit(TreeWalkListener listener, | ||
| 132 | + GeneratedYangParser.CaseStatementContext ctx) { | ||
| 133 | + | ||
| 134 | + // Check for stack to be non empty. | ||
| 135 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CASE_DATA, ctx.identifier().getText(), EXIT); | ||
| 136 | + | ||
| 137 | + if (listener.getParsedDataStack().peek() instanceof YangCase) { | ||
| 138 | + listener.getParsedDataStack().pop(); | ||
| 139 | + } else { | ||
| 140 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CASE_DATA, | ||
| 141 | + ctx.identifier().getText(), EXIT)); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * Validates the cardinality of case sub-statements as per grammar. | ||
| 147 | + * | ||
| 148 | + * @param ctx context object of the grammar rule | ||
| 149 | + */ | ||
| 150 | + private static void validateSubStatementsCardinality(GeneratedYangParser.CaseStatementContext ctx) { | ||
| 151 | + | ||
| 152 | + validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, CASE_DATA, ctx.identifier().getText()); | ||
| 153 | + validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, CASE_DATA, ctx.identifier().getText()); | ||
| 154 | + validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CASE_DATA, ctx.identifier().getText()); | ||
| 155 | + validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CASE_DATA, ctx.identifier().getText()); | ||
| 156 | + } | ||
| 157 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ChoiceListener.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2014-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.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
| 20 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
| 23 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
| 25 | +import org.onosproject.yangutils.datamodel.YangList; | ||
| 26 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 27 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 28 | +import org.onosproject.yangutils.datamodel.YangNotification; | ||
| 29 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
| 30 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
| 31 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 32 | +import org.onosproject.yangutils.parser.Parsable; | ||
| 33 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
| 34 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 35 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
| 36 | + | ||
| 37 | +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | ||
| 38 | +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangChoiceNode; | ||
| 39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
| 40 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
| 41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
| 42 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
| 43 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 44 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 45 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
| 46 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 47 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
| 48 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
| 49 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
| 50 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | ||
| 51 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 52 | +import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ||
| 53 | +import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA; | ||
| 54 | +import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA; | ||
| 55 | +import static org.onosproject.yangutils.utils.YangConstructType.DEFAULT_DATA; | ||
| 56 | +import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | ||
| 57 | +import static org.onosproject.yangutils.utils.YangConstructType.MANDATORY_DATA; | ||
| 58 | +import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | ||
| 59 | +import static org.onosproject.yangutils.utils.YangConstructType.SHORT_CASE_DATA; | ||
| 60 | +import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ||
| 61 | +import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA; | ||
| 62 | + | ||
| 63 | +/* | ||
| 64 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
| 65 | + * | ||
| 66 | + * ABNF grammar as per RFC6020 | ||
| 67 | + * choice-stmt = choice-keyword sep identifier-arg-str optsep | ||
| 68 | + * (";" / | ||
| 69 | + * "{" stmtsep | ||
| 70 | + * ;; these stmts can appear in any order | ||
| 71 | + * [when-stmt stmtsep] | ||
| 72 | + * *(if-feature-stmt stmtsep) | ||
| 73 | + * [default-stmt stmtsep] | ||
| 74 | + * [config-stmt stmtsep] | ||
| 75 | + * [mandatory-stmt stmtsep] | ||
| 76 | + * [status-stmt stmtsep] | ||
| 77 | + * [description-stmt stmtsep] | ||
| 78 | + * [reference-stmt stmtsep] | ||
| 79 | + * *((short-case-stmt / case-stmt) stmtsep) | ||
| 80 | + * "}") | ||
| 81 | + * | ||
| 82 | + * ANTLR grammar rule | ||
| 83 | + * choiceStatement : CHOICE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | ||
| 84 | + * | defaultStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement | ||
| 85 | + * | referenceStatement | shortCaseStatement | caseStatement)* RIGHT_CURLY_BRACE); | ||
| 86 | + */ | ||
| 87 | + | ||
| 88 | +/** | ||
| 89 | + * Implements listener based call back function corresponding to the "choice" | ||
| 90 | + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
| 91 | + */ | ||
| 92 | +public final class ChoiceListener { | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Create a new choice listener. | ||
| 96 | + */ | ||
| 97 | + private ChoiceListener() { | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * It is called when parser receives an input matching the grammar rule | ||
| 102 | + * (choice), perform validations and update the data model tree. | ||
| 103 | + * | ||
| 104 | + * @param listener Listener's object | ||
| 105 | + * @param ctx context object of the grammar rule | ||
| 106 | + */ | ||
| 107 | + public static void processChoiceEntry(TreeWalkListener listener, | ||
| 108 | + GeneratedYangParser.ChoiceStatementContext ctx) { | ||
| 109 | + | ||
| 110 | + // Check for stack to be non empty. | ||
| 111 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CHOICE_DATA, ctx.identifier().getText(), ENTRY); | ||
| 112 | + | ||
| 113 | + // Check validity of identifier and remove double quotes. | ||
| 114 | + String identifier = getValidIdentifier(ctx.identifier().getText(), CHOICE_DATA, ctx); | ||
| 115 | + | ||
| 116 | + // Validate sub statement cardinality. | ||
| 117 | + validateSubStatementsCardinality(ctx); | ||
| 118 | + | ||
| 119 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
| 120 | + | ||
| 121 | + // Check for identifier collision | ||
| 122 | + int line = ctx.getStart().getLine(); | ||
| 123 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
| 124 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CHOICE_DATA); | ||
| 125 | + | ||
| 126 | + if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer | ||
| 127 | + || curData instanceof YangList || curData instanceof YangCase || curData instanceof YangGrouping | ||
| 128 | + || curData instanceof YangAugment || curData instanceof YangInput || curData instanceof YangOutput | ||
| 129 | + || curData instanceof YangNotification) { | ||
| 130 | + | ||
| 131 | + YangChoice choiceNode = getYangChoiceNode(JAVA_GENERATION); | ||
| 132 | + choiceNode.setName(identifier); | ||
| 133 | + | ||
| 134 | + YangNode curNode = (YangNode) curData; | ||
| 135 | + try { | ||
| 136 | + curNode.addChild(choiceNode); | ||
| 137 | + } catch (DataModelException e) { | ||
| 138 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
| 139 | + CHOICE_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); | ||
| 140 | + } | ||
| 141 | + listener.getParsedDataStack().push(choiceNode); | ||
| 142 | + } else { | ||
| 143 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, | ||
| 144 | + CHOICE_DATA, ctx.identifier().getText(), ENTRY)); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * It is called when parser exits from grammar rule (choice), it perform | ||
| 150 | + * validations and update the data model tree. | ||
| 151 | + * | ||
| 152 | + * @param listener Listener's object | ||
| 153 | + * @param ctx context object of the grammar rule | ||
| 154 | + */ | ||
| 155 | + public static void processChoiceExit(TreeWalkListener listener, | ||
| 156 | + GeneratedYangParser.ChoiceStatementContext ctx) { | ||
| 157 | + | ||
| 158 | + // Check for stack to be non empty. | ||
| 159 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CHOICE_DATA, ctx.identifier().getText(), EXIT); | ||
| 160 | + | ||
| 161 | + if (listener.getParsedDataStack().peek() instanceof YangChoice) { | ||
| 162 | + listener.getParsedDataStack().pop(); | ||
| 163 | + } else { | ||
| 164 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CHOICE_DATA, | ||
| 165 | + ctx.identifier().getText(), EXIT)); | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * Validates the cardinality of choice sub-statements as per grammar. | ||
| 171 | + * | ||
| 172 | + * @param ctx context object of the grammar rule. | ||
| 173 | + */ | ||
| 174 | + private static void validateSubStatementsCardinality(GeneratedYangParser.ChoiceStatementContext ctx) { | ||
| 175 | + | ||
| 176 | + validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 177 | + validateCardinalityMaxOne(ctx.defaultStatement(), DEFAULT_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 178 | + validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 179 | + validateCardinalityMaxOne(ctx.mandatoryStatement(), MANDATORY_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 180 | + validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 181 | + validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CHOICE_DATA, | ||
| 182 | + ctx.identifier().getText()); | ||
| 183 | + validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CHOICE_DATA, ctx.identifier().getText()); | ||
| 184 | + validateMutuallyExclusiveChilds(ctx.shortCaseStatement(), SHORT_CASE_DATA, ctx.caseStatement(), CASE_DATA, | ||
| 185 | + CHOICE_DATA, ctx.identifier().getText()); | ||
| 186 | + } | ||
| 187 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ShortCaseListener.java
0 → 100644
| 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.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import org.antlr.v4.runtime.ParserRuleContext; | ||
| 20 | +import org.antlr.v4.runtime.tree.ParseTree; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
| 23 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 24 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
| 25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 26 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
| 27 | + | ||
| 28 | +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | ||
| 29 | +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangCaseNode; | ||
| 30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
| 31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
| 32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
| 33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
| 34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 35 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CHILD; | ||
| 36 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 37 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
| 38 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
| 40 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
| 41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
| 42 | +import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ||
| 43 | +import static org.onosproject.yangutils.utils.YangConstructType.SHORT_CASE_DATA; | ||
| 44 | + | ||
| 45 | +/* | ||
| 46 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
| 47 | + * | ||
| 48 | + * ABNF grammar as per RFC6020 | ||
| 49 | + * short-case-stmt = container-stmt / | ||
| 50 | + * leaf-stmt / | ||
| 51 | + * leaf-list-stmt / | ||
| 52 | + * list-stmt / | ||
| 53 | + * anyxml-stmt | ||
| 54 | + * | ||
| 55 | + * ANTLR grammar rule | ||
| 56 | + * shortCaseStatement : containerStatement | leafStatement | leafListStatement | listStatement; | ||
| 57 | + */ | ||
| 58 | + | ||
| 59 | +/** | ||
| 60 | + * Implements listener based call back function corresponding to the "short | ||
| 61 | + * case" rule defined in ANTLR grammar file for corresponding ABNF rule in RFC | ||
| 62 | + * 6020. | ||
| 63 | + */ | ||
| 64 | +public final class ShortCaseListener { | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Create a new short case listener. | ||
| 68 | + */ | ||
| 69 | + private ShortCaseListener() { | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * It is called when parser enters grammar rule (short case), it perform | ||
| 74 | + * validations and updates the data model tree. | ||
| 75 | + * | ||
| 76 | + * @param listener listener's object | ||
| 77 | + * @param ctx context object of the grammar rule | ||
| 78 | + */ | ||
| 79 | + public static void processShortCaseEntry(TreeWalkListener listener, | ||
| 80 | + GeneratedYangParser.ShortCaseStatementContext ctx) { | ||
| 81 | + | ||
| 82 | + ParseTree errorConstructContext; | ||
| 83 | + | ||
| 84 | + // Check for stack to be non empty. | ||
| 85 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, SHORT_CASE_DATA, "", ENTRY); | ||
| 86 | + | ||
| 87 | + YangCase caseNode = getYangCaseNode(JAVA_GENERATION); | ||
| 88 | + | ||
| 89 | + if (ctx.containerStatement() != null) { | ||
| 90 | + caseNode.setName(getValidIdentifier(ctx.containerStatement().identifier().getText(), CASE_DATA, ctx)); | ||
| 91 | + errorConstructContext = ctx.containerStatement(); | ||
| 92 | + } else if (ctx.listStatement() != null) { | ||
| 93 | + caseNode.setName(getValidIdentifier(ctx.listStatement().identifier().getText(), CASE_DATA, ctx)); | ||
| 94 | + errorConstructContext = ctx.listStatement(); | ||
| 95 | + } else if (ctx.leafListStatement() != null) { | ||
| 96 | + caseNode.setName(getValidIdentifier(ctx.leafListStatement().identifier().getText(), CASE_DATA, ctx)); | ||
| 97 | + errorConstructContext = ctx.leafListStatement(); | ||
| 98 | + } else if (ctx.leafStatement() != null) { | ||
| 99 | + caseNode.setName(getValidIdentifier(ctx.leafStatement().identifier().getText(), CASE_DATA, ctx)); | ||
| 100 | + errorConstructContext = ctx.leafStatement(); | ||
| 101 | + } else { | ||
| 102 | + throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, SHORT_CASE_DATA, "", ENTRY)); | ||
| 103 | + } | ||
| 104 | + // TODO implement for augment. | ||
| 105 | + | ||
| 106 | + int line = ((ParserRuleContext) errorConstructContext).getStart().getLine(); | ||
| 107 | + int charPositionInLine = ((ParserRuleContext) errorConstructContext).getStart().getCharPositionInLine(); | ||
| 108 | + | ||
| 109 | + // Check for identifier collision | ||
| 110 | + detectCollidingChildUtil(listener, line, charPositionInLine, caseNode.getName(), CASE_DATA); | ||
| 111 | + | ||
| 112 | + if ((listener.getParsedDataStack().peek()) instanceof YangChoice) { | ||
| 113 | + try { | ||
| 114 | + ((YangChoice) listener.getParsedDataStack().peek()).addChild(caseNode); | ||
| 115 | + } catch (DataModelException e) { | ||
| 116 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
| 117 | + SHORT_CASE_DATA, caseNode.getName(), ENTRY, e.getMessage())); | ||
| 118 | + } | ||
| 119 | + listener.getParsedDataStack().push(caseNode); | ||
| 120 | + } else { | ||
| 121 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, SHORT_CASE_DATA, | ||
| 122 | + caseNode.getName(), ENTRY)); | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * It is called when parser exits from grammar rule (short case), it perform | ||
| 128 | + * validations and update the data model tree. | ||
| 129 | + * | ||
| 130 | + * @param listener Listener's object | ||
| 131 | + * @param ctx context object of the grammar rule | ||
| 132 | + */ | ||
| 133 | + public static void processShortCaseExit(TreeWalkListener listener, | ||
| 134 | + GeneratedYangParser.ShortCaseStatementContext ctx) { | ||
| 135 | + | ||
| 136 | + // Check for stack to be non empty. | ||
| 137 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, SHORT_CASE_DATA, "", EXIT); | ||
| 138 | + | ||
| 139 | + if (listener.getParsedDataStack().peek() instanceof YangCase) { | ||
| 140 | + listener.getParsedDataStack().pop(); | ||
| 141 | + } else { | ||
| 142 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SHORT_CASE_DATA, | ||
| 143 | + "", EXIT)); | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | +} |
| 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.translator.tojava.javamodel; | ||
| 18 | + | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
| 21 | +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
| 22 | +import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
| 23 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
| 24 | +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | ||
| 25 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
| 26 | +import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
| 27 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
| 28 | + | ||
| 29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
| 30 | +import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
| 32 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
| 33 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
| 34 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
| 35 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
| 36 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * Input information extended to support java code generation. | ||
| 40 | + */ | ||
| 41 | +public class YangJavaInput extends YangInput | ||
| 42 | + implements JavaCodeGenerator, HasJavaFileInfo, | ||
| 43 | + HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Contains information of the java file being generated. | ||
| 47 | + */ | ||
| 48 | + private JavaFileInfo javaFileInfo; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Contains information of the imports to be inserted in the java file | ||
| 52 | + * generated. | ||
| 53 | + */ | ||
| 54 | + private JavaImportData javaImportData; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * File handle to maintain temporary java code fragments as per the code | ||
| 58 | + * snippet types. | ||
| 59 | + */ | ||
| 60 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Creates an instance of java input. | ||
| 64 | + */ | ||
| 65 | + public YangJavaInput() { | ||
| 66 | + super(); | ||
| 67 | + setJavaFileInfo(new JavaFileInfo()); | ||
| 68 | + setJavaImportData(new JavaImportData()); | ||
| 69 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Returns the generated java file information. | ||
| 74 | + * | ||
| 75 | + * @return generated java file information | ||
| 76 | + */ | ||
| 77 | + @Override | ||
| 78 | + public JavaFileInfo getJavaFileInfo() { | ||
| 79 | + | ||
| 80 | + if (javaFileInfo == null) { | ||
| 81 | + throw new RuntimeException("Missing java info in java datamodel node"); | ||
| 82 | + } | ||
| 83 | + return javaFileInfo; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Set the java file info object. | ||
| 88 | + * | ||
| 89 | + * @param javaInfo java file info object | ||
| 90 | + */ | ||
| 91 | + @Override | ||
| 92 | + public void setJavaFileInfo(JavaFileInfo javaInfo) { | ||
| 93 | + | ||
| 94 | + javaFileInfo = javaInfo; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Returns the data of java imports to be included in generated file. | ||
| 99 | + * | ||
| 100 | + * @return data of java imports to be included in generated file | ||
| 101 | + */ | ||
| 102 | + @Override | ||
| 103 | + public JavaImportData getJavaImportData() { | ||
| 104 | + | ||
| 105 | + return javaImportData; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * Set the data of java imports to be included in generated file. | ||
| 110 | + * | ||
| 111 | + * @param javaImportData data of java imports to be included in generated | ||
| 112 | + * file | ||
| 113 | + */ | ||
| 114 | + @Override | ||
| 115 | + public void setJavaImportData(JavaImportData javaImportData) { | ||
| 116 | + | ||
| 117 | + this.javaImportData = javaImportData; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Returns the temporary file handle. | ||
| 122 | + * | ||
| 123 | + * @return temporary file handle | ||
| 124 | + */ | ||
| 125 | + @Override | ||
| 126 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
| 127 | + | ||
| 128 | + if (tempFileHandle == null) { | ||
| 129 | + throw new RuntimeException("Missing temporary file handle for" + | ||
| 130 | + "current node " + getJavaFileInfo().getJavaName()); | ||
| 131 | + } | ||
| 132 | + return tempFileHandle; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * Set temporary file handle. | ||
| 137 | + * | ||
| 138 | + * @param fileHandle temporary file handle | ||
| 139 | + */ | ||
| 140 | + @Override | ||
| 141 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
| 142 | + | ||
| 143 | + tempFileHandle = fileHandle; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * Prepare the information for java code generation corresponding to YANG | ||
| 148 | + * container info. | ||
| 149 | + * | ||
| 150 | + * @param codeGenDir code generation directory | ||
| 151 | + * @throws IOException IO operation fail | ||
| 152 | + */ | ||
| 153 | + @Override | ||
| 154 | + public void generateCodeEntry(String codeGenDir) throws IOException { | ||
| 155 | + | ||
| 156 | + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
| 157 | + getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
| 158 | + getJavaFileInfo().setPackageFilePath( | ||
| 159 | + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
| 160 | + getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
| 161 | + | ||
| 162 | + String absloutePath = getAbsolutePackagePath( | ||
| 163 | + getJavaFileInfo().getBaseCodeGenPath(), | ||
| 164 | + getJavaFileInfo().getPackageFilePath()); | ||
| 165 | + createPackage(absloutePath, getName()); | ||
| 166 | + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
| 167 | + getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
| 168 | + getJavaFileInfo().getJavaName())); | ||
| 169 | + | ||
| 170 | + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
| 171 | + | ||
| 172 | + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * Create a java file using the YANG grouping info. | ||
| 177 | + * | ||
| 178 | + * @throws IOException IO operation fail | ||
| 179 | + */ | ||
| 180 | + @Override | ||
| 181 | + public void generateCodeExit() throws IOException { | ||
| 182 | + | ||
| 183 | + generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | ||
| 184 | + getTempJavaCodeFragmentFiles().close(); | ||
| 185 | + } | ||
| 186 | +} |
| 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.translator.tojava.javamodel; | ||
| 18 | + | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
| 21 | +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
| 22 | +import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
| 23 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
| 24 | +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | ||
| 25 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
| 26 | +import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
| 27 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
| 28 | + | ||
| 29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
| 30 | +import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
| 32 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
| 33 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | ||
| 34 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
| 35 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
| 36 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * Output information extended to support java code generation. | ||
| 40 | + */ | ||
| 41 | +public class YangJavaOutput extends YangOutput | ||
| 42 | + implements JavaCodeGenerator, HasJavaFileInfo, | ||
| 43 | + HasJavaImportData, HasTempJavaCodeFragmentFiles { | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Contains information of the java file being generated. | ||
| 47 | + */ | ||
| 48 | + private JavaFileInfo javaFileInfo; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Contains information of the imports to be inserted in the java file | ||
| 52 | + * generated. | ||
| 53 | + */ | ||
| 54 | + private JavaImportData javaImportData; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * File handle to maintain temporary java code fragments as per the code | ||
| 58 | + * snippet types. | ||
| 59 | + */ | ||
| 60 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Creates an instance of java output. | ||
| 64 | + */ | ||
| 65 | + public YangJavaOutput() { | ||
| 66 | + super(); | ||
| 67 | + setJavaFileInfo(new JavaFileInfo()); | ||
| 68 | + setJavaImportData(new JavaImportData()); | ||
| 69 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Returns the generated java file information. | ||
| 74 | + * | ||
| 75 | + * @return generated java file information | ||
| 76 | + */ | ||
| 77 | + @Override | ||
| 78 | + public JavaFileInfo getJavaFileInfo() { | ||
| 79 | + | ||
| 80 | + if (javaFileInfo == null) { | ||
| 81 | + throw new RuntimeException("Missing java info in java datamodel node"); | ||
| 82 | + } | ||
| 83 | + return javaFileInfo; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Set the java file info object. | ||
| 88 | + * | ||
| 89 | + * @param javaInfo java file info object | ||
| 90 | + */ | ||
| 91 | + @Override | ||
| 92 | + public void setJavaFileInfo(JavaFileInfo javaInfo) { | ||
| 93 | + | ||
| 94 | + javaFileInfo = javaInfo; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Returns the data of java imports to be included in generated file. | ||
| 99 | + * | ||
| 100 | + * @return data of java imports to be included in generated file | ||
| 101 | + */ | ||
| 102 | + @Override | ||
| 103 | + public JavaImportData getJavaImportData() { | ||
| 104 | + | ||
| 105 | + return javaImportData; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * Set the data of java imports to be included in generated file. | ||
| 110 | + * | ||
| 111 | + * @param javaImportData data of java imports to be included in generated | ||
| 112 | + * file | ||
| 113 | + */ | ||
| 114 | + @Override | ||
| 115 | + public void setJavaImportData(JavaImportData javaImportData) { | ||
| 116 | + | ||
| 117 | + this.javaImportData = javaImportData; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Returns the temporary file handle. | ||
| 122 | + * | ||
| 123 | + * @return temporary file handle | ||
| 124 | + */ | ||
| 125 | + @Override | ||
| 126 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
| 127 | + | ||
| 128 | + if (tempFileHandle == null) { | ||
| 129 | + throw new RuntimeException("Missing temporary file handle for" + | ||
| 130 | + "current node " + getJavaFileInfo().getJavaName()); | ||
| 131 | + } | ||
| 132 | + return tempFileHandle; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * Set temporary file handle. | ||
| 137 | + * | ||
| 138 | + * @param fileHandle temporary file handle | ||
| 139 | + */ | ||
| 140 | + @Override | ||
| 141 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
| 142 | + | ||
| 143 | + tempFileHandle = fileHandle; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * Prepare the information for java code generation corresponding to YANG | ||
| 148 | + * container info. | ||
| 149 | + * | ||
| 150 | + * @param codeGenDir code generation directory | ||
| 151 | + * @throws IOException IO operation fail | ||
| 152 | + */ | ||
| 153 | + @Override | ||
| 154 | + public void generateCodeEntry(String codeGenDir) throws IOException { | ||
| 155 | + | ||
| 156 | + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | ||
| 157 | + getJavaFileInfo().setPackage(getCurNodePackage(this)); | ||
| 158 | + getJavaFileInfo().setPackageFilePath( | ||
| 159 | + getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | ||
| 160 | + getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | ||
| 161 | + | ||
| 162 | + String absloutePath = getAbsolutePackagePath( | ||
| 163 | + getJavaFileInfo().getBaseCodeGenPath(), | ||
| 164 | + getJavaFileInfo().getPackageFilePath()); | ||
| 165 | + createPackage(absloutePath, getName()); | ||
| 166 | + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
| 167 | + getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
| 168 | + getJavaFileInfo().getJavaName())); | ||
| 169 | + | ||
| 170 | + getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
| 171 | + | ||
| 172 | + getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * Create a java file using the YANG grouping info. | ||
| 177 | + * | ||
| 178 | + * @throws IOException IO operation fail | ||
| 179 | + */ | ||
| 180 | + @Override | ||
| 181 | + public void generateCodeExit() throws IOException { | ||
| 182 | + | ||
| 183 | + generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | ||
| 184 | + getTempJavaCodeFragmentFiles().close(); | ||
| 185 | + } | ||
| 186 | +} |
| ... | @@ -235,6 +235,41 @@ public enum YangConstructType { | ... | @@ -235,6 +235,41 @@ public enum YangConstructType { |
| 235 | DATA_DEF_DATA, | 235 | DATA_DEF_DATA, |
| 236 | 236 | ||
| 237 | /** | 237 | /** |
| 238 | + * Identifies the YANG union element parsed data. | ||
| 239 | + */ | ||
| 240 | + UNION_DATA, | ||
| 241 | + | ||
| 242 | + /** | ||
| 243 | + * Identifies the YANG notification element parsed data. | ||
| 244 | + */ | ||
| 245 | + NOTIFICATION_DATA, | ||
| 246 | + | ||
| 247 | + /** | ||
| 248 | + * Identifies the YANG when element parsed data. | ||
| 249 | + */ | ||
| 250 | + WHEN_DATA, | ||
| 251 | + | ||
| 252 | + /** | ||
| 253 | + * Identifies the YANG input element parsed data. | ||
| 254 | + */ | ||
| 255 | + INPUT_DATA, | ||
| 256 | + | ||
| 257 | + /** | ||
| 258 | + * Identifies the YANG output element parsed data. | ||
| 259 | + */ | ||
| 260 | + OUTPUT_DATA, | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * Identifies the YANG rpc element parsed data. | ||
| 264 | + */ | ||
| 265 | + RPC_DATA, | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * Identifies the YANG short case element parsed data. | ||
| 269 | + */ | ||
| 270 | + SHORT_CASE_DATA, | ||
| 271 | + | ||
| 272 | + /** | ||
| 238 | * Identifies the derived data type. | 273 | * Identifies the derived data type. |
| 239 | */ | 274 | */ |
| 240 | DERIVED; | 275 | DERIVED; |
| ... | @@ -334,8 +369,22 @@ public enum YangConstructType { | ... | @@ -334,8 +369,22 @@ public enum YangConstructType { |
| 334 | return "default"; | 369 | return "default"; |
| 335 | case DATA_DEF_DATA: | 370 | case DATA_DEF_DATA: |
| 336 | return "data-def-substatements"; | 371 | return "data-def-substatements"; |
| 372 | + case WHEN_DATA: | ||
| 373 | + return "when"; | ||
| 374 | + case INPUT_DATA: | ||
| 375 | + return "input"; | ||
| 376 | + case OUTPUT_DATA: | ||
| 377 | + return "ouput"; | ||
| 378 | + case RPC_DATA: | ||
| 379 | + return "rpc"; | ||
| 380 | + case SHORT_CASE_DATA: | ||
| 381 | + return "short-case"; | ||
| 337 | case DERIVED: | 382 | case DERIVED: |
| 338 | return "derived"; | 383 | return "derived"; |
| 384 | + case NOTIFICATION_DATA: | ||
| 385 | + return "notification"; | ||
| 386 | + case UNION_DATA: | ||
| 387 | + return "union"; | ||
| 339 | default: | 388 | default: |
| 340 | return "yang"; | 389 | return "yang"; |
| 341 | } | 390 | } | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CaseListenerTest.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2014-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.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 20 | +import static org.hamcrest.core.Is.is; | ||
| 21 | +import org.junit.Test; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
| 23 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
| 25 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
| 26 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 27 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 28 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
| 29 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 30 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
| 31 | + | ||
| 32 | +import java.io.IOException; | ||
| 33 | +import java.util.ListIterator; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * Test cases for case listener. | ||
| 37 | + */ | ||
| 38 | +public class CaseListenerTest { | ||
| 39 | + | ||
| 40 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Checks multiple case statement. | ||
| 44 | + */ | ||
| 45 | + @Test | ||
| 46 | + public void processCaseStatement() throws IOException, ParserException { | ||
| 47 | + | ||
| 48 | + YangNode node = manager.getDataModel("src/test/resources/CaseStatement.yang"); | ||
| 49 | + | ||
| 50 | + // Check whether the data model tree returned is of type module. | ||
| 51 | + assertThat((node instanceof YangModule), is(true)); | ||
| 52 | + | ||
| 53 | + // Check whether the node type is set properly to module. | ||
| 54 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 55 | + | ||
| 56 | + // Check whether the module name is set correctly. | ||
| 57 | + YangModule yangNode = (YangModule) node; | ||
| 58 | + assertThat(yangNode.getName(), is("Test")); | ||
| 59 | + | ||
| 60 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
| 61 | + assertThat(yangContainer.getName(), is("food")); | ||
| 62 | + | ||
| 63 | + YangChoice yangChoice = (YangChoice) yangContainer.getChild(); | ||
| 64 | + assertThat(yangChoice.getName(), is("snack")); | ||
| 65 | + | ||
| 66 | + YangCase yangCase1 = (YangCase) yangChoice.getChild(); | ||
| 67 | + assertThat(yangCase1.getName(), is("sports-arena")); | ||
| 68 | + | ||
| 69 | + // Check whether leaf properties as set correctly. | ||
| 70 | + ListIterator<YangLeaf> leafIterator1 = yangCase1.getListOfLeaf().listIterator(); | ||
| 71 | + YangLeaf leafInfo1 = leafIterator1.next(); | ||
| 72 | + | ||
| 73 | + assertThat(leafInfo1.getLeafName(), is("pretzel")); | ||
| 74 | + | ||
| 75 | + YangCase yangCase2 = (YangCase) yangCase1.getNextSibling(); | ||
| 76 | + assertThat(yangCase2.getName(), is("late-night")); | ||
| 77 | + | ||
| 78 | + // Check whether leaf properties as set correctly. | ||
| 79 | + ListIterator<YangLeaf> leafIterator2 = yangCase2.getListOfLeaf().listIterator(); | ||
| 80 | + YangLeaf leafInfo2 = leafIterator2.next(); | ||
| 81 | + | ||
| 82 | + assertThat(leafInfo2.getLeafName(), is("chocolate")); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Checks duplicate case in choice. | ||
| 87 | + */ | ||
| 88 | + @Test(expected = ParserException.class) | ||
| 89 | + public void processDuplicateCaseInChoice() throws IOException, ParserException { | ||
| 90 | + | ||
| 91 | + YangNode node = manager.getDataModel("src/test/resources/DuplicateCaseInChoice.yang"); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Checks duplicate leaf at different hierarchy. | ||
| 96 | + */ | ||
| 97 | + @Test(expected = ParserException.class) | ||
| 98 | + public void processDuplicateLeafInHierarchy() throws IOException, ParserException { | ||
| 99 | + | ||
| 100 | + YangNode node = manager.getDataModel("src/test/resources/DuplicateLeafInHierarchy.yang"); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Checks duplicate leaf in different case within choice. | ||
| 105 | + */ | ||
| 106 | + @Test(expected = ParserException.class) | ||
| 107 | + public void processDuplicateLeafInChoice() throws IOException, ParserException { | ||
| 108 | + | ||
| 109 | + YangNode node = manager.getDataModel("src/test/resources/DuplicateLeafInChoice.yang"); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * Checks same case within different choice. | ||
| 114 | + */ | ||
| 115 | + @Test | ||
| 116 | + public void processCaseStatementSameEntryDifferentChoice() throws IOException, ParserException { | ||
| 117 | + | ||
| 118 | + YangNode node = manager.getDataModel("src/test/resources/CaseStatementSameEntryDifferentChoice.yang"); | ||
| 119 | + | ||
| 120 | + // Check whether the data model tree returned is of type module. | ||
| 121 | + assertThat((node instanceof YangModule), is(true)); | ||
| 122 | + | ||
| 123 | + // Check whether the node type is set properly to module. | ||
| 124 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 125 | + | ||
| 126 | + // Check whether the module name is set correctly. | ||
| 127 | + YangModule yangNode = (YangModule) node; | ||
| 128 | + assertThat(yangNode.getName(), is("Test")); | ||
| 129 | + | ||
| 130 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
| 131 | + assertThat(yangContainer.getName(), is("food")); | ||
| 132 | + | ||
| 133 | + YangChoice yangChoice = (YangChoice) yangContainer.getChild(); | ||
| 134 | + assertThat(yangChoice.getName(), is("snack")); | ||
| 135 | + | ||
| 136 | + YangCase yangCase1 = (YangCase) yangChoice.getChild(); | ||
| 137 | + assertThat(yangCase1.getName(), is("sports-arena")); | ||
| 138 | + | ||
| 139 | + // Check whether leaf properties as set correctly. | ||
| 140 | + ListIterator<YangLeaf> leafIterator1 = yangCase1.getListOfLeaf().listIterator(); | ||
| 141 | + YangLeaf leafInfo1 = leafIterator1.next(); | ||
| 142 | + | ||
| 143 | + assertThat(leafInfo1.getLeafName(), is("pretzel")); | ||
| 144 | + | ||
| 145 | + YangChoice yangChoice2 = (YangChoice) yangChoice.getNextSibling(); | ||
| 146 | + assertThat(yangChoice2.getName(), is("lunch")); | ||
| 147 | + | ||
| 148 | + YangCase yangCase2 = (YangCase) yangChoice2.getChild(); | ||
| 149 | + assertThat(yangCase2.getName(), is("sports-arena")); | ||
| 150 | + | ||
| 151 | + // Check whether leaf properties as set correctly. | ||
| 152 | + ListIterator<YangLeaf> leafIterator2 = yangCase2.getListOfLeaf().listIterator(); | ||
| 153 | + YangLeaf leafInfo2 = leafIterator2.next(); | ||
| 154 | + | ||
| 155 | + assertThat(leafInfo2.getLeafName(), is("chocolate")); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * Checks case choice hierarchy. | ||
| 160 | + */ | ||
| 161 | + @Test | ||
| 162 | + public void processCaseChoiceHierarchy() throws IOException, ParserException { | ||
| 163 | + | ||
| 164 | + YangNode node = manager.getDataModel("src/test/resources/CaseChoiceHierarchy.yang"); | ||
| 165 | + | ||
| 166 | + // Check whether the data model tree returned is of type module. | ||
| 167 | + assertThat((node instanceof YangModule), is(true)); | ||
| 168 | + | ||
| 169 | + // Check whether the node type is set properly to module. | ||
| 170 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 171 | + | ||
| 172 | + // Check whether the module name is set correctly. | ||
| 173 | + YangModule yangNode = (YangModule) node; | ||
| 174 | + assertThat(yangNode.getName(), is("Test")); | ||
| 175 | + | ||
| 176 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
| 177 | + assertThat(yangContainer.getName(), is("food")); | ||
| 178 | + | ||
| 179 | + YangChoice yangChoice1 = (YangChoice) yangContainer.getChild(); | ||
| 180 | + assertThat(yangChoice1.getName(), is("snack")); | ||
| 181 | + | ||
| 182 | + YangCase yangCase1 = (YangCase) yangChoice1.getChild(); | ||
| 183 | + assertThat(yangCase1.getName(), is("sports-arena")); | ||
| 184 | + | ||
| 185 | + // Check whether leaf properties as set correctly. | ||
| 186 | + ListIterator<YangLeaf> leafIterator1 = yangCase1.getListOfLeaf().listIterator(); | ||
| 187 | + YangLeaf leafInfo1 = leafIterator1.next(); | ||
| 188 | + | ||
| 189 | + assertThat(leafInfo1.getLeafName(), is("pretzel")); | ||
| 190 | + | ||
| 191 | + YangCase yangCase2 = (YangCase) yangCase1.getNextSibling(); | ||
| 192 | + assertThat(yangCase2.getName(), is("late-night")); | ||
| 193 | + | ||
| 194 | + YangChoice yangChoice2 = (YangChoice) yangCase2.getChild(); | ||
| 195 | + assertThat(yangChoice2.getName(), is("dinner")); | ||
| 196 | + | ||
| 197 | + YangCase yangCase3 = (YangCase) yangChoice2.getChild(); | ||
| 198 | + assertThat(yangCase3.getName(), is("late-night")); | ||
| 199 | + | ||
| 200 | + // Check whether leaf properties as set correctly. | ||
| 201 | + ListIterator<YangLeaf> leafIterator2 = yangCase3.getListOfLeaf().listIterator(); | ||
| 202 | + YangLeaf leafInfo2 = leafIterator2.next(); | ||
| 203 | + assertThat(leafInfo2.getLeafName(), is("beer")); | ||
| 204 | + } | ||
| 205 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014-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.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 20 | +import static org.hamcrest.core.Is.is; | ||
| 21 | +import org.junit.Test; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
| 23 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 25 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 26 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
| 27 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 28 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
| 29 | + | ||
| 30 | +import java.io.IOException; | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * Test cases for choice listener. | ||
| 34 | + */ | ||
| 35 | +public class ChoiceListenerTest { | ||
| 36 | + | ||
| 37 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * Checks choice statement without body. | ||
| 41 | + */ | ||
| 42 | + @Test | ||
| 43 | + public void processChoiceStatementWithoutBody() throws IOException, ParserException { | ||
| 44 | + | ||
| 45 | + YangNode node = manager.getDataModel("src/test/resources/ChoiceStatementWithoutBody.yang"); | ||
| 46 | + | ||
| 47 | + // Check whether the data model tree returned is of type module. | ||
| 48 | + assertThat((node instanceof YangModule), is(true)); | ||
| 49 | + | ||
| 50 | + // Check whether the node type is set properly to module. | ||
| 51 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 52 | + | ||
| 53 | + // Check whether the module name is set correctly. | ||
| 54 | + YangModule yangNode = (YangModule) node; | ||
| 55 | + assertThat(yangNode.getName(), is("Test")); | ||
| 56 | + | ||
| 57 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
| 58 | + assertThat(yangContainer.getName(), is("food")); | ||
| 59 | + | ||
| 60 | + YangChoice yangChoice = (YangChoice) yangContainer.getChild(); | ||
| 61 | + assertThat(yangChoice.getName(), is("snack")); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Checks choice statement with stmt end. | ||
| 66 | + */ | ||
| 67 | + @Test | ||
| 68 | + public void processChoiceStatementWithStmtend() throws IOException, ParserException { | ||
| 69 | + | ||
| 70 | + YangNode node = manager.getDataModel("src/test/resources/ChoiceStatementWithStmtend.yang"); | ||
| 71 | + | ||
| 72 | + // Check whether the data model tree returned is of type module. | ||
| 73 | + assertThat((node instanceof YangModule), is(true)); | ||
| 74 | + | ||
| 75 | + // Check whether the node type is set properly to module. | ||
| 76 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 77 | + | ||
| 78 | + // Check whether the module name is set correctly. | ||
| 79 | + YangModule yangNode = (YangModule) node; | ||
| 80 | + assertThat(yangNode.getName(), is("Test")); | ||
| 81 | + | ||
| 82 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
| 83 | + assertThat(yangContainer.getName(), is("food")); | ||
| 84 | + | ||
| 85 | + YangChoice yangChoice = (YangChoice) yangContainer.getChild(); | ||
| 86 | + assertThat(yangChoice.getName(), is("snack")); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Checks choice statement duplicate entry. | ||
| 91 | + */ | ||
| 92 | + @Test(expected = ParserException.class) | ||
| 93 | + public void processChoiceStatementDuplicateEntry() throws IOException, ParserException { | ||
| 94 | + | ||
| 95 | + YangNode node = manager.getDataModel("src/test/resources/ChoiceStatementDuplicateEntry.yang"); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * Checks choice statement with same entry in two different container. | ||
| 100 | + */ | ||
| 101 | + @Test | ||
| 102 | + public void processChoiceStatementSameEntryDifferentContainer() throws IOException, ParserException { | ||
| 103 | + | ||
| 104 | + YangNode node = manager.getDataModel("src/test/resources/ChoiceStatementSameEntryDifferentContainer.yang"); | ||
| 105 | + | ||
| 106 | + // Check whether the data model tree returned is of type module. | ||
| 107 | + assertThat((node instanceof YangModule), is(true)); | ||
| 108 | + | ||
| 109 | + // Check whether the node type is set properly to module. | ||
| 110 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 111 | + | ||
| 112 | + // Check whether the module name is set correctly. | ||
| 113 | + YangModule yangNode = (YangModule) node; | ||
| 114 | + assertThat(yangNode.getName(), is("Test")); | ||
| 115 | + | ||
| 116 | + YangContainer yangContainer1 = (YangContainer) yangNode.getChild(); | ||
| 117 | + assertThat(yangContainer1.getName(), is("food1")); | ||
| 118 | + | ||
| 119 | + YangChoice yangChoice1 = (YangChoice) yangContainer1.getChild(); | ||
| 120 | + assertThat(yangChoice1.getName(), is("snack")); | ||
| 121 | + | ||
| 122 | + YangContainer yangContainer2 = (YangContainer) yangNode.getChild().getNextSibling(); | ||
| 123 | + assertThat(yangContainer2.getName(), is("food2")); | ||
| 124 | + | ||
| 125 | + YangChoice yangChoice2 = (YangChoice) yangContainer2.getChild(); | ||
| 126 | + assertThat(yangChoice2.getName(), is("snack")); | ||
| 127 | + } | ||
| 128 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + case late-night { | ||
| 13 | + choice dinner { | ||
| 14 | + case late-night { | ||
| 15 | + leaf beer { | ||
| 16 | + type empty; | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + leaf beer { | ||
| 12 | + type empty; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + case late-night { | ||
| 16 | + leaf chocolate { | ||
| 17 | + type enumeration { | ||
| 18 | + enum dark; | ||
| 19 | + enum milk; | ||
| 20 | + enum first-available; | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + leaf beer { | ||
| 12 | + type empty; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + choice lunch { | ||
| 17 | + case sports-arena { | ||
| 18 | + leaf chocolate { | ||
| 19 | + type enumeration { | ||
| 20 | + enum dark; | ||
| 21 | + enum milk; | ||
| 22 | + enum first-available; | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + leaf beer { | ||
| 12 | + type empty; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + case sports-arena { | ||
| 16 | + leaf chocolate { | ||
| 17 | + type enumeration { | ||
| 18 | + enum dark; | ||
| 19 | + enum milk; | ||
| 20 | + enum first-available; | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + leaf beer { | ||
| 12 | + type empty; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + case late-night { | ||
| 16 | + leaf pretzel { | ||
| 17 | + type empty; | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | +} |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type empty; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + case late-night { | ||
| 13 | + choice lunch { | ||
| 14 | + case late { | ||
| 15 | + leaf pretzel { | ||
| 16 | + type empty; | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | +} |
-
Please register or login to post a comment