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