Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../../img/srcFileCovDistChart1.png 26% of files have more coverage
24   120   10   12
8   46   0,42   2
2     5  
1    
2,9% of code in this file is excluded from these metrics.
 
  ArrayConverter       Line # 38 24 10 5,9% 0.05882353
 
  (1)
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10    * This library is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this library; if not, write to the Free Software
17    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18    *
19    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23   
24    package net.smartlab.web.bean;
25   
26    import java.io.IOException;
27    import java.io.StreamTokenizer;
28    import java.io.StringReader;
29    import java.util.ArrayList;
30    import java.util.List;
31    import java.util.Locale;
32   
33    /**
34    * TODO documentation
35    *
36    * @author rlogiacco
37    */
 
38    public abstract class ArrayConverter extends Converter {
39   
40    /**
41    * TODO documentation
42    */
43    protected final static String model[] = new String[0];
44   
45    /**
46    * TODO documentation
47    */
 
48  9 toggle public ArrayConverter() {
49  9 super();
50    }
51   
52    /**
53    * <p>
54    * Parse an incoming String of the form similar to an array initializer in
55    * the Java language into a <code>List</code> with individual Strings for each
56    * element, according to the following rules.
57    * </p>
58    * <ul>
59    * <li>The string must have matching '{' and '}' delimiters around a
60    * comma-delimited list of values.</li>
61    * <li>Whitespace before and after each element is stripped.</li>
62    * <li>If an element is itself delimited by matching single or double
63    * quotes, the usual rules for interpreting a quoted String apply.</li>
64    * </ul>
65    *
66    * @param value String value to be parsed
67    * @return a list of String elements
68    * @throws ConversionException if the syntax of <code>svalue</code> is not
69    * syntactically valid
70    * @throws NullPointerException if <code>svalue</code> is
71    * <code>null</code>
72    */
 
73  0 toggle protected List parseElements(String value) throws ConversionException {
74    // Validate the passed argument
75  0 if (value == null) {
76  0 throw new NullPointerException();
77    }
78   
79    // Trim any matching '{' and '}' delimiters
80  0 value = value.trim();
81  0 if (value.startsWith("{") && value.endsWith("}")) {
82  0 value = value.substring(1, value.length() - 1);
83    }
84  0 try {
85    // Set up a StreamTokenizer on the characters in this String
86  0 StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(value));
87  0 tokenizer.whitespaceChars(',', ','); // Commas are delimiters
88  0 tokenizer.ordinaryChars('0', '9'); // Needed to turn off numeric flag
89  0 tokenizer.ordinaryChars('.', '.');
90  0 tokenizer.ordinaryChars('-', '-');
91  0 tokenizer.wordChars('0', '9'); // Needed to make part of tokens
92  0 tokenizer.wordChars('.', '.');
93  0 tokenizer.wordChars('-', '-');
94   
95    // Split comma-delimited tokens into a List
96  0 ArrayList list = new ArrayList();
97  0 while (true) {
98  0 int type = tokenizer.nextToken();
99  0 if ((type == StreamTokenizer.TT_WORD) || (type > 0)) {
100  0 list.add(tokenizer.sval);
101  0 } else if (type == StreamTokenizer.TT_EOF) {
102  0 break;
103    } else {
104  0 throw new ConversionException("Encountered token of type " + type);
105    }
106    }
107    // Return the completed list
108  0 return list;
109   
110    } catch (IOException ioe) {
111    throw new ConversionException(ioe);
112    }
113    }
114   
115    /**
116    * @see net.smartlab.web.bean.Converter#convert(java.lang.Class,
117    * java.lang.Object, java.util.Locale)
118    */
119    public abstract Object convert(Class type, Object value, Locale locale) throws ConversionException;
120    }