[Jvalid-devel] Retrieving native values.
Status: Alpha
Brought to you by:
mikewill_1998
|
From: Mike W. <mik...@st...> - 2001-03-22 00:49:32
|
I think I may have a solution that I want to bounce off you.
We could provide two methods of validation. The current one validate(
"<Contraint_Name>", value ) and one more that will return an object
representing the native value.
The second method would take the same parameters as validate but would
return an object. The returned object would be one of the native
wrapper classes or in the case of a date an instance of the Date class.
An exception would be thrown if the value fails the validation. The
exception would provide a getErrorList method that will return the
normal List of errors. If you simply called getMessage() it would
collect all the errors in the list and return them as a string.
I believe this would give us the best of both worlds! Plus, my earlier
reservations would be taken care of :) We would still have a clean
simple solution and it would be more flexible. If all you care about is
validation you call validate and check the ErrorList for errors. If you
want the value you call getObject( "<Contraint_Name>", value ), catch
the exception and cast the returned object to your expected data type.
Here's an example (Probably need to come up with a better name for the
Exception :)
try
{
Date orderDate = (Date) validator.getObject( "OrderDate", testDate );
//-------------------------------
// Data was valid so do something with it :)
//-------------------------------
}
catch ( ScrewedUpDataException sud )
{
List errorList = sud.getErrorList();
//-----------------------
// Do something with the errors.
//-----------------------
}
|