mobile/android/thirdparty/org/json/simple/parser/ParseException.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/org/json/simple/parser/ParseException.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +package org.json.simple.parser;
     1.5 +
     1.6 +/**
     1.7 + * ParseException explains why and where the error occurs in source JSON text.
     1.8 + * 
     1.9 + * @author FangYidong<fangyidong@yahoo.com.cn>
    1.10 + *
    1.11 + */
    1.12 +public class ParseException extends Exception {
    1.13 +	private static final long serialVersionUID = -7880698968187728548L;
    1.14 +	
    1.15 +	public static final int ERROR_UNEXPECTED_CHAR = 0;
    1.16 +	public static final int ERROR_UNEXPECTED_TOKEN = 1;
    1.17 +	public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
    1.18 +
    1.19 +	private int errorType;
    1.20 +	private Object unexpectedObject;
    1.21 +	private int position;
    1.22 +	
    1.23 +	public ParseException(int errorType){
    1.24 +		this(-1, errorType, null);
    1.25 +	}
    1.26 +	
    1.27 +	public ParseException(int errorType, Object unexpectedObject){
    1.28 +		this(-1, errorType, unexpectedObject);
    1.29 +	}
    1.30 +	
    1.31 +	public ParseException(int position, int errorType, Object unexpectedObject){
    1.32 +		this.position = position;
    1.33 +		this.errorType = errorType;
    1.34 +		this.unexpectedObject = unexpectedObject;
    1.35 +	}
    1.36 +	
    1.37 +	public int getErrorType() {
    1.38 +		return errorType;
    1.39 +	}
    1.40 +	
    1.41 +	public void setErrorType(int errorType) {
    1.42 +		this.errorType = errorType;
    1.43 +	}
    1.44 +	
    1.45 +	/**
    1.46 +	 * @see org.json.simple.parser.JSONParser#getPosition()
    1.47 +	 * 
    1.48 +	 * @return The character position (starting with 0) of the input where the error occurs.
    1.49 +	 */
    1.50 +	public int getPosition() {
    1.51 +		return position;
    1.52 +	}
    1.53 +	
    1.54 +	public void setPosition(int position) {
    1.55 +		this.position = position;
    1.56 +	}
    1.57 +	
    1.58 +	/**
    1.59 +	 * @see org.json.simple.parser.Yytoken
    1.60 +	 * 
    1.61 +	 * @return One of the following base on the value of errorType:
    1.62 +	 * 		   	ERROR_UNEXPECTED_CHAR		java.lang.Character
    1.63 +	 * 			ERROR_UNEXPECTED_TOKEN		org.json.simple.parser.Yytoken
    1.64 +	 * 			ERROR_UNEXPECTED_EXCEPTION	java.lang.Exception
    1.65 +	 */
    1.66 +	public Object getUnexpectedObject() {
    1.67 +		return unexpectedObject;
    1.68 +	}
    1.69 +	
    1.70 +	public void setUnexpectedObject(Object unexpectedObject) {
    1.71 +		this.unexpectedObject = unexpectedObject;
    1.72 +	}
    1.73 +	
    1.74 +	public String toString(){
    1.75 +		StringBuffer sb = new StringBuffer();
    1.76 +		
    1.77 +		switch(errorType){
    1.78 +		case ERROR_UNEXPECTED_CHAR:
    1.79 +			sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position).append(".");
    1.80 +			break;
    1.81 +		case ERROR_UNEXPECTED_TOKEN:
    1.82 +			sb.append("Unexpected token ").append(unexpectedObject).append(" at position ").append(position).append(".");
    1.83 +			break;
    1.84 +		case ERROR_UNEXPECTED_EXCEPTION:
    1.85 +			sb.append("Unexpected exception at position ").append(position).append(": ").append(unexpectedObject);
    1.86 +			break;
    1.87 +		default:
    1.88 +			sb.append("Unkown error at position ").append(position).append(".");
    1.89 +			break;
    1.90 +		}
    1.91 +		return sb.toString();
    1.92 +	}
    1.93 +}

mercurial