All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.cast.castor.EmailAddressCastor Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy