panda.cast.castor.EmailAddressCastor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.cast.castor;
import panda.cast.CastContext;
import panda.lang.Strings;
import panda.net.mail.EmailAddress;
import panda.net.mail.EmailException;
public class EmailAddressCastor extends AnySingleCastor {
public EmailAddressCastor() {
super(EmailAddress.class);
}
@Override
protected EmailAddress castValue(Object value, CastContext cc) {
if (value instanceof CharSequence) {
String s = value.toString();
if (Strings.isEmpty(s)) {
return defaultValue();
}
try {
return EmailAddress.parse(s);
}
catch (EmailException e) {
return castError(value, cc, e);
}
}
JavaBeanCastor jbc = new JavaBeanCastor(EmailAddress.class, cc.getCastors().getBeans());
return jbc.cast(value, cc);
}
}