Changeset 402 for tapas/common


Ignore:
Timestamp:
03/08/12 17:20:11 (12 years ago)
Author:
vmipsl
Message:

clean
mise en place message d'erreurs javascript

Location:
tapas/common
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • tapas/common/interface/com/ether/FormattedException.java

    r376 r402  
    55 
    66@SuppressWarnings("serial") 
    7 public class FormattedException extends Exception 
     7public class FormattedException 
     8        extends Exception 
    89{ 
    9     public FormattedException(final Object... parameters) { 
    10         this(Locale.getDefault(), DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters); 
     10    public FormattedException( final Object... parameters ) 
     11    { 
     12        this( Locale.getDefault(), DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters ); 
    1113    } 
    1214 
    13     public FormattedException(final Locale locale, final Object... parameters) { 
    14         this(locale, DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters); 
     15    public FormattedException( final Throwable throwable, final Object... parameters ) 
     16    { 
     17        this( Locale.getDefault(), throwable.getMessage(), throwable, parameters ); 
    1518    } 
    1619 
    17     public FormattedException(final String message, final Object... parameters) { 
    18         this(Locale.getDefault(), message, DEFAULT_THROWABLE, parameters); 
     20    public FormattedException( final Locale locale, final String message, final Object... parameters ) 
     21    { 
     22        this( locale, message, null, parameters ); 
    1923    } 
    2024 
    21     public FormattedException(final Locale locale, final String message, final Object... parameters) { 
    22         this(locale, message, null, parameters); 
     25    public FormattedException( final String message, final Throwable throwable, final Object... parameters ) 
     26    { 
     27        this( Locale.getDefault(), message, throwable, parameters ); 
    2328    } 
    2429 
    25     public FormattedException(final Throwable throwable, final Object... parameters) { 
    26         this(Locale.getDefault(), throwable.getMessage(), throwable, parameters); 
     30    public FormattedException( final Locale locale, final String message, final Throwable throwable, final Object... parameters ) 
     31    { 
     32        super( format( locale, message, parameters ), throwable ); 
    2733    } 
    2834 
    29     public FormattedException(final String message, final Throwable throwable, final Object... parameters) { 
    30         this(Locale.getDefault(), message, throwable, parameters); 
     35    public FormattedException( final Enum<? extends Code> code, final String message, final Throwable throwable, 
     36                               final Object... parameters ) 
     37    { 
     38        this( prefix( code, message ), throwable, parameters ); 
    3139    } 
    3240 
    33     public FormattedException(final Locale locale, final String message, final Throwable throwable, final Object... parameters) { 
    34         super(format(locale, message, parameters), throwable); 
     41    private static String format( final Locale locale, final String message, final Object[] parameters ) 
     42    { 
     43        final StringBuilder stringBuilder = new StringBuilder(); 
     44        final Formatter formatter = new Formatter( stringBuilder ); 
     45        formatter.format( locale, message, parameters ); 
     46        return stringBuilder.toString(); 
    3547    } 
    3648 
    37     private static String format(final Locale locale, final String message, final Object[] parameters) 
     49    public static String formatThrowable( final Enum<? extends Code> code, final String message, final Throwable throwable ) 
    3850    { 
    39         final StringBuilder stringBuilder = new StringBuilder(); 
    40         final Formatter formatter = new Formatter(stringBuilder); 
    41         formatter.format(locale, message, parameters); 
    42         return stringBuilder.toString(); 
     51        if( throwable.equals( EXCEPTION_THROWABLE ) ) 
     52            return code.name(); 
     53        else 
     54            return prefix( code, message ); 
    4355    } 
    4456 
     
    4658     * Prefixes the message with code if not null. 
    4759     */ 
    48     public static String prefix(final Enum<? extends Code> code, final String message) 
     60    public static String prefix( final Enum<? extends Code> code, final String message ) 
    4961    { 
    50                 final StringBuffer stringBuffer = new StringBuffer(); 
     62        final StringBuffer stringBuffer = new StringBuffer(); 
    5163 
    52                 if (code != null) { 
    53                         stringBuffer.append(code.toString()); 
    54                         stringBuffer.append(" - "); 
    55                 } 
     64        if( code != null ) 
     65        { 
     66            stringBuffer.append( code.toString() ); 
     67            stringBuffer.append( " - " ); 
     68        } 
    5669 
    57                 stringBuffer.append(message); 
    58                 return stringBuffer.toString(); 
     70        stringBuffer.append( message ); 
     71        return stringBuffer.toString(); 
     72    } 
     73 
     74    public static Throwable getExceptionThrowable() 
     75    { 
     76        return EXCEPTION_THROWABLE; 
    5977    } 
    6078 
    6179    /** 
    62      * The error code, it identifies the type of error.  
    63      * The derived classes must creates their own code as enum and implements this interface.  
     80     * The error code, it identifies the type of error. 
     81     * The derived classes must creates their own code as enum and implements this interface. 
    6482     * If the subclass is not an enum it won't be recognized by the constructor. 
    6583     */ 
     
    7088    public static String DEFAULT_MESSAGE = "no message"; 
    7189    public static String DEFAULT_THROWABLE = null; 
     90    private static final Throwable EXCEPTION_THROWABLE = new Throwable( "EXCEPTION_THROWABLE" ); 
    7291} 
Note: See TracChangeset for help on using the changeset viewer.