FileDocCategorySizeDatePackage
AttrString.javaAPI DocGlassfish v2 API4650Fri May 04 22:24:36 BST 2007com.sun.enterprise.config.serverbeans.validation

AttrString

public class AttrString extends AttrType
Class which contains Meta data for all types of attributes which is present in Validation Descriptor XML File Sample type="address" /> type="integer" range="low,high" /> type="string" max-length="length" />
author
Srinivas Krishnan
version
2.0

Fields Summary
int
maxLength
Vector
ee
String
expr
Constructors Summary
public AttrString(String name, String type, boolean optional)

        super(name,type, optional);
        this.maxLength = 0;
        ee = null;
        expr = null;
    
Methods Summary
public intgetMaxLength()

        return maxLength;
    
public voidsetEnumstring(java.util.Vector vec)

        ee = vec;
    
public voidsetMaxLength(int max)

        maxLength = max;
    
public voidsetRegExpression(java.lang.String str)

        expr = str;
    
public voidvalidate(java.lang.Object o, ValidationContext valCtx)

        super.validate(o, valCtx); // call to common validator first
        if(o == null) {
            return; 
        }
        
        final String str = (String)o;
        if(0 != maxLength && str.length() > maxLength) {
            reportAttributeError(valCtx, "invalidStringLength",
                "Attribute[{0}={1}] : String {2} length is greather than maximum length {3}",
                new Object[] {valCtx.attrName, str, str, String.valueOf(maxLength)});
        }
        if(null != ee && !ee.contains(str) ){
            reportAttributeError(valCtx, "strInvalidEnum",
                "Attribute({0}={1}) : Invalid String - Required {2}",
                new Object[] {valCtx.attrName, str, ee.toString()});
        }
        
        if(null != expr && !str.matches(expr)) 
        {
            String printOwnerName = GenericValidator.getConfigElementPrintName(
                valCtx, getFutureXPathForValidatingAttribute(valCtx), false, false);
            String generic_descr = valCtx.smh.getLocalString(
                "default_pattern_description",
                "Please refer to admin documentation." );
            String descr = valCtx.smh.getLocalString(
                "pattern_description_for_" + (expr.replaceAll("[\\\\=:]", "`")),
                generic_descr );
            
            reportAttributeError(valCtx, "regexpNotMatch",
                "Value \"{1}\" is not valid for attribute \"{0}\" of {2}. {3}", 
                new Object[] {valCtx.attrName, str, printOwnerName, descr});
        }