/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

/**
 *
 * @author gleimar
 */
public class MACConstraint implements Constraint {

    @Override
    public void validate(Component cmpnt, Object o) throws WrongValueException {
        if (o == null) {
            throw new WrongValueException(cmpnt, Labels.getLabel("MSG.CONSTRAINT.MACConstraint"));
        }

        String strMAC = o.toString();

        strMAC = strMAC.replaceAll("-", "");

        if (strMAC.length() != 12) {
            throw new WrongValueException(cmpnt, Labels.getLabel("MSG.CONSTRAINT.MACConstraint"));
        }

        try {
            Long.parseLong(strMAC, 16);
        } catch (Throwable t) {
            throw new WrongValueException(cmpnt, Labels.getLabel("MSG.CONSTRAINT.MACConstraint"));
        }
    }
}
