1 16 17 18 package org.apache.xmlrpc; 19 20 21 import java.text.ParseException ; 22 23 import org.apache.commons.codec.binary.Base64; 24 import org.apache.commons.codec.DecoderException; 25 import org.apache.xmlrpc.util.DateTool; 26 27 45 public class DefaultTypeFactory 46 implements TypeFactory 47 { 48 52 private static DateTool dateTool = new DateTool(); 53 private static final Base64 base64Codec = new Base64(); 54 55 58 public DefaultTypeFactory() 59 { 60 } 61 62 public Object createInteger(String cdata) 63 { 64 return new Integer (cdata.trim()); 65 } 66 67 public Object createBoolean(String cdata) 68 { 69 return ("1".equals(cdata.trim ()) 70 ? Boolean.TRUE : Boolean.FALSE); 71 } 72 73 public Object createDouble(String cdata) 74 { 75 return new Double (cdata.trim ()); 76 77 } 78 79 public Object createDate(String cdata) 80 { 81 try 82 { 83 return dateTool.parse(cdata.trim()); 84 } 85 catch (ParseException p) 86 { 87 throw new RuntimeException (p.getMessage()); 88 } 89 } 90 91 public Object createBase64(String cdata) 92 { 93 try 94 { 95 return base64Codec.decode((Object ) cdata.getBytes()); 96 } 97 catch (DecoderException e) { 98 return new byte[0]; 100 } 101 } 102 103 public Object createString(String cdata) 104 { 105 return cdata; 106 } 107 } 108 | Popular Tags |