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

StringValidator

public class StringValidator extends BaseValidator
Class for validating String method parameters. Current implementation's stock object (getInstance()) verifies that the String exists and has length > 0
author
bnevins
version
$Revision: 1.6 $

Fields Summary
private final int
mMininumLength
private static final int
kDefaultMinimumLength
private static final StringValidator
sDefaultInstance
private static final String
badArgMessage
Constructors Summary
public StringValidator(int minimumLength)
Create a StringValidator

param
minimumLength The String is invalid if its length is less than this


                         
       
     
        Assert.assertRange(minimumLength, 0, Integer.MAX_VALUE, "minimumLength"); 
        mMininumLength = minimumLength; 
    
Methods Summary
public static ValidatorgetInstance()
Get the standard StringValidator

return
A class variable with a default minimum length of 1

        return sDefaultInstance;
    
private ValidatorResultmakeBadResult(int len)

        return new ValidatorResult(false, 
                        "The String argument is invalid.  The minimum required length is " +
                        mMininumLength + " and the String's actual length is " + len);
    
public ValidatorResultvalidate(java.lang.Object obj)
Validate a String

param
obj The String to be validated
return
ValidatorResult is invalid if the String's length was less than the minimum required length

 
        ValidatorResult result = super.validate(obj);

        if (result.isValid()) 
        { 
            Assert.assertit( (obj instanceof String), badArgMessage);

            final String 	str = (String)obj; 
            final int		len	= str.length();

            if(len < mMininumLength) 
            { 
                result = makeBadResult(len);
            } 
        } 
        return result;