1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.util.Vector ; 27 28 40 41 42 43 public class AttrString extends AttrType { 44 45 int maxLength; 46 Vector ee; 47 String expr; 48 49 public AttrString(String name, String type, boolean optional) { 50 super(name,type, optional); 51 this.maxLength = 0; 52 ee = null; 53 expr = null; 54 } 55 56 public void setRegExpression(String str) { 57 expr = str; 58 } 59 60 public void setEnumstring(Vector vec) { 61 ee = vec; 62 } 63 64 public int getMaxLength() { 65 return maxLength; 66 } 67 68 public void setMaxLength(int max) { 69 maxLength = max; 70 } 71 72 public void validate(Object o, ValidationContext valCtx) { 73 super.validate(o, valCtx); if(o == null) { 75 return; 76 } 77 78 final String str = (String )o; 79 if(0 != maxLength && str.length() > maxLength) { 80 reportAttributeError(valCtx, "invalidStringLength", 81 "Attribute[{0}={1}] : String {2} length is greather than maximum length {3}", 82 new Object [] {valCtx.attrName, str, str, String.valueOf(maxLength)}); 83 } 84 if(null != ee && !ee.contains(str) ){ 85 reportAttributeError(valCtx, "strInvalidEnum", 86 "Attribute({0}={1}) : Invalid String - Required {2}", 87 new Object [] {valCtx.attrName, str, ee.toString()}); 88 } 89 90 if(null != expr && !str.matches(expr)) 91 { 92 String printOwnerName = GenericValidator.getConfigElementPrintName( 93 getFutureXPathForValidatingAttribute(valCtx), false, false); 94 String generic_descr = valCtx.smh.getLocalString( 95 "default_pattern_description", 96 "Please refer to admin documentation." ); 97 String descr = valCtx.smh.getLocalString( 98 "pattern_description_for_" + (expr.replaceAll("[\\\\=:]", "`")), 99 generic_descr ); 100 101 reportAttributeError(valCtx, "regexpNotMatch", 102 "Value \"{1}\" is not valid for attribute \"{0}\" of {2}. {3}", 103 new Object [] {valCtx.attrName, str, printOwnerName, descr}); 104 } 105 } 106 } 107 108 | Popular Tags |