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

play.data.validation.IPv6AddressCheck Maven / Gradle / Ivy

There is a newer version: 2.6.2
Show newest version
package play.data.validation;

import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;
import net.sf.oval.exception.OValException;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPv6AddressCheck extends AbstractAnnotationCheck {

    static final String mes = "validation.ipv6";

    @Override
    public void configure(IPv6Address phone) {
        setMessage(phone.message());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator)
    throws OValException {
        if (value == null || value.toString().length() == 0) {
            return true;
        }
        try {
            InetAddress addr = InetAddress.getByName(value.toString());
            return addr instanceof Inet6Address;
        } catch (UnknownHostException e) {
            return false;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy