All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ait.tooling.json.parser.JSONParserException Maven / Gradle / Ivy

Go to download

Ahome Tooling JSON - Java JSON Parser and Serializer, heavily mooded from JSON Simple.

There is a newer version: 1.0.45-RELEASE
Show newest version
/*
 * Copyright (c) 2014,2015 Ahome' Innovation Technologies. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ait.tooling.json.parser;

public class JSONParserException extends Exception
{
    private static final long serialVersionUID           = -1386449426626594502L;

    public static final int   ERROR_UNEXPECTED_CHAR      = 0;

    public static final int   ERROR_UNEXPECTED_TOKEN     = 1;

    public static final int   ERROR_UNEXPECTED_EXCEPTION = 2;

    private int               m_errorType;

    private Object            m_unexpectedObject;

    private int               m_position;

    public JSONParserException(final int errorType)
    {
        this(-1, errorType, null);
    }

    public JSONParserException(final int errorType, final Object unexpectedObject)
    {
        this(-1, errorType, unexpectedObject);
    }

    public JSONParserException(final int position, final int errorType, final Object unexpectedObject)
    {
        m_position = position;

        m_errorType = errorType;

        m_unexpectedObject = unexpectedObject;
    }

    public int getErrorType()
    {
        return m_errorType;
    }

    public void setErrorType(final int errorType)
    {
        m_errorType = errorType;
    }

    public int getPosition()
    {
        return m_position;
    }

    public void setPosition(final int position)
    {
        m_position = position;
    }

    public Object getUnexpectedObject()
    {
        return m_unexpectedObject;
    }

    public void setUnexpectedObject(final Object unexpectedObject)
    {
        m_unexpectedObject = unexpectedObject;
    }

    public String toString()
    {
        final StringBuilder sb = new StringBuilder();

        switch (m_errorType)
        {
            case ERROR_UNEXPECTED_CHAR:
                sb.append("Unexpected character (").append(m_unexpectedObject).append(") at position ").append(m_position).append(".");
                break;
            case ERROR_UNEXPECTED_TOKEN:
                sb.append("Unexpected token ").append(m_unexpectedObject).append(" at position ").append(m_position).append(".");
                break;
            case ERROR_UNEXPECTED_EXCEPTION:
                sb.append("Unexpected exception at position ").append(m_position).append(": ").append(m_unexpectedObject);
                break;
            default:
                sb.append("Unkown error at position ").append(m_position).append(".");
                break;
        }
        return sb.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy