This project has retired. For details please refer to its
Attic page.
JSONParseException xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.commons.impl.json.parser;
2021/**22 * ParseException explains why and where the error occurs in source JSON text.23 * 24 * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified25 * for OpenCMIS.)26 * 27 * @author FangYidong<fangyidong@yahoo.com.cn>28 */29publicclassJSONParseExceptionextends Exception {
30privatestaticfinallong serialVersionUID = -7880698968187728548L;
3132publicstaticfinalint ERROR_UNEXPECTED_CHAR = 0;
33publicstaticfinalint ERROR_UNEXPECTED_TOKEN = 1;
34publicstaticfinalint ERROR_UNEXPECTED_EXCEPTION = 2;
3536privateint errorType;
37private Object unexpectedObject;
38privateint position;
3940publicJSONParseException(int errorType) {
41this(-1, errorType, null);
42 }
4344publicJSONParseException(int errorType, Object unexpectedObject) {
45this(-1, errorType, unexpectedObject);
46 }
4748publicJSONParseException(int position, int errorType, Object unexpectedObject) {
49this.position = position;
50this.errorType = errorType;
51this.unexpectedObject = unexpectedObject;
52 }
5354publicint getErrorType() {
55return errorType;
56 }
5758publicvoid setErrorType(int errorType) {
59this.errorType = errorType;
60 }
6162/**63 * @see org.json.simple.parser.JSONParser#getPosition()64 * 65 * @return The character position (starting with 0) of the input where the66 * error occurs.67 */68publicint getPosition() {
69return position;
70 }
7172publicvoid setPosition(int position) {
73this.position = position;
74 }
7576/**77 * @see org.json.simple.parser.Yytoken78 * 79 * @return One of the following base on the value of errorType:80 * ERROR_UNEXPECTED_CHAR java.lang.Character ERROR_UNEXPECTED_TOKEN81 * org.json.simple.parser.Yytoken ERROR_UNEXPECTED_EXCEPTION82 * java.lang.Exception83 */84public Object getUnexpectedObject() {
85return unexpectedObject;
86 }
8788publicvoid setUnexpectedObject(Object unexpectedObject) {
89this.unexpectedObject = unexpectedObject;
90 }
9192public String toString() {
93 StringBuilder sb = new StringBuilder();
9495switch (errorType) {
96case ERROR_UNEXPECTED_CHAR:
97 sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position)
98 .append(".");
99break;
100case ERROR_UNEXPECTED_TOKEN:
101 sb.append("Unexpected token ").append(unexpectedObject).append(" at position ").append(position)
102 .append(".");
103break;
104case ERROR_UNEXPECTED_EXCEPTION:
105 sb.append("Unexpected exception at position ").append(position).append(": ").append(unexpectedObject);
106break;
107default:
108 sb.append("Unkown error at position ").append(position).append(".");
109break;
110 }
111return sb.toString();
112 }
113 }