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

ArgChecker

public class ArgChecker extends Object
Use ArgChecker to check method parameters
Example usage:
ArgChecker.check( name != null, "null name" );
ArgChecker.check( index, 0, numItems, "index" );
ArgChecker.check( str, "userName");
ArgChecker.check( str, minimumStringLength, "userName");
ArgChecker.checkValid(parameter, "parameter-name");

Fields Summary
private static final boolean
sChecksEnabled
private static final com.sun.enterprise.admin.util.AssertImpl
sImpl
Constructors Summary
private ArgChecker()


    
    
        // need to do this in a static block to guarantee the 
        // setWantStackTrace() call
        sImpl = new AssertImpl("ArgChecker Failure", AssertImpl.sIllegalArgument);
        sImpl.setWantStackTrace(false);
    
        Assert.assertit(false, "You can't call the ArgChecker constructor!");
    
Methods Summary
public static voidcheck(java.lang.String checkMe, int minimumLength, java.lang.String name)
Check the String with a custom StringValidator

param
checkMe a String to check
param
minimumLength The minimum acceptable length of the String to allow
param
name The name of the String
throws
IllegalArgumentException if checkMe is null or zero-length

  
        check(checkMe, name, new StringValidator(minimumLength)); 
    
public static final voidcheck(boolean b, java.lang.Object msg)
If expression is false, take appropriate action to note the failure.

If expression is true, do nothing.

param
b boolean derived from callers expression.
param
msg message to be added to IllegalArgumentException upon failure
throws
IllegalArgumentException if b is false

        if ( sChecksEnabled )
        {
            sImpl.assertIt(b, msg);
        }
    
public static final voidcheck(long value, long min, long max, java.lang.Object userMsg)
Checks that the specified value is in a specified range.

A convenience method which calls checkRange()

see
#checkRange
param
value the value to be range-checked
param
min minimum value. value must be >= min
param
max maximum value. value must be <= max
param
userMsg additional user message (optional) to be included
throws
IllegalArgumentException if the specified value is not in the specified range.

        checkRange(value, min, max, userMsg);
    
public static voidcheck(java.lang.Object object, java.lang.String name, com.sun.enterprise.admin.util.Validator validator)
Checks that the object is valid generically by using a Validation object.

Convenience method. Calls checkValid().

see
checkValid(Object, String, IValidator)
param
object the value to be validated
param
name name of the object to be validated
param
validator validation object to validate the object
throws
IllegalArgumentException if validator says that object is NOT valid

  
        checkValid(object, name, validator);
    
public static voidcheck(java.lang.Object object, java.lang.String name)
Check that the object is valid. Convenience method. Calls checkValid().

see
checkValid(Object, String)
param
object the value to be validated
param
name name of the object to be validated
throws
IllegalArgumentException if validator says that object is NOT valid

        checkValid( object, name);
    
public static voidcheck(java.lang.String checkMe, java.lang.String name)
Check the String with the standard StringValidator

param
checkMe a String to check
param
name The name of the String
throws
IllegalArgumentException if checkMe is null or zero-length

        check(checkMe, name, StringValidator.getInstance()); 
   
public static final voidcheckRange(long value, long min, long max, java.lang.Object userMsg)
Checks that the specified value is in a specified range.

The test done is ( value >= min && value <= max ) If the test fails, then a descriptive string is generated which lists the value together with the min and max and user-specified message.

param
value the value to be range-checked
param
min minimum value. value must be >= min
param
max maximum value. value must be <= max
param
userMsg additional user message (optional) to be included
throws
IllegalArgumentException if the specified value is not in the specified range.

        if ( sChecksEnabled )
        {
            sImpl.assertRange(value, min, max, userMsg);
        }
    
public static voidcheckValid(java.lang.Object object, java.lang.String name, com.sun.enterprise.admin.util.Validator validator)
Checks that the object is valid generically by using a Validation object.

If the validation fails, then the check fails as with other checks.

param
object the value to be validated
param
name name of the object to be validated
param
validator validation object to validate the object
throws
IllegalArgumentException if validator says that object is NOT valid

  
        if ( sChecksEnabled )
        {
            sImpl.assertValid(object, name, validator);
        }
    
public static voidcheckValid(java.lang.Object object, java.lang.String name)
Check that the object is valid. Calls check( object, name, validator ) where validator is either the non-null validator or the object itself, if the object implements IValidator.

param
object the value to be validated
param
name name of the object to be validated
throws
IllegalArgumentException if validator says that object is NOT valid

        final Validator validator  = (object instanceof Validator ) ?
                                        (Validator)object : 
                                        BaseValidator.getInstance();
        check( object, name, validator );