blob: 1ef25e3d5cf3d420f4901a63c779c79aef6c4e81 [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +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.ParsableDataType;
20
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053021import static org.onosproject.yangutils.parser.ParsableDataType.getParsableDataType;
22import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage;
23import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType;
24
Gaurav Agrawala04483c2016-02-13 14:23:40 +053025/**
26 * It's a utility to help construct detailed error message.
27 */
28public final class ListenerErrorMessageConstruction {
29
30 /**
31 * Private constructor.
32 */
33 private ListenerErrorMessageConstruction() {
34 }
35
36 /**
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053037 * Constructs message for error with extended information and returns the
38 * same.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053039 *
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053040 * @param errorType error type needs to be set in error message.
41 * @param parsableDataType type of parsable data in which error occurred.
42 * @param parsableDataTypeName identifier/string of parsable data type in
43 * which error occurred.
44 * @param errorLocation location where error occurred.
45 * @param extendedErrorInformation extended error information.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053046 * @return constructed error message.
47 */
48 public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType,
49 ParsableDataType parsableDataType,
50 String parsableDataTypeName,
51 ListenerErrorLocation errorLocation,
52 String extendedErrorInformation) {
53 String newErrorMessage;
54 newErrorMessage = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053055 errorLocation)
56 + "\n"
57 + "Error Information: "
58 + extendedErrorInformation;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053059 return newErrorMessage;
60 }
61
62 /**
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053063 * Constructs message for error during listener based tree walk and returns
64 * the same.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053065 *
66 * @param errorType error type needs to be set in error message.
67 * @param parsableDataType type of parsable data in which error occurred.
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053068 * @param parsableDataTypeName identifier/string of parsable data type in
69 * which error occurred.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053070 * @param errorLocation location where error occurred.
71 * @return constructed error message.
72 */
73 public static String constructListenerErrorMessage(ListenerErrorType errorType,
74 ParsableDataType parsableDataType,
75 String parsableDataTypeName,
76 ListenerErrorLocation errorLocation) {
77
78 String errorMessage;
79
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053080 errorMessage = "Internal parser error detected: " + getErrorType(errorType) + " "
81 + getParsableDataType(parsableDataType);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053082
83 if (!parsableDataTypeName.isEmpty()) {
84 errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" ";
85 } else {
86 errorMessage = errorMessage + " ";
87
88 }
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053089 errorMessage = errorMessage + getErrorLocationMessage(errorLocation) + " processing.";
Gaurav Agrawala04483c2016-02-13 14:23:40 +053090 return errorMessage;
91 }
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053092}