blob: f2396923d5e7b5e36362548c20dcf76f38261fc7 [file] [log] [blame]
Vinod Kumar Sf677daf2016-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 */
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053016package org.onosproject.yangutils.linker.impl;
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053017
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053018import org.onosproject.yangutils.datamodel.YangNode;
19import org.onosproject.yangutils.datamodel.YangType;
20import org.onosproject.yangutils.datamodel.YangUses;
21import org.onosproject.yangutils.linker.exceptions.LinkerException;
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053022
23/**
24 * Represents information about entity being resolved.
Vinod Kumar S79a374b2016-04-30 21:09:15 +053025 *
26 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053027 */
28public class YangEntityToResolveInfo<T> {
29
30 // Parsable node for which resolution is to be performed.
31 private T entityToResolve;
32
33 // Holder of the YANG construct for which resolution has to be carried out.
34 private YangNode holderOfEntityToResolve;
35
36 /**
37 * Retrieves the entity to be resolved.
38 *
39 * @return entity to be resolved
40 */
41 public T getEntityToResolve() {
42 return entityToResolve;
43 }
44
45 /**
46 * Sets entity to be resolved.
47 *
48 * @param entityToResolve entity to be resolved
49 */
50 public void setEntityToResolve(T entityToResolve) {
51 this.entityToResolve = entityToResolve;
52 }
53
54 /**
55 * Retrieves the parent node which contains the entity to be resolved.
56 *
57 * @return parent node which contains the entity to be resolved
58 */
59 public YangNode getHolderOfEntityToResolve() {
60 return holderOfEntityToResolve;
61 }
62
63 /**
64 * Sets parent node which contains the entity to be resolved.
65 *
Vinod Kumar S79a374b2016-04-30 21:09:15 +053066 * @param holderOfEntityToResolve parent node which contains the entity to
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053067 * be resolved
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053068 */
69 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
70 this.holderOfEntityToResolve = holderOfEntityToResolve;
71 }
72
Vinod Kumar S79a374b2016-04-30 21:09:15 +053073 /**
74 * Retrieves the prefix of the entity.
75 *
76 * @return entities prefix
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053077 * @throws LinkerException linker error
Vinod Kumar S79a374b2016-04-30 21:09:15 +053078 */
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053079 public String getEntityPrefix()
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053080 throws LinkerException {
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053081 if (getEntityToResolve() == null) {
82 return null;
83 }
84
85 String prefix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053086 T entityToBeResolved = getEntityToResolve();
87 if (entityToBeResolved instanceof YangType) {
88 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
89 } else if (entityToBeResolved instanceof YangUses) {
90 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053091 } else {
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053092 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053093 }
94 return prefix;
95 }
96}