blob: 141e3dcd65e5123015359f1cf4ca997244fa31ea [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawala04483c2016-02-13 14:23:40 +05303 *
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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053019import org.onosproject.yangutils.utils.YangConstructType;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053020
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053021import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage;
22import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType;
Bharat saraswald9822e92016-04-05 15:13:44 +053023import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType;
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053024
Gaurav Agrawala04483c2016-02-13 14:23:40 +053025/**
Bharat saraswald9822e92016-04-05 15:13:44 +053026 * Represents a utility to help construct detailed error message.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053027 */
28public final class ListenerErrorMessageConstruction {
29
30 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053031 * Creates a object of listen error message.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053032 */
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 Agrawal8e8770a2016-02-27 03:57:50 +053040 * @param errorType error type needs to be set in error message
41 * @param yangConstructType type of parsable data in which error occurred
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053042 * @param parsableDataTypeName identifier/string of parsable data type in
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053043 * which error occurred
44 * @param errorLocation location where error occurred
45 * @param extendedErrorInformation extended error information
46 * @return constructed error message
Gaurav Agrawala04483c2016-02-13 14:23:40 +053047 */
48 public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType,
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053049 YangConstructType yangConstructType,
Gaurav Agrawala04483c2016-02-13 14:23:40 +053050 String parsableDataTypeName,
51 ListenerErrorLocation errorLocation,
52 String extendedErrorInformation) {
53 String newErrorMessage;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053054 newErrorMessage = constructListenerErrorMessage(errorType, yangConstructType, 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 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053066 * @param errorType error type needs to be set in error message
67 * @param yangConstructType 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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053069 * which error occurred
70 * @param errorLocation location where error occurred
71 * @return constructed error message
Gaurav Agrawala04483c2016-02-13 14:23:40 +053072 */
73 public static String constructListenerErrorMessage(ListenerErrorType errorType,
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053074 YangConstructType yangConstructType,
Gaurav Agrawala04483c2016-02-13 14:23:40 +053075 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) + " "
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053081 + getYangConstructType(yangConstructType);
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}