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