Inheritance diagram for edu.virtualschool.jwaa.field.GenericField:


The base Field class imposes no validation constraints at all (e.g. anything goes). Validation constraints are added by field subclasses such as CityField, USStateField, CountryField, ZipcodeField, IDField, DollarField, etc.
Fields will be automatically reusable across applications if and only if the database declaration for each application complies with the field length and type assumptions of the Field subclass. For example, Field records must be declared text because Field imposes no length restriction, CityField records should be varchar(64) because CityField imposes a max length restriction of 64, and so forth. If the maximum length assumptions are not appropriate (maybe your application manages Welch village names), make a new field subclass.
An API that automates Field to SQL dependencies was tried but proved unwieldy. I may revisit this later. Fixme. Copyright 2002 by Brad Cox: <bcox@virtualschool.edu>
Definition at line 36 of file GenericField.java.
Public Member Functions | |
| GenericField (Object value, Object defaultValue) | |
| final void | setValid (boolean v, String m) |
| final String | getMessage () |
| boolean | ok () |
| final String | getStringValue () |
| boolean | equals (Object o) |
| final int | hashCode () |
| final String | toString () |
| final Validatable | cloneWithValue (String stringValue) throws Fault |
| final void | requireLength (int min, int max) |
| final void | requireLengthMax (int max) |
| final void | requireLengthMin (int min) |
| final void | requireMatch (RE re, String m) |
| final void | requireNonNull () |
| String | inspect () |
Static Public Member Functions | |
| final RE | createRegexp (String s) |
Public Attributes | |
| String | stringValue |
| boolean | ok |
| String | message |
Static Package Attributes | |
| final Logger | logger = Logger.getLogger(GenericField.class.getName()) |
|
|
Create an instance of the receiver with the provided value; Implements edu.virtualschool.jwaa.field.Validatable. Definition at line 92 of file GenericField.java.
00093 {
00094 if (stringValue == null)
00095 stringValue = "";
00096 Class c = this.getClass();
00097 Object[] argValues = new Object[] { stringValue };
00098 try
00099 {
00100 Constructor constructor = c.getConstructor(argTypes);
00101 Object copy = constructor.newInstance(argValues);
00102 return (Validatable)copy;
00103 }
00104 catch (Exception e)
00105 {
00106 throw new Fault(e.getMessage() + "\n"+c.getName()+"="+stringValue+"\n"+
00107 c.getName()+" must be public and must have a public constructor with one argument of type Object");
00108 }
00109 }
|
|
|
Convenience method to help subclasses build regular expressions as class initializers without screwing around with REexception. in class initializers. This class catches all REexceptions, logs them, and ignores any it catches, returning null. Caveat emptor.
Definition at line 119 of file GenericField.java.
00120 {
00121 try { return new RE(s); }
00122 catch (REException e)
00123 {
00124 System.err.println("REException compiling " + s);
00125 e.printStackTrace(System.err);
00126 return null;
00127 }
00128 }
|
|
|
Return the validation message. This is contructed only at this late date to cut down on instance creation.
Implements edu.virtualschool.jwaa.field.Validatable. Definition at line 71 of file GenericField.java.
00071 { return message; }
|
|
|
Return the value of this field as a String
Implements edu.virtualschool.jwaa.field.Validatable. Definition at line 79 of file GenericField.java.
00079 { return stringValue; }
|
|
|
Does field's contents comply with its class's syntactic validity requirements?
Implements edu.virtualschool.jwaa.field.Validatable. Definition at line 77 of file GenericField.java.
00077 { return ok; }
|
|
||||||||||||
|
Require stringValue.length to be between min and max Definition at line 132 of file GenericField.java. References edu.virtualschool.jwaa.field.GenericField.requireLengthMax(), and edu.virtualschool.jwaa.field.GenericField.requireLengthMin().
00133 {
00134 requireLengthMin(min);
00135 requireLengthMax(max);
00136 }
|
|
|
Require stringValue.length to be < max Definition at line 140 of file GenericField.java. References edu.virtualschool.jwaa.field.GenericField.setValid(). Referenced by edu.virtualschool.jwaa.field.GenericField.requireLength().
00141 {
00142 int len = stringValue.length();
00143 if (len > max) setValid(false,
00144 "Fewer than " + max + " characters are required");
00145 }
|
|
|
Require stringValue.length to be >= min. Definition at line 149 of file GenericField.java. References edu.virtualschool.jwaa.field.GenericField.setValid(). Referenced by edu.virtualschool.jwaa.field.GenericField.requireLength().
00150 {
00151 int len = stringValue.length();
00152 if(len < min) setValid(false,
00153 "At least " + min + " characters are required");
00154 }
|
|
||||||||||||
|
Require regular expression match Definition at line 158 of file GenericField.java. References edu.virtualschool.jwaa.field.GenericField.setValid().
00159 {
00160 if(!re.isMatch(stringValue)) setValid(false,m);
00161 }
|
|
|
Require the stringValue to not be null or "" Definition at line 165 of file GenericField.java. References edu.virtualschool.jwaa.field.GenericField.setValid().
00166 {
00167 if(stringValue.equals("")) setValid(false,"*");
00168 }
|
|
||||||||||||
|
Set the validity and messsage of this field to specified
Implements edu.virtualschool.jwaa.field.Validatable. Definition at line 64 of file GenericField.java. Referenced by edu.virtualschool.jwaa.field.GenericField.requireLengthMax(), edu.virtualschool.jwaa.field.GenericField.requireLengthMin(), edu.virtualschool.jwaa.field.GenericField.requireMatch(), and edu.virtualschool.jwaa.field.GenericField.requireNonNull().
00065 { if (ok) { ok = v; message = m; } }
|