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