blob: 94ec60119036bb4ee3a59688110103ed562d25f0 [file] [log] [blame]
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +05301/*
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
17package org.onosproject.yangutils.datamodel;
18
19import java.util.LinkedList;
20import java.util.List;
21import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
23import org.onosproject.yangutils.utils.YangConstructType;
24
25import 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 */
69public 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}