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 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 18 | import org.onosproject.yangutils.datamodel.YangNode; |
| 19 | import org.onosproject.yangutils.datamodel.YangType; |
| 20 | import org.onosproject.yangutils.datamodel.YangUses; |
| 21 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Represents information about entity being resolved. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 25 | * |
| 26 | * @param <T> type of entity being resolved, uses / grouping |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 27 | */ |
| 28 | public class YangEntityToResolveInfo<T> { |
| 29 | |
| 30 | // Parsable node for which resolution is to be performed. |
| 31 | private T entityToResolve; |
| 32 | |
| 33 | // Holder of the YANG construct for which resolution has to be carried out. |
| 34 | private YangNode holderOfEntityToResolve; |
| 35 | |
| 36 | /** |
| 37 | * Retrieves the entity to be resolved. |
| 38 | * |
| 39 | * @return entity to be resolved |
| 40 | */ |
| 41 | public T getEntityToResolve() { |
| 42 | return entityToResolve; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Sets entity to be resolved. |
| 47 | * |
| 48 | * @param entityToResolve entity to be resolved |
| 49 | */ |
| 50 | public void setEntityToResolve(T entityToResolve) { |
| 51 | this.entityToResolve = entityToResolve; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Retrieves the parent node which contains the entity to be resolved. |
| 56 | * |
| 57 | * @return parent node which contains the entity to be resolved |
| 58 | */ |
| 59 | public YangNode getHolderOfEntityToResolve() { |
| 60 | return holderOfEntityToResolve; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Sets parent node which contains the entity to be resolved. |
| 65 | * |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 66 | * @param holderOfEntityToResolve parent node which contains the entity to |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 67 | * be resolved |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 68 | */ |
| 69 | public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) { |
| 70 | this.holderOfEntityToResolve = holderOfEntityToResolve; |
| 71 | } |
| 72 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 73 | /** |
| 74 | * Retrieves the prefix of the entity. |
| 75 | * |
| 76 | * @return entities prefix |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 77 | * @throws LinkerException linker error |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 78 | */ |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 79 | public String getEntityPrefix() |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 80 | throws LinkerException { |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 81 | if (getEntityToResolve() == null) { |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | String prefix; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 86 | T entityToBeResolved = getEntityToResolve(); |
| 87 | if (entityToBeResolved instanceof YangType) { |
| 88 | prefix = ((YangType<?>) entityToBeResolved).getPrefix(); |
| 89 | } else if (entityToBeResolved instanceof YangUses) { |
| 90 | prefix = ((YangUses) entityToBeResolved).getPrefix(); |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 91 | } else { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame^] | 92 | 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] | 93 | } |
| 94 | return prefix; |
| 95 | } |
| 96 | } |