blob: b8f63ebe070f5aee63efe8c62b1c22ff7326d92a [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 Agrawal58b348e2016-06-07 14:00:26 +053018import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053019import org.onosproject.yangutils.datamodel.YangNode;
20import org.onosproject.yangutils.datamodel.YangType;
21import org.onosproject.yangutils.datamodel.YangUses;
22import org.onosproject.yangutils.linker.exceptions.LinkerException;
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053023
24/**
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053025 * Represents implementation of information about entity being resolved.
Vinod Kumar S79a374b2016-04-30 21:09:15 +053026 *
27 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053028 */
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053029public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T> {
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053030
31 // Parsable node for which resolution is to be performed.
32 private T entityToResolve;
33
34 // Holder of the YANG construct for which resolution has to be carried out.
35 private YangNode holderOfEntityToResolve;
36
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053037 @Override
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053038 public T getEntityToResolve() {
39 return entityToResolve;
40 }
41
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053042 @Override
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053043 public void setEntityToResolve(T entityToResolve) {
44 this.entityToResolve = entityToResolve;
45 }
46
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053047 @Override
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053048 public YangNode getHolderOfEntityToResolve() {
49 return holderOfEntityToResolve;
50 }
51
Gaurav Agrawal58b348e2016-06-07 14:00:26 +053052 @Override
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053053 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
54 this.holderOfEntityToResolve = holderOfEntityToResolve;
55 }
56
Vinod Kumar S79a374b2016-04-30 21:09:15 +053057 /**
58 * Retrieves the prefix of the entity.
59 *
60 * @return entities prefix
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053061 * @throws LinkerException linker error
Vinod Kumar S79a374b2016-04-30 21:09:15 +053062 */
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053063 public String getEntityPrefix()
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053064 throws LinkerException {
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053065 if (getEntityToResolve() == null) {
66 return null;
67 }
68
69 String prefix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053070 T entityToBeResolved = getEntityToResolve();
71 if (entityToBeResolved instanceof YangType) {
72 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
73 } else if (entityToBeResolved instanceof YangUses) {
74 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053075 } else {
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053076 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
Vinod Kumar Sf677daf2016-04-15 18:08:57 +053077 }
78 return prefix;
79 }
80}