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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 package org.json.simple.parser;
     3 /**
     4  * ParseException explains why and where the error occurs in source JSON text.
     5  * 
     6  * @author FangYidong<fangyidong@yahoo.com.cn>
     7  *
     8  */
     9 public class ParseException extends Exception {
    10 	private static final long serialVersionUID = -7880698968187728548L;
    12 	public static final int ERROR_UNEXPECTED_CHAR = 0;
    13 	public static final int ERROR_UNEXPECTED_TOKEN = 1;
    14 	public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
    16 	private int errorType;
    17 	private Object unexpectedObject;
    18 	private int position;
    20 	public ParseException(int errorType){
    21 		this(-1, errorType, null);
    22 	}
    24 	public ParseException(int errorType, Object unexpectedObject){
    25 		this(-1, errorType, unexpectedObject);
    26 	}
    28 	public ParseException(int position, int errorType, Object unexpectedObject){
    29 		this.position = position;
    30 		this.errorType = errorType;
    31 		this.unexpectedObject = unexpectedObject;
    32 	}
    34 	public int getErrorType() {
    35 		return errorType;
    36 	}
    38 	public void setErrorType(int errorType) {
    39 		this.errorType = errorType;
    40 	}
    42 	/**
    43 	 * @see org.json.simple.parser.JSONParser#getPosition()
    44 	 * 
    45 	 * @return The character position (starting with 0) of the input where the error occurs.
    46 	 */
    47 	public int getPosition() {
    48 		return position;
    49 	}
    51 	public void setPosition(int position) {
    52 		this.position = position;
    53 	}
    55 	/**
    56 	 * @see org.json.simple.parser.Yytoken
    57 	 * 
    58 	 * @return One of the following base on the value of errorType:
    59 	 * 		   	ERROR_UNEXPECTED_CHAR		java.lang.Character
    60 	 * 			ERROR_UNEXPECTED_TOKEN		org.json.simple.parser.Yytoken
    61 	 * 			ERROR_UNEXPECTED_EXCEPTION	java.lang.Exception
    62 	 */
    63 	public Object getUnexpectedObject() {
    64 		return unexpectedObject;
    65 	}
    67 	public void setUnexpectedObject(Object unexpectedObject) {
    68 		this.unexpectedObject = unexpectedObject;
    69 	}
    71 	public String toString(){
    72 		StringBuffer sb = new StringBuffer();
    74 		switch(errorType){
    75 		case ERROR_UNEXPECTED_CHAR:
    76 			sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position).append(".");
    77 			break;
    78 		case ERROR_UNEXPECTED_TOKEN:
    79 			sb.append("Unexpected token ").append(unexpectedObject).append(" at position ").append(position).append(".");
    80 			break;
    81 		case ERROR_UNEXPECTED_EXCEPTION:
    82 			sb.append("Unexpected exception at position ").append(position).append(": ").append(unexpectedObject);
    83 			break;
    84 		default:
    85 			sb.append("Unkown error at position ").append(position).append(".");
    86 			break;
    87 		}
    88 		return sb.toString();
    89 	}
    90 }

mercurial