1 7 package org.jboss.xml.binding; 8 9 import java.text.ParseException ; 10 11 15 public interface TypeConverter 16 { 17 TypeConverter STRING = new TypeConverter() 18 { 19 public Object unmarshal(String value) 20 { 21 return value; 22 } 23 24 public String marshal(Object value) 25 { 26 return (String )value; 27 } 28 }; 29 30 TypeConverter INT = new TypeConverter() 31 { 32 public Object unmarshal(String value) 33 { 34 return Integer.valueOf(value); 35 } 36 37 public String marshal(Object value) 38 { 39 return String.valueOf(value); 40 } 41 }; 42 43 TypeConverter LONG = new TypeConverter() 44 { 45 public Object unmarshal(String value) 46 { 47 return Long.valueOf(value); 48 } 49 50 public String marshal(Object value) 51 { 52 return String.valueOf(value); 53 } 54 }; 55 56 TypeConverter DOUBLE = new TypeConverter() 57 { 58 public Object unmarshal(String value) 59 { 60 return Double.valueOf(value); 61 } 62 63 public String marshal(Object value) 64 { 65 return String.valueOf(value); 66 } 67 }; 68 69 TypeConverter FLOAT = new TypeConverter() 70 { 71 public Object unmarshal(String value) 72 { 73 return Float.valueOf(value); 74 } 75 76 public String marshal(Object value) 77 { 78 return String.valueOf(value); 79 } 80 }; 81 82 TypeConverter SHORT = new TypeConverter() 83 { 84 public Object unmarshal(String value) 85 { 86 return Short.valueOf(value); 87 } 88 89 public String marshal(Object value) 90 { 91 return String.valueOf(value); 92 } 93 }; 94 95 TypeConverter BYTE = new TypeConverter() 96 { 97 public Object unmarshal(String value) 98 { 99 return Byte.valueOf(value); 100 } 101 102 public String marshal(Object value) 103 { 104 return String.valueOf(value); 105 } 106 }; 107 108 TypeConverter CHAR = new TypeConverter() 109 { 110 public Object unmarshal(String value) 111 { 112 return value == null ? null : new Character (value.charAt(0)); 113 } 114 115 public String marshal(Object value) 116 { 117 return String.valueOf(value); 118 } 119 }; 120 121 TypeConverter JAVA_UTIL_DATE = new TypeConverter() 122 { 123 private static final String FORMAT = "yyyy-MM-dd"; 124 125 public Object unmarshal(String value) 126 { 127 try 128 { 129 return new java.text.SimpleDateFormat (FORMAT).parse(value); 130 } 131 catch(ParseException e) 132 { 133 throw new IllegalStateException ("Failed to parse date string value: " + value); 134 } 135 } 136 137 public String marshal(Object value) 138 { 139 return new java.text.SimpleDateFormat (FORMAT).format(value); 140 } 141 }; 142 143 Object unmarshal(String value); 144 145 String marshal(Object value); 146 } 147 | Popular Tags |