blob: 62f6c9ee2d2d36107c89ba0d3c94f28d84e75254 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-02-16 01:37:16 +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 */
16package org.onosproject.yangutils.datamodel;
17
Bharat saraswal96dfef02016-06-16 00:29:12 +053018import java.io.Serializable;
19
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053020import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053021import org.onosproject.yangutils.datamodel.utils.Parsable;
22import org.onosproject.yangutils.datamodel.utils.YangConstructType;
rama-huawei6c728a92016-07-11 14:48:12 +053023import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
24import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.MUST_VIOLATION_ERROR_APP_TAG;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
26/*-
27 * The "must" statement, which is optional, takes as an argument a string that
28 * contains an XPath expression. It is used to formally declare a constraint
29 * on valid data.
30 *
31 * When a datastore is validated, all "must" constraints are conceptually
32 * evaluated once for each data node in the data tree, and for all leafs with
33 * default values in use. If a data node does not exist in the data tree, and
34 * it does not have a default value, its "must" statements are not evaluated.
35 *
36 * All such constraints MUST evaluate to true for the data to be valid.
37 *
38 * The must's sub-statements
39 *
40 * +---------------+---------+-------------+------------------+
41 * | substatement | section | cardinality |data model mapping|
42 * +---------------+---------+-------------+------------------+
43 * | description | 7.19.3 | 0..1 | -string |
44 * | error-app-tag | 7.5.4.2 | 0..1 | -not supported |
45 * | error-message | 7.5.4.1 | 0..1 | -not supported |
46 * | reference | 7.19.4 | 0..1 | -string |
47 * +---------------+---------+-------------+------------------+
48 */
49
50/**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 * Represents information defined in YANG must.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053052 */
rama-huawei6c728a92016-07-11 14:48:12 +053053public class YangMust implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
Bharat saraswal96dfef02016-06-16 00:29:12 +053054
55 private static final long serialVersionUID = 806201646L;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053056
57 /**
58 * Constraint info.
59 */
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053060 private String constraint;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053061
62 /**
63 * Description string.
64 */
65 private String description;
66
67 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053068 * Reference string.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053069 */
70 private String reference;
71
72 /**
rama-huawei6c728a92016-07-11 14:48:12 +053073 * YANG application error information.
74 */
75 private YangAppErrorInfo yangAppErrorInfo;
76
77 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053078 * Creates a YANG must restriction.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053079 */
80 public YangMust() {
rama-huawei6c728a92016-07-11 14:48:12 +053081 yangAppErrorInfo = new YangAppErrorInfo();
82 yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
83 yangAppErrorInfo.setErrorAppTag(MUST_VIOLATION_ERROR_APP_TAG);
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053084 }
85
86 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053087 * Returns the constraint.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053088 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053089 * @return the constraint
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053090 */
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053091 public String getConstraint() {
92 return constraint;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053093 }
94
95 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053096 * Sets the constraint.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053097 *
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053098 * @param constraint the constraint to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053099 */
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530100 public void setConstraint(String constraint) {
101 this.constraint = constraint;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530102 }
103
104 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530105 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530106 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530107 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530108 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530109 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530110 public String getDescription() {
111 return description;
112 }
113
114 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530115 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530116 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530117 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530118 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530119 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 public void setDescription(String description) {
121 this.description = description;
122 }
123
124 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530125 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530127 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530129 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 public String getReference() {
131 return reference;
132 }
133
134 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530135 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530136 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530137 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530138 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530139 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530140 public void setReference(String reference) {
141 this.reference = reference;
142 }
143
144 /**
145 * Returns the type of the parsed data.
146 *
147 * @return returns MUST_DATA
148 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530149 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530150 public YangConstructType getYangConstructType() {
151 return YangConstructType.MUST_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152 }
153
154 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530155 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530156 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530157 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530158 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530159 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 public void validateDataOnEntry() throws DataModelException {
161 // TODO auto-generated method stub, to be implemented by parser
162 }
163
164 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530165 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530166 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530167 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530168 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530169 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530170 public void validateDataOnExit() throws DataModelException {
171 // TODO auto-generated method stub, to be implemented by parser
172 }
rama-huawei6c728a92016-07-11 14:48:12 +0530173
174 @Override
175 public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
176 this.yangAppErrorInfo = yangAppErrorInfo;
177 }
178
179 @Override
180 public YangAppErrorInfo getAppErrorInfo() {
181 return yangAppErrorInfo;
182 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530183}