Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.utils.YangConstructType; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 20 | |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 21 | import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType; |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 22 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage; |
| 23 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType; |
| 24 | |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 25 | /** |
| 26 | * It's a utility to help construct detailed error message. |
| 27 | */ |
| 28 | public final class ListenerErrorMessageConstruction { |
| 29 | |
| 30 | /** |
| 31 | * Private constructor. |
| 32 | */ |
| 33 | private ListenerErrorMessageConstruction() { |
| 34 | } |
| 35 | |
| 36 | /** |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 37 | * Constructs message for error with extended information and returns the |
| 38 | * same. |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 39 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 40 | * @param errorType error type needs to be set in error message |
| 41 | * @param yangConstructType type of parsable data in which error occurred |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 42 | * @param parsableDataTypeName identifier/string of parsable data type in |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 43 | * which error occurred |
| 44 | * @param errorLocation location where error occurred |
| 45 | * @param extendedErrorInformation extended error information |
| 46 | * @return constructed error message |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 47 | */ |
| 48 | public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType, |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 49 | YangConstructType yangConstructType, |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 50 | String parsableDataTypeName, |
| 51 | ListenerErrorLocation errorLocation, |
| 52 | String extendedErrorInformation) { |
| 53 | String newErrorMessage; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 54 | newErrorMessage = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName, |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 55 | errorLocation) |
| 56 | + "\n" |
| 57 | + "Error Information: " |
| 58 | + extendedErrorInformation; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 59 | return newErrorMessage; |
| 60 | } |
| 61 | |
| 62 | /** |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 63 | * Constructs message for error during listener based tree walk and returns |
| 64 | * the same. |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 65 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 66 | * @param errorType error type needs to be set in error message |
| 67 | * @param yangConstructType type of parsable data in which error occurred |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 68 | * @param parsableDataTypeName identifier/string of parsable data type in |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 69 | * which error occurred |
| 70 | * @param errorLocation location where error occurred |
| 71 | * @return constructed error message |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 72 | */ |
| 73 | public static String constructListenerErrorMessage(ListenerErrorType errorType, |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 74 | YangConstructType yangConstructType, |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 75 | String parsableDataTypeName, |
| 76 | ListenerErrorLocation errorLocation) { |
| 77 | |
| 78 | String errorMessage; |
| 79 | |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 80 | errorMessage = "Internal parser error detected: " + getErrorType(errorType) + " " |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 81 | + getYangConstructType(yangConstructType); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 82 | |
| 83 | if (!parsableDataTypeName.isEmpty()) { |
| 84 | errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" "; |
| 85 | } else { |
| 86 | errorMessage = errorMessage + " "; |
| 87 | |
| 88 | } |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 89 | errorMessage = errorMessage + getErrorLocationMessage(errorLocation) + " processing."; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 90 | return errorMessage; |
| 91 | } |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 92 | } |