com.github.fge.jsonschema.main.JsonSchemaException Maven / Gradle / Ivy
/*
* Copyright (c) 2012, Francis Galiegue
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.github.fge.jsonschema.main;
import com.github.fge.jsonschema.report.Message;
/**
* Generic exception thrown when the validation cannot proceed normally
*
* Note that all constructors of this class take a {@link Message} as an
* argument.
*/
public final class JsonSchemaException
extends Exception
{
private final Message message;
private JsonSchemaException(final Message message, final Throwable e)
{
super(message.getMessage(), e);
this.message = message;
}
public static JsonSchemaException wrap(final Message message,
final Throwable e)
{
if (!(e instanceof JsonSchemaException))
return new JsonSchemaException(message, e);
final JsonSchemaException wrapped = (JsonSchemaException) e;
final Throwable cause = wrapped.getCause();
return cause == null
? wrapped
: new JsonSchemaException(wrapped.message, cause);
}
public JsonSchemaException(final Message message)
{
this.message = message;
}
public Message getValidationMessage()
{
return message;
}
@Override
public String getMessage()
{
return message.toString();
}
@Override
public String getLocalizedMessage()
{
return message.toString();
}
@Override
public String toString()
{
return getClass().getName() + ": " + message;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy