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