blob: 229625ce8707acffdd26bac78abfd967d60bd37e [file] [log] [blame]
Vinod Kumar Sd4deb062016-04-15 18:08:57 +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;
19
20/**
21 * Represents information about entity being resolved.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053022 *
23 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053024 */
25public class YangEntityToResolveInfo<T> {
26
27 // Parsable node for which resolution is to be performed.
28 private T entityToResolve;
29
30 // Holder of the YANG construct for which resolution has to be carried out.
31 private YangNode holderOfEntityToResolve;
32
33 /**
34 * Retrieves the entity to be resolved.
35 *
36 * @return entity to be resolved
37 */
38 public T getEntityToResolve() {
39 return entityToResolve;
40 }
41
42 /**
43 * Sets entity to be resolved.
44 *
45 * @param entityToResolve entity to be resolved
46 */
47 public void setEntityToResolve(T entityToResolve) {
48 this.entityToResolve = entityToResolve;
49 }
50
51 /**
52 * Retrieves the parent node which contains the entity to be resolved.
53 *
54 * @return parent node which contains the entity to be resolved
55 */
56 public YangNode getHolderOfEntityToResolve() {
57 return holderOfEntityToResolve;
58 }
59
60 /**
61 * Sets parent node which contains the entity to be resolved.
62 *
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053063 * @param holderOfEntityToResolve parent node which contains the entity to
64 * be resolved
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053065 */
66 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
67 this.holderOfEntityToResolve = holderOfEntityToResolve;
68 }
69
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053070 /**
71 * Retrieves the prefix of the entity.
72 *
73 * @return entities prefix
74 * @throws DataModelException data model error
75 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053076 public String getEntityPrefix()
77 throws DataModelException {
78 if (getEntityToResolve() == null) {
79 return null;
80 }
81
82 String prefix;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053083 T entityToBeResolved = getEntityToResolve();
84 if (entityToBeResolved instanceof YangType) {
85 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
86 } else if (entityToBeResolved instanceof YangUses) {
87 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053088 } else {
89 throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
90 }
91 return prefix;
92 }
93}