blob: d33dfd7d288bb2da0cab42be9329743795c854dd [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;
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053022import org.onosproject.yangutils.datamodel.YangBase;
23import org.onosproject.yangutils.datamodel.YangIdentityRef;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053024import org.onosproject.yangutils.datamodel.YangNode;
25import org.onosproject.yangutils.datamodel.YangType;
26import org.onosproject.yangutils.datamodel.YangUses;
27import org.onosproject.yangutils.linker.exceptions.LinkerException;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053028
29/**
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053030 * Represents implementation of information about entity being resolved.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053031 *
32 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053033 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053034public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable {
35
36 private static final long serialVersionUID = 806201659L;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053037
38 // Parsable node for which resolution is to be performed.
39 private T entityToResolve;
40
41 // Holder of the YANG construct for which resolution has to be carried out.
42 private YangNode holderOfEntityToResolve;
43
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053044 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053045 public T getEntityToResolve() {
46 return entityToResolve;
47 }
48
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053049 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053050 public void setEntityToResolve(T entityToResolve) {
51 this.entityToResolve = entityToResolve;
52 }
53
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053054 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053055 public YangNode getHolderOfEntityToResolve() {
56 return holderOfEntityToResolve;
57 }
58
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053059 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053060 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
61 this.holderOfEntityToResolve = holderOfEntityToResolve;
62 }
63
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053064 /**
65 * Retrieves the prefix of the entity.
66 *
67 * @return entities prefix
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053068 * @throws LinkerException linker error
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053069 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053070 public String getEntityPrefix()
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053071 throws LinkerException {
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053072 if (getEntityToResolve() == null) {
73 return null;
74 }
75
76 String prefix;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053077 T entityToBeResolved = getEntityToResolve();
78 if (entityToBeResolved instanceof YangType) {
79 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
80 } else if (entityToBeResolved instanceof YangUses) {
81 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053082 } else if (entityToBeResolved instanceof YangIfFeature) {
83 prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
Shankara-Huaweidf7b9ca2016-07-14 11:35:34 +053084 } else if (entityToBeResolved instanceof YangBase) {
85 prefix = ((YangBase) entityToBeResolved).getBaseIdentifier().getPrefix();
86 } else if (entityToBeResolved instanceof YangIdentityRef) {
87 prefix = ((YangIdentityRef) entityToBeResolved).getBaseIdentity().getPrefix();
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053088 } else {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053089 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053090 }
91 return prefix;
92 }
93}