blob: 6b6be585d5f803db2acd974fec33c7f0095e5f47 [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;
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053021import org.onosproject.yangutils.datamodel.YangNode;
22import org.onosproject.yangutils.datamodel.YangType;
23import org.onosproject.yangutils.datamodel.YangUses;
24import org.onosproject.yangutils.linker.exceptions.LinkerException;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053025
26/**
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053027 * Represents implementation of information about entity being resolved.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053028 *
29 * @param <T> type of entity being resolved, uses / grouping
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053030 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053031public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable {
32
33 private static final long serialVersionUID = 806201659L;
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053034
35 // Parsable node for which resolution is to be performed.
36 private T entityToResolve;
37
38 // Holder of the YANG construct for which resolution has to be carried out.
39 private YangNode holderOfEntityToResolve;
40
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053041 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053042 public T getEntityToResolve() {
43 return entityToResolve;
44 }
45
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053046 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053047 public void setEntityToResolve(T entityToResolve) {
48 this.entityToResolve = entityToResolve;
49 }
50
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053051 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053052 public YangNode getHolderOfEntityToResolve() {
53 return holderOfEntityToResolve;
54 }
55
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053056 @Override
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053057 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
58 this.holderOfEntityToResolve = holderOfEntityToResolve;
59 }
60
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053061 /**
62 * Retrieves the prefix of the entity.
63 *
64 * @return entities prefix
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053065 * @throws LinkerException linker error
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053066 */
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053067 public String getEntityPrefix()
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053068 throws LinkerException {
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053069 if (getEntityToResolve() == null) {
70 return null;
71 }
72
73 String prefix;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053074 T entityToBeResolved = getEntityToResolve();
75 if (entityToBeResolved instanceof YangType) {
76 prefix = ((YangType<?>) entityToBeResolved).getPrefix();
77 } else if (entityToBeResolved instanceof YangUses) {
78 prefix = ((YangUses) entityToBeResolved).getPrefix();
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053079 } else {
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +053080 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053081 }
82 return prefix;
83 }
84}