001package org.javasimon.utils.bean;
002
003/**
004 * Converter from String to Long.
005 *
006 * @author <a href="mailto:ivan.mushketyk@gmail.com">Ivan Mushketyk</a>
007 */
008public class ToLongConverter implements Converter {
009
010        @Override
011        public Long convert(Class<?> targetClass, String strVal) {
012                if (strVal == null) {
013                        return null;
014                }
015
016                try {
017                        return Long.parseLong(strVal);
018                } catch (NumberFormatException ex) {
019                        throw new ConvertException(
020                                String.format("Cannot convert string '%s' to Long", strVal));
021                }
022        }
023}