AttrIntpublic class AttrInt 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" /> |
Fields Summary |
---|
public static final int | IGNORE_LOW | public static final int | IGNORE_HIGH | int | highRange | int | lowRange |
Constructors Summary |
---|
public AttrInt(String name, String type, boolean optional)
super(name,type, optional);
this.highRange = IGNORE_HIGH;
this.lowRange = IGNORE_LOW;
|
Methods Summary |
---|
int | compareIntWithStr(int iVal, java.lang.String strVal)
return (iVal-Integer.parseInt(strVal));
| public int | getHighRange()
return highRange;
| public int | getLowRange()
return lowRange;
| public void | setHighRange(int high)
highRange = high;
| public void | setLowRange(int low)
lowRange = low;
| public void | validate(java.lang.Object value, ValidationContext valCtx)
super.validate(value, valCtx); // call to common validator first
int tmp=0;
boolean success=true;
if(value == null || value.equals(""))
return;
if(valCtx.isDELETE())
return;
try {
tmp = Integer.parseInt(value.toString());
} catch(NumberFormatException n) {
reportAttributeError(valCtx, "invalidInteger",
"Attribute({0}={1}) : {2} Invalid integer",
new Object[] {valCtx.attrName, value, value});
success=false;
}
if(success) {
if( (lowRange != IGNORE_LOW && tmp < lowRange) || (highRange != IGNORE_HIGH && tmp > highRange) ) {
if(lowRange == 0 && highRange == IGNORE_HIGH) {
reportAttributeError(valCtx, "invalidIntegerNegative",
"Attribute({0}={1}) : {2} Invalid Value, Cannot be a negative number",
new Object[] {valCtx.attrName, String.valueOf(tmp), String.valueOf(tmp)});
}
else
{
reportAttributeError(valCtx, "invalidIntegerRange",
"Attribute({0}={1}) : {2} Invalid Value, Valid Range {3},{4}",
new Object[] {valCtx.attrName, String.valueOf(tmp), String.valueOf(tmp), String.valueOf(lowRange), String.valueOf(highRange)});
}
}
String compValue = getValueForAttribute((String)getRuleValue("le-than"), valCtx);
if(compValue!=null && !compValue.trim().equals("0"))
{
if(compareIntWithStr(tmp, compValue)>0)
reportAttributeError(valCtx, "not-le-than",
"Value ({0}) should be less or equal than to value of attribute {1} ({2})",
new Object[]{value, getRuleValue("le-than"), compValue});
}
compValue = getValueForAttribute((String)getRuleValue("ge-than"), valCtx);
if(compValue!=null && !compValue.trim().equals("0"))
{
if(compareIntWithStr(tmp, compValue)<0)
reportAttributeError(valCtx, "not-ge-then",
"Value ({0}) should be more or equal to value of attribute {1} ({2})",
new Object[]{value, getRuleValue("ge-than"), compValue});
}
compValue = getValueForAttribute((String)getRuleValue("gt-than"), valCtx);
if(compValue!=null && !compValue.trim().equals("0"))
{
if(compareIntWithStr(tmp, compValue)<=0)
reportAttributeError(valCtx, "not-gt-then",
"Value ({0}) should be more then value of attribute {1} ({2})",
new Object[]{value, getRuleValue("gt-than"), compValue});
}
compValue = getValueForAttribute((String)getRuleValue("ls-than"), valCtx);
if(compValue!=null && !compValue.trim().equals("0"))
{
if(compareIntWithStr(tmp, compValue)>=0)
reportAttributeError(valCtx, "not-ls-then",
"Value ({0}) should be less than value of attribute {1} ({2})",
new Object[]{value, getRuleValue("ls-than"), compValue});
}
}
|
|