blob: 6ecded38134bf8a58ce604b0932f6f42d3ffd372 [file] [log] [blame]
Gaurav Agrawal88897632016-02-12 18:37:50 +05301/*
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
17package org.onosproject.yangutils.parser.impl.parserutils;
18
19import org.onosproject.yangutils.parser.impl.TreeWalkListener;
20
21/**
22 * Its a utility to carry out listener validation.
23 */
24public 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}