* source
* @param targetClass
* target class
*/
public Object convert(Object source, Class targetClass) {
Email email = null;
try {
if (source != null) {
if (targetClass == Email.class) {
// from String to Email
if (source instanceof Email) {
email = (Email) source;
} else if (source instanceof String) {
String emailString = (String) source;
if (emailString.equals("")) {
return null;
} else {
email = Transformer.email(emailString);
if (email == null) {
throw new ConversionException("Not a valid Email: "
+ source);
}
}
} else {
throw new ConversionException("Not a valid Email: "
+ source);
}
} else if (targetClass == String.class) {
// from Email to String
if (source instanceof String) {
return source;
} else if (source instanceof Email) {
Email convertedEmail = (Email) source;
String emailString = Transformer.string(convertedEmail);
return emailString;
} else {
throw new ConversionException("Not a valid Email: "
+ source);