1 package net.logAnalyzer.converters;
2
3 import net.logAnalyzer.handlers.ParsingException;
4
5 /***
6 * This class implements a converter used to parse or convert
7 * {@link java.lang.String}values.
8 *
9 * @author Karim REFEYTON
10 * @version 0.1
11 */
12 public class StringConverter extends LAConverter {
13
14 /***
15 * Constructs a new converter from a converter definition.
16 *
17 * @param definition
18 * Definition of the converter.
19 * @param literal
20 * Literal value identifying the converter.
21 */
22 public StringConverter(ConverterDefinition definition, String literal) {
23 super(definition, literal);
24 }
25
26 /***
27 * Returns the class {@link String}.
28 *
29 * @see LAConverter#getValueClass()
30 */
31 public Class getValueClass() {
32 return String.class;
33 }
34
35 /***
36 * Returns the value unmodified.
37 *
38 * @return The value unmodified.
39 * @see LAConverter#parse(String)
40 * @throws ParsingException
41 * If the value can't be parsed.
42 */
43 public Object parse(String value) throws ParsingException {
44 if (value == null) {
45 return "";
46 } else {
47 return value;
48 }
49 }
50
51 /***
52 * Returns a string representation of the value calling <tt>toString()</tt>.
53 *
54 * @param value
55 * Value to convert as String.
56 * @return String representation of the value.
57 * @see LAConverter#toString(Object)
58 */
59 public String toString(Object value) {
60 return value.toString();
61 }
62 }