blob: 4d7f2dfb74d3edb7fe4c3bbbfc9033ebe23db8e5 [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;
23import org.onosproject.yangutils.parser.Parsable;
24import org.onosproject.yangutils.utils.YangConstructType;
25
26import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
27
28/*
29 * Reference RFC 6020.
30 *
31 * The "input" statement, which is optional, is used to define input
32 * parameters to the RPC operation. It does not take an argument. The
33 * substatements to "input" define nodes under the RPC's input node.
34 *
35 * If a leaf in the input tree has a "mandatory" statement with the
36 * value "true", the leaf MUST be present in a NETCONF RPC invocation.
37 * Otherwise, the server MUST return a "missing-element" error.
38 *
39 * If a leaf in the input tree has a default value, the NETCONF server
40 * MUST use this value in the same cases as described in Section 7.6.1.
41 * In these cases, the server MUST operationally behave as if the leaf
42 * was present in the NETCONF RPC invocation with the default value as
43 * its value.
44 *
45 * If a "config" statement is present for any node in the input 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 input tree.
50 *
51 * The input 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 input.
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053070 */
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053071public class YangInput extends YangNode
72 implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
Gaurav Agrawale3ed0d92016-03-23 19:04:17 +053073
74 /**
75 * Name of the input.
76 */
77 private String name;
78
79 /**
80 * List of leaves contained.
81 */
82 private List<YangLeaf> listOfLeaf;
83
84 /**
85 * List of leaf-lists contained.
86 */
87 private List<YangLeafList> listOfLeafList;
88
89 /**
90 * Create a rpc input node.
91 */
92 public YangInput() {
93 super(YangNodeType.INPUT_NODE);
94 listOfLeaf = new LinkedList<YangLeaf>();
95 listOfLeafList = new LinkedList<YangLeafList>();
96 }
97
98 @Override
99 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
100 // Detect colliding child.
101 detectCollidingChildUtil(identifierName, dataType, this);
102 }
103
104 @Override
105 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
106 if (this.getName().equals(identifierName)) {
107 throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
108 + this.getName() + "\"");
109 }
110 }
111
112 @Override
113 public YangConstructType getYangConstructType() {
114 return YangConstructType.INPUT_DATA;
115 }
116
117 @Override
118 public void validateDataOnEntry() throws DataModelException {
119 //TODO: implement the method.
120 }
121
122 @Override
123 public void validateDataOnExit() throws DataModelException {
124 //TODO: implement the method.
125 }
126
127 @Override
128 public List<YangLeaf> getListOfLeaf() {
129 return listOfLeaf;
130 }
131
132 @Override
133 public void addLeaf(YangLeaf leaf) {
134 getListOfLeaf().add(leaf);
135 }
136
137 @Override
138 public List<YangLeafList> getListOfLeafList() {
139 return listOfLeafList;
140 }
141
142 @Override
143 public void addLeafList(YangLeafList leafList) {
144 getListOfLeafList().add(leafList);
145 }
146
147 @Override
148 public String getName() {
149 return name;
150 }
151
152 @Override
153 public void setName(String name) {
154 this.name = name;
155 }
156}