blob: f06ca0129cad4ce126f2e112402059fdd2aad92f [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
19import java.util.LinkedList;
20import java.util.List;
Bharat saraswald9822e92016-04-05 15:13:44 +053021
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053023import org.onosproject.yangutils.datamodel.utils.Parsable;
24import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053025
26import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
27
28/*
29 * Reference RFC 6020.
30 *
31 * The "output" statement, which is optional, is used to define output
32 * parameters to the RPC operation. It does not take an argument. The
33 * substatements to "output" define nodes under the RPC's output node.
34 *
35 * If a leaf in the output tree has a "mandatory" statement with the
36 * value "true", the leaf MUST be present in a NETCONF RPC reply.
37 *
38 * If a leaf in the output tree has a default value, the NETCONF client
39 * MUST use this value in the same cases as described in Section 7.6.1.
40 * In these cases, the client MUST operationally behave as if the leaf
41 * was present in the NETCONF RPC reply with the default value as its
42 * value.
43 *
44 * If a "config" statement is present for any node in the output 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 output tree.
49 *
50 * The output 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/**
Bharat saraswald9822e92016-04-05 15:13:44 +053068 * Represents data model node to maintain information defined in YANG output.
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053069 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053070public class YangOutput
71 extends YangNode
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053072 implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053073
Bharat saraswal96dfef02016-06-16 00:29:12 +053074 private static final long serialVersionUID = 806201612L;
75
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053076 /**
77 * Name of the output.
78 */
79 private String name;
80
81 /**
82 * List of leaves contained.
83 */
84 private List<YangLeaf> listOfLeaf;
85
86 /**
87 * List of leaf-lists contained.
88 */
89 private List<YangLeafList> listOfLeafList;
90
91 /**
92 * Create a rpc output node.
93 */
94 public YangOutput() {
95 super(YangNodeType.OUTPUT_NODE);
96 listOfLeaf = new LinkedList<YangLeaf>();
97 listOfLeafList = new LinkedList<YangLeafList>();
98 }
99
100 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530101 public void detectCollidingChild(String identifierName, YangConstructType dataType)
102 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530103 // Detect colliding child.
104 detectCollidingChildUtil(identifierName, dataType, this);
105 }
106
107 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530108 public void detectSelfCollision(String identifierName, YangConstructType dataType)
109 throws DataModelException {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530110 if (getName().equals(identifierName)) {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530111 throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \""
Bharat saraswal96dfef02016-06-16 00:29:12 +0530112 + getName() + "\"");
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530113 }
114 }
115
116 @Override
117 public YangConstructType getYangConstructType() {
118 return YangConstructType.OUTPUT_DATA;
119 }
120
121 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530122 public void validateDataOnEntry()
123 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530124 //TODO: implement the method.
125 }
126
127 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530128 public void validateDataOnExit()
129 throws DataModelException {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530130 //TODO: implement the method.
131 }
132
133 @Override
134 public List<YangLeaf> getListOfLeaf() {
135 return listOfLeaf;
136 }
137
138 @Override
139 public void addLeaf(YangLeaf leaf) {
140 getListOfLeaf().add(leaf);
141 }
142
143 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530144 public void setListOfLeaf(List<YangLeaf> leafsList) {
145 listOfLeaf = leafsList;
146 }
147
148 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530149 public List<YangLeafList> getListOfLeafList() {
150 return listOfLeafList;
151 }
152
153 @Override
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530154 public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
155 this.listOfLeafList = listOfLeafList;
156 }
157
158
159 @Override
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +0530160 public void addLeafList(YangLeafList leafList) {
161 getListOfLeafList().add(leafList);
162 }
163
164 @Override
165 public String getName() {
166 return name;
167 }
168
169 @Override
170 public void setName(String name) {
171 this.name = name;
172 }
173}