KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > converters > ByteConverter


1 package jodd.bean.converters;
2
3 /**
4  * Converts given object to Byte. Given object (if not already instance of
5  * Byte) is first converted to String and then analyzed.
6  */

7
8 public class ByteConverter implements jodd.bean.Converter {
9
10
11     public Object convert(Object value) throws IllegalArgumentException {
12         
13         if (value == null) {
14             return (Byte) null;
15         }
16
17         if (value instanceof Byte) {
18             return (value);
19         } else if (value instanceof Number) {
20             return new Byte(((Number)value).byteValue());
21         }
22         try {
23             return (new Byte(value.toString()));
24         } catch (Exception e) {
25             throw new IllegalArgumentException("Byte conversion for " + value + " failed.");
26         }
27     }
28
29 }
30
Popular Tags