blob: 2019339cab60f68daf92ae03193b1222aec4c836 [file] [log] [blame]
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +05301/*
2 * Copyright 2016-present 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 */
16package org.onosproject.yangutils.datamodel;
17
18import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19import org.onosproject.yangutils.datamodel.utils.Parsable;
20import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
21import org.onosproject.yangutils.datamodel.utils.YangConstructType;
22
23import java.io.Serializable;
24
25/*-
26 * Reference RFC 6020.
27 *
28 * The identityref type is used to reference an existing identity.
29 *
30 * The identityref's base Statement :
31 * The "base" statement, which is a substatement to the "type"
32 * statement, MUST be present if the type is "identityref". The
33 * argument is the name of an identity, as defined by an "identity"
34 * statement. If a prefix is present on the identity name, it refers to
35 * an identity defined in the module that was imported with that prefix.
36 * Otherwise, an identity with the matching name MUST be defined in the
37 * current module or an included submodule.
38 * Valid values for an identityref are any identities derived from the
39 * identityref's base identity. On a particular server, the valid
40 * values are further restricted to the set of identities defined in the
41 * modules supported by the server.
42 */
43
44/**
45 * Represents data model node to maintain information defined in YANG identityref.
46 */
47public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
48
49 private static final long serialVersionUID = 806201692L;
50
51 // Get referred identity parent information.
52 private YangIdentity referredIdentity;
53
54 // YANG node identifier.
55 private YangNodeIdentifier baseIdentity;
56
57 /**
58 * Status of resolution. If completely resolved enum value is "RESOLVED",
59 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
60 * is added to uses/type/identityref/base but it's not resolved value of enum should be
61 * "INTRA_FILE_RESOLVED".
62 */
63 private ResolvableStatus resolvableStatus;
64
65 // Creates a specific identityref of node.
66 public YangIdentityRef() {
67 super(YangNodeType.IDENTITYREF_NODE);
68 baseIdentity = new YangNodeIdentifier();
69 resolvableStatus = ResolvableStatus.UNRESOLVED;
70 }
71
72 @Override
73 public ResolvableStatus getResolvableStatus() {
74 return resolvableStatus;
75 }
76
77 @Override
78 public void setResolvableStatus(ResolvableStatus resolvableStatus) {
79 this.resolvableStatus = resolvableStatus;
80 }
81
82 @Override
janani b23ccc312016-07-14 19:35:22 +053083 public Object resolve() throws DataModelException {
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053084
85 // Check if the derived info is present.
86 YangIdentity identity = getReferredIdentity();
87
88 if (identity == null) {
89 throw new DataModelException("Linker Error: Identity information is missing.");
90 }
91
92 while (identity.getBaseNode() != null) {
93 if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) {
94 setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
janani b23ccc312016-07-14 19:35:22 +053095 return null;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053096 }
97 identity = identity.getBaseNode().getReferredIdentity();
98 }
janani b23ccc312016-07-14 19:35:22 +053099 return null;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +0530100 }
101
102 /**
103 * Returns the YANG base node identifier.
104 *
105 * @return the YANG base node identifier
106 */
107 public YangNodeIdentifier getBaseIdentity() {
108 return baseIdentity;
109 }
110
111 /**
112 * Sets the YANG node identifier.
113 *
114 * @param baseIdentity the YANG node identifier to set
115 */
116 public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
117 this.baseIdentity = baseIdentity;
118 }
119
120 /**
121 * Returns the name of identity.
122 *
123 * @return the identity name
124 */
125 @Override
126 public String getName() {
127 return baseIdentity.getName();
128 }
129
130 /**
131 * Sets the name of identity.
132 *
133 * @param name the identity name to set
134 */
135 @Override
136 public void setName(String name) {
137 baseIdentity.setName(name);
138 }
139
140 /**
141 * Sets node identifier.
142 *
143 * @param nodeIdentifier the node identifier
144 */
145 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
146 this.baseIdentity = nodeIdentifier;
147 }
148
149 /**
150 * Returns prefix associated with base.
151 *
152 * @return prefix associated with base
153 */
154 public String getPrefix() {
155 return baseIdentity.getPrefix();
156 }
157
158 /**
159 * Sets prefix associated with base.
160 *
161 * @param prefix prefix associated with base
162 */
163 public void setPrefix(String prefix) {
164 baseIdentity.setPrefix(prefix);
165 }
166
167 @Override
168 public YangConstructType getYangConstructType() {
169 return YangConstructType.IDENTITYREF_DATA;
170 }
171
172 @Override
173 public void validateDataOnEntry() throws DataModelException {
174 }
175
176 @Override
177 public void validateDataOnExit() throws DataModelException {
178 }
179
180 /**
181 * Returns the parent identity node.
182 *
183 * @return the parent identity node
184 */
185 public YangIdentity getReferredIdentity() {
186 return referredIdentity;
187 }
188
189 /**
190 * Sets the parent identity node.
191 *
192 * @param referredIdentity the parent identity node to set
193 */
194 public void setReferredIdentity(YangIdentity referredIdentity) {
195 this.referredIdentity = referredIdentity;
196 }
197}