Purple Code

com.purpletech.util
Class StringConverter

java.lang.Object
  |
  +--com.purpletech.util.StringConverter

public class StringConverter
extends java.lang.Object

Converts a String into a given object type (and back again). Supports factories, so if you have a custom type, you can add it, e.g.

        stringconverter.setFactory(Foo.class,
                new StringConverter.Factory() {
                     public Object fromString(String value) {
                         return new Foo(value);
                     }
                     public String toString(Object obj) {
                         return ((Foo)obj).getStringValue();
                     }
                 });
 

Author:
Alex Chaffee (alex@jguru.com)

Nested Class Summary
static class StringConverter.DateFactory
           
static class StringConverter.Factory
           
static class StringConverter.GenderFactory
           
 
Field Summary
protected static java.lang.Class[] argString
           
static java.text.DateFormat dateFormat
           
protected  java.util.Map factories
           
 
Constructor Summary
StringConverter()
           
 
Method Summary
 java.lang.Object fromString(java.lang.String string, java.lang.Object type)
           
 StringConverter.Factory getFactory(java.lang.Object type)
           
static void printParseException(java.io.PrintWriter out, java.lang.String s, java.text.ParseException p)
           
 void setFactory(java.lang.Object type, StringConverter.Factory factory)
           
 java.lang.String toString(java.lang.Object object)
           
 java.lang.String toString(java.lang.Object object, java.lang.Object type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dateFormat

public static java.text.DateFormat dateFormat

factories

protected java.util.Map factories

argString

protected static java.lang.Class[] argString
Constructor Detail

StringConverter

public StringConverter()
Method Detail

setFactory

public void setFactory(java.lang.Object type,
                       StringConverter.Factory factory)

getFactory

public StringConverter.Factory getFactory(java.lang.Object type)

printParseException

public static void printParseException(java.io.PrintWriter out,
                                       java.lang.String s,
                                       java.text.ParseException p)

fromString

public java.lang.Object fromString(java.lang.String string,
                                   java.lang.Object type)
                            throws java.text.ParseException
Parameters:
string - the string to parse
type - the type of parsing to be done (usually the class object, although it could be a string key for, e.g., dates)
java.text.ParseException

toString

public java.lang.String toString(java.lang.Object object)

toString

public java.lang.String toString(java.lang.Object object,
                                 java.lang.Object type)

Documentation generated March 5 2003