if (! myMetaData.allowsNull(fieldName))
{
if (fieldValue == null)
{
throw new PersistenceException("$keelNullNotAllowed|" + myMetaData.getTableName() + "."
+ myMetaData.getDescription(fieldName));
}
else if (fieldValue.toString().equals(""))
{
throw new PersistenceException("$keelNullNotAllowed|" + myMetaData.getTableName() + "."
+ myMetaData.getDescription(fieldName));
}
}
else
{ /* It's null and it's allowed to be, so do no further checks */
if (fieldValue == null)
{
return;
}
}
Pattern mask = myMetaData.getPattern(fieldName);
if (mask != null)
{
if (! patternMatcher.matches(fieldValue.toString(), mask))
{
throw new PersistenceException("$keelFieldNotMatch|" + fieldName + "|" + mask.getPattern());
}
}
/*
* For multi-valued fields, the value specified must be one of the
* valid values Note: I have changed this behavior slightly from
* previous versions. If a field has been marked as "allowsNull", it
* should pass the check below, even if the field has also been marked
* as "multiValued". In other words, a mutlivalued, allowsnull field
* should pass the checkField method if it has a null value. - Adam
*/
if (myMetaData.isMultiValued(fieldName) && (! fieldValue.equals("")))
{
//Added this line to fix object comparison problems - ACR
String stringFieldValue = fieldValue.toString();
Map values = getValidValues(fieldName);
if (values == null)
{
throw new PersistenceException("(" + getName() + ") '" + myMetaData.getDescription(fieldName)
+ "' is set as multi-valued, but there are no defined " + "valid values" + toString());
}
Object oneValue = null;
for (Iterator e = values.keySet().iterator(); e.hasNext();)
{
oneValue = (String) e.next();
//Changed this line to fix object comparison issues. - ACR
if (stringFieldValue.equals(oneValue))
{
return;
}
} /* for each valid value */
throw new PersistenceException("(" + getName() + ") '" + fieldValue + "' is not a valid value for field '"
+ fieldName + "(" + myMetaData.getDescription(fieldName) + ")' " + toString());
} /* if field is multi-valued */
if (isDateType(myMetaData.getType(fieldName)))
{
String stringDate = fieldValue.toString();
String format = "yyyy-MM-dd hh:mm:ss";
String type = myMetaData.getType(fieldName);
if (type.equalsIgnoreCase("date"))
{
format = "yyyy-MM-dd";
}
else if (type.equalsIgnoreCase("time"))
{
format = "hh:mm:ss";
}
//--- quikdraw: This is doing exactly what?
try
{
new SimpleDateFormat(format).parse(stringDate);
}
catch (ParseException pe)
{
throw new PersistenceException("Value '" + stringDate + "' for field '"
+ myMetaData.getDescription(fieldName) + "' cannot be parsed as a date");
}
}
} /* checkField(String, String) */