blob: 0e496bbea1f4280f001b54632a72e6a8194e7156 [file] [log] [blame]
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05303 *
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
17package org.onosproject.yangutils.datamodel;
18
Bharat saraswalb1170bd2016-07-14 13:26:18 +053019import java.util.ArrayList;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053020import java.util.LinkedList;
21import java.util.List;
Bharat saraswald9822e92016-04-05 15:13:44 +053022
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053023import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053024import org.onosproject.yangutils.datamodel.utils.Parsable;
25import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053026
27import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
28
29/*
30 * Reference RFC 6020.
31 *
32 * The "output" statement, which is optional, is used to define output
33 * parameters to the RPC operation. It does not take an argument. The
34 * substatements to "output" define nodes under the RPC's output node.
35 *
36 * If a leaf in the output tree has a "mandatory" statement with the
37 * value "true", the leaf MUST be present in a NETCONF RPC reply.
38 *
39 * If a leaf in the output tree has a default value, the NETCONF client
40 * MUST use this value in the same cases as described in Section 7.6.1.
41 * In these cases, the client MUST operationally behave as if the leaf
42 * was present in the NETCONF RPC reply with the default value as its
43 * value.
44 *
45 * If a "config" statement is present for any node in the output tree,
46 * the "config" statement is ignored.
47 *
48 * If any node has a "when" statement that would evaluate to false, then
49 * this node MUST NOT be present in the output tree.
50 *
51 * The output substatements
52 *
53 * +--------------+---------+-------------+------------------+
54 * | substatement | section | cardinality |data model mapping|
55 * +--------------+---------+-------------+------------------+
56 * | anyxml | 7.10 | 0..n | -not supported |
57 * | choice | 7.9 | 0..n | -child nodes |
58 * | container | 7.5 | 0..n | -child nodes |
59 * | grouping | 7.11 | 0..n | -child nodes |
60 * | leaf | 7.6 | 0..n | -YangLeaf |
61 * | leaf-list | 7.7 | 0..n | -YangLeafList |
62 * | list | 7.8 | 0..n | -child nodes |
63 * | typedef | 7.3 | 0..n | -child nodes |
64 * | uses | 7.12 | 0..n | -child nodes |
65 * +--------------+---------+-------------+------------------+
66 */
67
68/**
Bharat saraswald9822e92016-04-05 15:13:44 +053069 * Represents data model node to maintain information defined in YANG output.
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053070 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053071public class YangOutput
72 extends YangNode
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053073 implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053074
Bharat saraswal96dfef02016-06-16 00:29:12 +053075 private static final long serialVersionUID = 806201612L;
76
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053077 /**
78 * Name of the output.
79 */
80 private String name;
81
82 /**
83 * List of leaves contained.
84 */
85 private List<YangLeaf> listOfLeaf;
86
87 /**
88 * List of leaf-lists contained.
89 */
90 private List<YangLeafList> listOfLeafList;
91
Bharat saraswalb1170bd2016-07-14 13:26:18 +053092 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
93
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053094 /**
95 * Create a rpc output node.
96 */
97 public YangOutput() {
98 super(YangNodeType.OUTPUT_NODE);
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053099 listOfLeaf = new LinkedList<>();
100 listOfLeafList = new LinkedList<>();
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530101 }
102
103 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530104 public void detectCollidingChild(String identifierName, YangConstructType dataType)
105 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530106 // Detect colliding child.
107 detectCollidingChildUtil(identifierName, dataType, this);
108 }
109
110 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530111 public void detectSelfCollision(String identifierName, YangConstructType dataType)
112 throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530113 if (getName().equals(identifierName)) {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530114 throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \""
Bharat saraswal96dfef02016-06-16 00:29:12 +0530115 + getName() + "\"");
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530116 }
117 }
118
119 @Override
120 public YangConstructType getYangConstructType() {
121 return YangConstructType.OUTPUT_DATA;
122 }
123
124 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530125 public void validateDataOnEntry()
126 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530127 //TODO: implement the method.
128 }
129
130 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530131 public void validateDataOnExit()
132 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530133 //TODO: implement the method.
134 }
135
136 @Override
137 public List<YangLeaf> getListOfLeaf() {
138 return listOfLeaf;
139 }
140
141 @Override
142 public void addLeaf(YangLeaf leaf) {
143 getListOfLeaf().add(leaf);
144 }
145
146 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530147 public void setListOfLeaf(List<YangLeaf> leafsList) {
148 listOfLeaf = leafsList;
149 }
150
151 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530152 public List<YangLeafList> getListOfLeafList() {
153 return listOfLeafList;
154 }
155
156 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530157 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
158 this.listOfLeafList = listOfLeafList;
159 }
160
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530161 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530162 public void addLeafList(YangLeafList leafList) {
163 getListOfLeafList().add(leafList);
164 }
165
166 @Override
167 public String getName() {
168 return name;
169 }
170
171 @Override
172 public void setName(String name) {
173 this.name = name;
174 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530175
176 @Override
177 public void addAugmentation(YangAugmentedInfo augmentInfo) {
178 yangAugmentedInfo.add(augmentInfo);
179 }
180
181 @Override
182 public void removeAugmentation(YangAugmentedInfo augmentInfo) {
183 yangAugmentedInfo.remove(augmentInfo);
184 }
185
186 @Override
187 public List<YangAugmentedInfo> getAugmentedInfoList() {
188 return yangAugmentedInfo;
189 }
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530190}