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