blob: d03fcf412c55c643677e71aa72d78275a9ef97da [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
83 public void resolve() throws DataModelException {
84
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);
95 return;
96 }
97 identity = identity.getBaseNode().getReferredIdentity();
98 }
99 }
100
101 /**
102 * Returns the YANG base node identifier.
103 *
104 * @return the YANG base node identifier
105 */
106 public YangNodeIdentifier getBaseIdentity() {
107 return baseIdentity;
108 }
109
110 /**
111 * Sets the YANG node identifier.
112 *
113 * @param baseIdentity the YANG node identifier to set
114 */
115 public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
116 this.baseIdentity = baseIdentity;
117 }
118
119 /**
120 * Returns the name of identity.
121 *
122 * @return the identity name
123 */
124 @Override
125 public String getName() {
126 return baseIdentity.getName();
127 }
128
129 /**
130 * Sets the name of identity.
131 *
132 * @param name the identity name to set
133 */
134 @Override
135 public void setName(String name) {
136 baseIdentity.setName(name);
137 }
138
139 /**
140 * Sets node identifier.
141 *
142 * @param nodeIdentifier the node identifier
143 */
144 public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
145 this.baseIdentity = nodeIdentifier;
146 }
147
148 /**
149 * Returns prefix associated with base.
150 *
151 * @return prefix associated with base
152 */
153 public String getPrefix() {
154 return baseIdentity.getPrefix();
155 }
156
157 /**
158 * Sets prefix associated with base.
159 *
160 * @param prefix prefix associated with base
161 */
162 public void setPrefix(String prefix) {
163 baseIdentity.setPrefix(prefix);
164 }
165
166 @Override
167 public YangConstructType getYangConstructType() {
168 return YangConstructType.IDENTITYREF_DATA;
169 }
170
171 @Override
172 public void validateDataOnEntry() throws DataModelException {
173 }
174
175 @Override
176 public void validateDataOnExit() throws DataModelException {
177 }
178
179 /**
180 * Returns the parent identity node.
181 *
182 * @return the parent identity node
183 */
184 public YangIdentity getReferredIdentity() {
185 return referredIdentity;
186 }
187
188 /**
189 * Sets the parent identity node.
190 *
191 * @param referredIdentity the parent identity node to set
192 */
193 public void setReferredIdentity(YangIdentity referredIdentity) {
194 this.referredIdentity = referredIdentity;
195 }
196}