1 16 17 package org.apache.commons.beanutils.converters; 18 19 import java.io.File ; 20 21 import org.apache.commons.beanutils.ConversionException; 22 import org.apache.commons.beanutils.Converter; 23 24 34 public final class FileConverter implements Converter { 35 36 38 39 42 private Object defaultValue = null; 43 44 45 48 private boolean useDefault = true; 49 50 51 53 54 58 public FileConverter() { 59 60 this.defaultValue = null; 61 this.useDefault = false; 62 63 } 64 65 66 72 public FileConverter(Object defaultValue) { 73 74 this.defaultValue = defaultValue; 75 this.useDefault = true; 76 77 } 78 79 80 81 83 84 94 public Object convert(Class type, Object value) { 95 96 if (value == null) { 97 if (useDefault) { 98 return (defaultValue); 99 } else { 100 throw new ConversionException("No value specified"); 101 } 102 } 103 104 if (value instanceof File ) { 105 return (value); 106 } 107 108 return new File (value.toString()); 109 } 110 } 111 | Popular Tags |