1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of GeneratedSaxParser.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __GENERATEDSAXPARSER_PARSERERROR_H__
12 #define __GENERATEDSAXPARSER_PARSERERROR_H__
13 
14 #include "GeneratedSaxParserPrerequisites.h"
15 #include "GeneratedSaxParserTypes.h"
16 
17 
18 
19 namespace GeneratedSaxParser
20 {
21 	class ParserError
22 	{
23 	public:
24 		enum Severity
25 		{
26 			SEVERITY_ERROR_NONCRITICAL,
27 			SEVERITY_CRITICAL,
28 		};
29 
30 		enum ErrorType
31 		{
32 			ERROR_COULD_NOT_OPEN_FILE,
33 			ERROR_XML_PARSER_ERROR,
34 			ERROR_UNKNOWN_ELEMENT,
35 			ERROR_TEXTDATA_PARSING_FAILED,
36 			ERROR_UNKNOWN_ATTRIBUTE,
37 			ERROR_ATTRIBUTE_PARSING_FAILED,
38             ERROR_REQUIRED_ATTRIBUTE_MISSING,
39 
40             ERROR_VALIDATION_MAX_OCCURS_EXCEEDED,
41             ERROR_VALIDATION_MIN_OCCURS_UNMATCHED,
42             ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT,
43             ERROR_VALIDATION_SEQUENCE_NEXT_SIBLING_ALREADY_PRESENT,
44             ERROR_VALIDATION_CHOICE_SIBLING_ALREADY_PRESENT,
45             ERROR_VALIDATION_CHOICE_NO_CHILD_PRESENT,
46             ERROR_VALIDATION_UNEXPECTED_ELEMENT,
47             ERROR_VALIDATION_UNEXPECTED_CLOSING_TAG,
48 
49             ERROR_VALIDATION_MIN_INCLUSIVE,
50             ERROR_VALIDATION_MAX_INCLUSIVE,
51             ERROR_VALIDATION_MIN_EXCLUSIVE,
52             ERROR_VALIDATION_MAX_EXCLUSIVE,
53             ERROR_VALIDATION_LENGTH,
54             ERROR_VALIDATION_MIN_LENGTH,
55             ERROR_VALIDATION_MAX_LENGTH,
56             ERROR_VALIDATION_PATTERN,
57 
58             SIMPLE_TYPE_VALIDATION_OK
59         };
60 	private:
61 		/** The Severity of the error*/
62 		Severity mSeverity;
63 
64 		/** The type of th error.*/
65 		ErrorType mErrorType;
66 
67 		/** The hash of the element, the error occurred in.*/
68 		const char* mElementName;
69 
70 		/** The hash of the attribute, that caused the error. Might be zero if no attribute
71 		was involved.*/
72 		const char* mAttributeName;
73 
74 		/** The line number the error occurred in. Might be zero if the location could not be
75 		determined.*/
76 		size_t mLineNumber;
77 
78 		/** The column number the error occurred in. Might be zero if the location could not be
79 		determined.*/
80 		size_t mColumnNumber;
81 
82 		/** Additional text information. Its meaning depends on the error type. Might be empty.*/
83 		String mAdditionalText;
84 
85 	public:
86 		ParserError(Severity severity,
87 					ErrorType errorType,
88 					const char* elementName,
89 					const char* attributeName,
90 					size_t lineNumber,
91 					size_t columnNumber,
92 					String additionalText = "");
93 		virtual ~ParserError();
94 
95 		/** Returns the severity of the error.*/
getSeverity()96 		Severity getSeverity() const { return mSeverity; }
97 
98 		/** Returns the error type.*/
getErrorType()99 		ErrorType getErrorType() const { return mErrorType; }
100 
101 		/** Returns the name of the element, the error occurred in.*/
getElement()102 		const char* getElement() const { return mElementName; }
103 
104 		/** Returns the name of the attribute, that caused the error. Might be zero if no attribute
105 		was involved.*/
getAttribute()106 		const char* getAttribute() const { return mAttributeName; }
107 
108 		/** Returns the line number the error occurred in. Might be zero if the location could not be
109 		determined.*/
getLineNumber()110 		size_t getLineNumber() const { return mLineNumber; }
111 
112 		/** Returns the column number the error occurred in. Might be zero if the location could not be
113 		determined.*/
getColumnNumber()114 		size_t getColumnNumber() const { return mColumnNumber; }
115 
116 		/** Returns the Additional text information. Its meaning depends on the error type. Might be empty.*/
getAdditionalText()117 		const String& getAdditionalText() const { return mAdditionalText; }
118 
119 		/** Returns a human readable error message, describing the error.*/
120 		String getErrorMessage() const;
121 
122 
123 	public:
124 
125 
126 	private:
127 		ParserError();
128         /** Disable default copy ctor. */
129 		ParserError( const ParserError& pre );
130         /** Disable default assignment operator. */
131 		const ParserError& operator= ( const ParserError& pre );
132 
133 	};
134 } // namespace GeneratedSaxParser
135 
136 #endif // __GENERATEDSAXPARSER_PARSERERROR_H__
137