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

com.peterphi.std.util.jaxb.exception.JAXBRuntimeException Maven / Gradle / Ivy

There is a newer version: 10.1.5
Show newest version
package com.peterphi.std.util.jaxb.exception;

import javax.xml.bind.JAXBException;

/**
 * A RuntimeException version of a JAXBException
 */
public class JAXBRuntimeException extends RuntimeException
{
	private static final long serialVersionUID = 1L;

	private JAXBException source;


	public JAXBRuntimeException(final String operation, JAXBException e)
	{
		this(computeMessage(operation, e), e.getCause() != null ? e.getCause() : e);

		this.source = source;
	}


	private static String computeMessage(final String operation, final JAXBException e)
	{
		final String message;

		if (e.getMessage() != null)
			message = e.getMessage();
		else if (e.getErrorCode() != null)
			message = e.getErrorCode();
		else if (e.getCause() != null && e.getCause().getMessage() != null)
			message = e.getCause().getMessage();
		else if (e.getLinkedException() != null && e.getLinkedException().getMessage() != null)
			message = e.getLinkedException().getMessage();
		else
			message = null;

		if (message != null)
			return operation + " failed: " + message;
		else
			return operation + " failed";
	}


	public JAXBRuntimeException(String msg, Throwable t)
	{
		super(msg, t);
	}


	public JAXBRuntimeException(Throwable t)
	{
		super(t);
	}


	public JAXBRuntimeException(String msg)
	{
		super(msg);
	}


	public JAXBException getSource()
	{
		return this.source;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy