Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 1 | /* |
| 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 Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 16 | package org.onosproject.yangutils.linker.impl; |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 17 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 18 | import java.io.Serializable; |
| 19 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 20 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; |
Vidyashree Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.YangIfFeature; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.datamodel.YangType; |
| 24 | import org.onosproject.yangutils.datamodel.YangUses; |
| 25 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 26 | |
| 27 | /** |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 28 | * Represents implementation of information about entity being resolved. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 29 | * |
| 30 | * @param <T> type of entity being resolved, uses / grouping |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 31 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 32 | public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable { |
| 33 | |
| 34 | private static final long serialVersionUID = 806201659L; |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 35 | |
| 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 Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 42 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 43 | public T getEntityToResolve() { |
| 44 | return entityToResolve; |
| 45 | } |
| 46 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 47 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 48 | public void setEntityToResolve(T entityToResolve) { |
| 49 | this.entityToResolve = entityToResolve; |
| 50 | } |
| 51 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 52 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 53 | public YangNode getHolderOfEntityToResolve() { |
| 54 | return holderOfEntityToResolve; |
| 55 | } |
| 56 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 57 | @Override |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 58 | public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) { |
| 59 | this.holderOfEntityToResolve = holderOfEntityToResolve; |
| 60 | } |
| 61 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 62 | /** |
| 63 | * Retrieves the prefix of the entity. |
| 64 | * |
| 65 | * @return entities prefix |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 66 | * @throws LinkerException linker error |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 67 | */ |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 68 | public String getEntityPrefix() |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 69 | throws LinkerException { |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 70 | if (getEntityToResolve() == null) { |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | String prefix; |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 75 | 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 Rama | deac28b | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 80 | } else if (entityToBeResolved instanceof YangIfFeature) { |
| 81 | prefix = ((YangIfFeature) entityToBeResolved).getPrefix(); |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 82 | } else { |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 83 | throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses"); |
Vinod Kumar S | d4deb06 | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 84 | } |
| 85 | return prefix; |
| 86 | } |
| 87 | } |