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