/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dhaval.web.vaadin.simple.validators;

import com.vaadin.data.Validator;
import java.util.Date;

/**
 *
 * @author dhaval
 */
public class DateValidator implements Validator{

    private String message;

    public DateValidator(String message) {
        this.message = message;
    }


    public void validate(Object value) throws InvalidValueException {
        if(!isValid(value)){
            throw new InvalidValueException(message);
        }
    }

    public boolean isValid(Object value) {
        if(value instanceof Date){
            return true;
        }

        try{
            Date d = new Date(value.toString());
            return true;
        }catch(Exception e){
            return false;
        }
    }

}
