Make validation of model properties more powerful

Custom validate function can be defined in the metadata now. This
function should throw an exception when value is invalid. Otherwise,
it *must* return the final value. Note that it can be used to
automatically "fix" the simple user errors if validation functions
knows how to do it.