FileDocCategorySizeDatePackage
AssertImpl.javaAPI DocGlassfish v2 API6452Fri May 04 22:34:10 BST 2007com.sun.enterprise.admin.util

AssertImpl

public final class AssertImpl extends Object
Implementation class for Assert and CheckArgs

Fields Summary
private int
mExceptionType
private boolean
mWantStackTrace
private String
mPreamble
private static final String
sDefaultPreamble
static final int
sAssertError
static final int
sIllegalArgument
private static com.sun.enterprise.admin.util.SOMLocalStringsManager
localizedStrMgr
Constructors Summary
AssertImpl(int exceptionType)


     
    
        this("", exceptionType);
    
AssertImpl(String msg, int exceptionType)

        mPreamble 		= msg;
        mExceptionType	= exceptionType;

        if(mPreamble == null)
        {
            mPreamble = sDefaultPreamble;
        }

        // add a ": " -- if it isn't an empty string
        if(mPreamble.length() > 0 && !mPreamble.endsWith(": "))
        {
            mPreamble += ": ";
        }

        if(mExceptionType < sAssertError || mExceptionType > sIllegalArgument)
        {
            lowLevelAssert("Invalid exception type id.  Must be 0 or 1");

            // caller could swallow that assert and call assert() later
            // so let's setup a reasonable value.
            mExceptionType = sAssertError;	
        }
    
Methods Summary
voidassertIt(boolean b, java.lang.Object userMsg)

        if (b)
        {
            return;
        }
        String msg = null;
        if(userMsg != null)
        {
            msg = userMsg.toString();
        }
        else
        {
            msg = "boolean test was false";
        }
        toss(msg);
    
voidassertRange(long value, long min, long max, java.lang.Object userMsg)

        if (value < min || value > max)
        {
            final String rangeString = "[" + min + ", " + max + "]";
            String msg	= "illegal integer value = " + value +
                    " must be in range " + rangeString;
            if (userMsg != null)
            {
                msg += " ( " + userMsg.toString() + " )";
            }
            toss(msg);
        }
    
voidassertValid(java.lang.Object object, java.lang.String name, com.sun.enterprise.admin.util.Validator validator)

  
        final ValidatorResult result = validator.validate(object);

        if (!result.isValid())
        {
            final String msg	= "Validation failed for " + name +
                                            ": " + result.getString();
            toss(msg);
        }
    
private voidlowLevelAssert(java.lang.String s)

        // if there is a problem in this code -- we can't do a normal assert or
        // we are going to enter an infinite loop - since Assert calls us!!

		String msg = localizedStrMgr.getString( "admin.util.fatal_error_in_setupexceptionconstructor", s );
        throw new AssertError( msg );
    
private voidpr(java.lang.String s)

        Debug.println(s);
    
voidsetWantStackTrace(boolean what)

        mWantStackTrace = what;
    
private voidtoss(java.lang.String msg)
An assertion has failed, do something with the message. Our current implemention is to dump the stack trace and throw an AssertError, so that the failure is obnoxious and will be noticed.

        String s = mPreamble + msg;
        Throwable t = null;

        /* yes -- the following is ugly.  But there is NO WAY to throw the 
         * common superclass -- Throwable -- without making everyone on 
         * the call stack declare it!!
         **/

        if(mExceptionType == sIllegalArgument)
        {
            IllegalArgumentException iae = new IllegalArgumentException(s);

            if(mWantStackTrace)
            {
                Debug.printStackTrace(iae);
            }
            throw iae;
        }
        else if(mExceptionType == sAssertError)
        {
            AssertError ae = new AssertError(s);

            if(mWantStackTrace)
            {
                Debug.printStackTrace(ae);
            }
            throw ae;
        }
        else
        {
            lowLevelAssert("Impossible condition -- bad mExceptionType -- " 
                    + mExceptionType);
        }