Gaurav Agrawal | 8889763 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.parserutils; |
| 18 | |
| 19 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 20 | |
| 21 | /** |
| 22 | * Its a utility to carry out listener validation. |
| 23 | */ |
| 24 | public final class ListenerValidation { |
| 25 | |
| 26 | /** |
| 27 | * Creates a new belongto listener. |
| 28 | */ |
| 29 | private ListenerValidation() { |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Checks if error is set or parsed data stack is empty. |
| 34 | * |
| 35 | * @param listener Listener's object. |
| 36 | * @param errNode parsable node for which validation needs to be done. |
| 37 | * @return validation result. |
| 38 | */ |
| 39 | public static boolean preValidation(TreeWalkListener listener, String errNode) { |
| 40 | |
| 41 | // Check whether error found while walking YANG file, if yes return true. |
| 42 | if (listener.getErrorInformation().isErrorFlag()) { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | // If stack is empty it indicates error condition |
| 47 | if (listener.getParsedDataStack().empty()) { |
| 48 | listener.getErrorInformation().setErrorFlag(true); |
| 49 | listener.getErrorInformation().setErrorMsg("Parsable stack empty at" + errNode + "entry"); |
| 50 | return true; |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | } |