Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +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.ParsableDataType; |
| 20 | |
| 21 | /** |
| 22 | * It's a utility to help construct detailed error message. |
| 23 | */ |
| 24 | public final class ListenerErrorMessageConstruction { |
| 25 | |
| 26 | /** |
| 27 | * Private constructor. |
| 28 | */ |
| 29 | private ListenerErrorMessageConstruction() { |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Constructs message for error with extended information and returns the same. |
| 34 | * |
| 35 | * @param errorType error type needs to be set in error message. |
| 36 | * @param parsableDataType type of parsable data in which error occurred. |
| 37 | * @param parsableDataTypeName identifier/string of parsable data type in which error occurred. |
| 38 | * @param errorLocation location where error occurred. |
| 39 | * @param extendedErrorInformation extended error information. |
| 40 | * @return constructed error message. |
| 41 | */ |
| 42 | public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType, |
| 43 | ParsableDataType parsableDataType, |
| 44 | String parsableDataTypeName, |
| 45 | ListenerErrorLocation errorLocation, |
| 46 | String extendedErrorInformation) { |
| 47 | String newErrorMessage; |
| 48 | newErrorMessage = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName, |
| 49 | errorLocation) + "\n" + "Error Information: " + extendedErrorInformation; |
| 50 | return newErrorMessage; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Constructs message for error during listener based tree walk and returns the same. |
| 55 | * |
| 56 | * @param errorType error type needs to be set in error message. |
| 57 | * @param parsableDataType type of parsable data in which error occurred. |
| 58 | * @param parsableDataTypeName identifier/string of parsable data type in which error occurred. |
| 59 | * @param errorLocation location where error occurred. |
| 60 | * @return constructed error message. |
| 61 | */ |
| 62 | public static String constructListenerErrorMessage(ListenerErrorType errorType, |
| 63 | ParsableDataType parsableDataType, |
| 64 | String parsableDataTypeName, |
| 65 | ListenerErrorLocation errorLocation) { |
| 66 | |
| 67 | String errorMessage; |
| 68 | |
| 69 | errorMessage = "Internal parser error detected: " + ListenerErrorType.getErrorType(errorType) + " " |
| 70 | + ParsableDataType.getParsableDataType(parsableDataType); |
| 71 | |
| 72 | |
| 73 | if (!parsableDataTypeName.isEmpty()) { |
| 74 | errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" "; |
| 75 | } else { |
| 76 | errorMessage = errorMessage + " "; |
| 77 | |
| 78 | } |
| 79 | errorMessage = errorMessage + ListenerErrorLocation.getErrorLocationMessage(errorLocation) + " processing."; |
| 80 | return errorMessage; |
| 81 | } |
| 82 | } |