blob: 17285f6d7cb9c3622c40104ec41d6b4b292bc863 [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 */
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053016package org.onosproject.yangutils.linker.impl;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053017
Bharat saraswal96dfef02016-06-16 00:29:12 +053018import java.io.Serializable;
19
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053020import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053021import org.onosproject.yangutils.datamodel.YangIfFeature;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053022import org.onosproject.yangutils.datamodel.YangNode;
23import org.onosproject.yangutils.datamodel.YangType;
24import org.onosproject.yangutils.datamodel.YangUses;
25import org.onosproject.yangutils.linker.exceptions.LinkerException;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053026
27/**
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053028 * Represents implementation of information about entity being resolved.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053029 *
30 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053031 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053032public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable {
33
34 private static final long serialVersionUID = 806201659L;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053035
36 // Parsable node for which resolution is to be performed.
37 private T entityToResolve;
38
39 // Holder of the YANG construct for which resolution has to be carried out.
40 private YangNode holderOfEntityToResolve;
41
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053042 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053043 public T getEntityToResolve() {
44 return entityToResolve;
45 }
46
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053047 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053048 public void setEntityToResolve(T entityToResolve) {
49 this.entityToResolve = entityToResolve;
50 }
51
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053052 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053053 public YangNode getHolderOfEntityToResolve() {
54 return holderOfEntityToResolve;
55 }
56
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053057 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053058 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
59 this.holderOfEntityToResolve = holderOfEntityToResolve;
60 }
61
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053062 /**
63 * Retrieves the prefix of the entity.
64 *
65 * @return entities prefix
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053066 * @throws LinkerException linker error
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053067 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053068 public String getEntityPrefix()
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053069 throws LinkerException {
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053070 if (getEntityToResolve() == null) {
71 return null;
72 }
73
74 String prefix;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053075 T entityToBeResolved = getEntityToResolve();
76 if (entityToBeResolved instanceof YangType) {
77 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
78 } else if (entityToBeResolved instanceof YangUses) {
79 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053080 } else if (entityToBeResolved instanceof YangIfFeature) {
81 prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053082 } else {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053083 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053084 }
85 return prefix;
86 }
87}