org.commonjava.web.config.ConfigurationException Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2011 John Casey
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see
* .
******************************************************************************/
package org.commonjava.web.config;
import java.text.MessageFormat;
public class ConfigurationException
extends Exception
{
private static final long serialVersionUID = 1L;
private final Object[] params;
private String formattedMessage;
public ConfigurationException( final String message, final Throwable cause, final Object... params )
{
super( message, cause );
this.params = params;
}
public ConfigurationException( final String message, final Object... params )
{
super( message );
this.params = params;
}
@Override
public synchronized String getMessage()
{
if ( formattedMessage == null )
{
final String format = super.getMessage();
if ( params == null || params.length < 1 )
{
formattedMessage = format;
}
else
{
final String original = formattedMessage;
try
{
formattedMessage = String.format( format, params );
}
catch ( final Error e )
{
}
catch ( final RuntimeException e )
{
}
catch ( final Exception e )
{
}
if ( formattedMessage == null || original == formattedMessage )
{
try
{
formattedMessage = MessageFormat.format( format, params );
}
catch ( final Error e )
{
formattedMessage = format;
throw e;
}
catch ( final RuntimeException e )
{
formattedMessage = format;
throw e;
}
catch ( final Exception e )
{
formattedMessage = format;
}
}
}
}
return formattedMessage;
}
}