1 3 package jodd.typeconverter; 4 5 11 public class StringArrayConverter implements TypeConverter { 12 13 public static String [] valueOf(Object value) { 14 15 if (value == null) { 16 return null; 17 } 18 Class type = value.getClass(); 19 if (type.isArray() == false) { 20 return new String [] { value.toString() }; 21 } 22 23 if (type == String [].class) { 25 return (String []) value; 26 } 27 28 Object [] values; 29 try { 30 values = (Object []) value; 31 } catch (ClassCastException ccex) { 32 throw new TypeConversionException(ccex); 33 } 34 35 String [] result = new String [values.length]; 36 for (int i = 0; i < values.length; i++) { 37 if (values[i] != null) { 38 result[i] = values[i].toString(); 39 } 40 } 41 return result; 42 } 43 44 public Object convert(Object value) { 45 return valueOf(value); 46 } 47 48 } 49 | Popular Tags |