1 16 17 18 package org.apache.commons.beanutils.converters; 19 20 21 import java.io.IOException ; 22 import java.io.StreamTokenizer ; 23 import java.io.StringReader ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import org.apache.commons.beanutils.ConversionException; 27 import org.apache.commons.beanutils.Converter; 28 29 30 31 49 50 public abstract class AbstractArrayConverter implements Converter { 51 52 53 55 56 59 protected Object defaultValue = null; 60 61 62 65 protected static String strings[] = new String [0]; 66 67 68 71 protected boolean useDefault = true; 72 73 74 76 77 88 public abstract Object convert(Class type, Object value); 89 90 91 93 94 113 protected List parseElements(String svalue) { 114 115 if (svalue == null) { 117 throw new NullPointerException (); 118 } 119 120 svalue = svalue.trim(); 122 if (svalue.startsWith("{") && svalue.endsWith("}")) { 123 svalue = svalue.substring(1, svalue.length() - 1); 124 } 125 126 try { 127 128 StreamTokenizer st = 130 new StreamTokenizer (new StringReader (svalue)); 131 st.whitespaceChars(',',','); st.ordinaryChars('0', '9'); st.ordinaryChars('.', '.'); 134 st.ordinaryChars('-', '-'); 135 st.wordChars('0', '9'); st.wordChars('.', '.'); 137 st.wordChars('-', '-'); 138 139 ArrayList list = new ArrayList (); 141 while (true) { 142 int ttype = st.nextToken(); 143 if ((ttype == StreamTokenizer.TT_WORD) || 144 (ttype > 0)) { 145 list.add(st.sval); 146 } else if (ttype == StreamTokenizer.TT_EOF) { 147 break; 148 } else { 149 throw new ConversionException 150 ("Encountered token of type " + ttype); 151 } 152 } 153 154 return (list); 156 157 } catch (IOException e) { 158 159 throw new ConversionException(e); 160 161 } 162 163 164 165 } 166 167 168 } 169 | Popular Tags |