Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

edu.virtualschool.jwaa.field.GenericField Class Reference

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

edu.virtualschool.jwaa.field.Validatable edu.virtualschool.jwaa.field.CityField edu.virtualschool.jwaa.field.CommaSeparatedField edu.virtualschool.jwaa.field.CountryField edu.virtualschool.jwaa.field.DoubleField edu.virtualschool.jwaa.field.EmailField edu.virtualschool.jwaa.field.FileField edu.virtualschool.jwaa.field.IdentifierField edu.virtualschool.jwaa.field.IntegerField edu.virtualschool.jwaa.field.LongField edu.virtualschool.jwaa.field.NameField edu.virtualschool.jwaa.field.OpField edu.virtualschool.jwaa.field.StreetField edu.virtualschool.jwaa.field.TextField edu.virtualschool.jwaa.field.ZipcodeField Collaboration diagram for edu.virtualschool.jwaa.field.GenericField:

Collaboration graph
[legend]
List of all members.

Detailed Description

Fields represent user-accessible data exposed via an application's user interface. They are concerned only with data representation and validation; presentation is handled elsewhere. All fields implement the Validatable interface specification.

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())


Member Function Documentation

final Validatable edu.virtualschool.jwaa.field.GenericField.cloneWithValue String  stringValue  )  throws Fault
 

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   }

final RE edu.virtualschool.jwaa.field.GenericField.createRegexp String  s  )  [static]
 

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.

Parameters:
s: the regular expression source code
Returns:
RE: the compiled regular expression

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   }

final String edu.virtualschool.jwaa.field.GenericField.getMessage  ) 
 

Return the validation message. This is contructed only at this late date to cut down on instance creation.

Returns:
String

Implements edu.virtualschool.jwaa.field.Validatable.

Definition at line 71 of file GenericField.java.

00071 { return message; }

final String edu.virtualschool.jwaa.field.GenericField.getStringValue  ) 
 

Return the value of this field as a String

Returns:
String: 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; }

boolean edu.virtualschool.jwaa.field.GenericField.ok  ) 
 

Does field's contents comply with its class's syntactic validity requirements?

Returns:
boolean

Implements edu.virtualschool.jwaa.field.Validatable.

Definition at line 77 of file GenericField.java.

00077 { return ok; }

final void edu.virtualschool.jwaa.field.GenericField.requireLength int  min,
int  max
 

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   }

final void edu.virtualschool.jwaa.field.GenericField.requireLengthMax int  max  ) 
 

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   }

final void edu.virtualschool.jwaa.field.GenericField.requireLengthMin int  min  ) 
 

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   }

final void edu.virtualschool.jwaa.field.GenericField.requireMatch RE  re,
String  m
 

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   }

final void edu.virtualschool.jwaa.field.GenericField.requireNonNull  ) 
 

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   }

final void edu.virtualschool.jwaa.field.GenericField.setValid boolean  v,
String  m
 

Set the validity and messsage of this field to specified

Parameters:
v: true if valid
m: reason if not valie

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; } }


The documentation for this class was generated from the following file: