KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > parser > StringParser


1 package prefuse.data.parser;
2
3 /**
4  * DataParser instance that "parses" a String value from a text string, this
5  * is the default fallback parser, which simply returns the string value
6  * to be parsed.
7  *
8  * @author <a HREF="http://jheer.org">jeffrey heer</a>
9  */

10 public class StringParser implements DataParser {
11     
12     /**
13      * Returns String.class.
14      * @see prefuse.data.parser.DataParser#getType()
15      */

16     public Class JavaDoc getType() {
17         return String JavaDoc.class;
18     }
19     
20     /**
21      * @see prefuse.data.parser.DataParser#format(java.lang.Object)
22      */

23     public String JavaDoc format(Object JavaDoc value) {
24         if ( value == null ) return null;
25         if ( !(value instanceof String JavaDoc) )
26             throw new IllegalArgumentException JavaDoc(
27               "This class can only format Objects of type String.");
28         return (String JavaDoc)value;
29     }
30     
31     /**
32      * @see prefuse.data.parser.DataParser#canParse(java.lang.String)
33      */

34     public boolean canParse(String JavaDoc text) {
35         return true;
36     }
37     
38     /**
39      * @see prefuse.data.parser.DataParser#parse(java.lang.String)
40      */

41     public Object JavaDoc parse(String JavaDoc text) throws DataParseException {
42         return text;
43     }
44     
45     /**
46      * Simply returns the input string.
47      * @param text the text string to "parse"
48      * @return the input text string
49      * @throws DataParseException never actually throws an exception
50      */

51     public String JavaDoc parseString(String JavaDoc text) throws DataParseException {
52         return text;
53     }
54     
55 } // end of class StringParser
56
Popular Tags