org.sonatype.gshell.util.converter
Class ConverterSupport

java.lang.Object
  extended by java.beans.PropertyEditorSupport
      extended by org.sonatype.gshell.util.converter.ConverterSupport
All Implemented Interfaces:
PropertyEditor, Converter
Direct Known Subclasses:
BigDecimalConverter, BigIntegerConverter, BooleanConverter, ByteConverter, CharacterConverter, ClassConverter, CollectionConverterSupport, DateConverter, DoubleConverter, EnumConverter, FileConverter, FloatConverter, Inet4AddressConverter, Inet6AddressConverter, InetAddressConverter, IntegerConverter, LongConverter, MapConverterSupport, ObjectNameConverter, PatternConverter, ShortConverter, StringConverter, UriConverter, UrlConverter

public abstract class ConverterSupport
extends PropertyEditorSupport
implements Converter

Support for Converter implementations.

Since:
2.0

Constructor Summary
protected ConverterSupport(Class type)
           
 
Method Summary
protected abstract  Object convertToObject(String text)
          Converts the supplied text in to an instance of the editor type.
protected  String convertToString(Object value)
          Converts the supplied object to text.
 String getAsText()
           
 Class getType()
          Gets the the type of object supported by this converter.
 Object getValue()
           
 void setAsText(String text)
           
 void setValue(Object value)
           
 Object toObject(String text)
          Converts the supplied text in to an instance of the editor type.
 String toString(Object value)
          Converts the supplied object to text.
 
Methods inherited from class java.beans.PropertyEditorSupport
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, isPaintable, paintValue, removePropertyChangeListener, setSource, supportsCustomEditor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.PropertyEditor
addPropertyChangeListener, getCustomEditor, getJavaInitializationString, getTags, isPaintable, paintValue, removePropertyChangeListener, supportsCustomEditor
 

Constructor Detail

ConverterSupport

protected ConverterSupport(Class type)
Method Detail

getType

public final Class getType()
Description copied from interface: Converter
Gets the the type of object supported by this converter.

Specified by:
getType in interface Converter
Returns:
The type supported by this converter.

getAsText

public final String getAsText()
Specified by:
getAsText in interface PropertyEditor
Overrides:
getAsText in class PropertyEditorSupport

setAsText

public final void setAsText(String text)
Specified by:
setAsText in interface PropertyEditor
Overrides:
setAsText in class PropertyEditorSupport

getValue

public final Object getValue()
Specified by:
getValue in interface PropertyEditor
Overrides:
getValue in class PropertyEditorSupport

setValue

public final void setValue(Object value)
Specified by:
setValue in interface PropertyEditor
Overrides:
setValue in class PropertyEditorSupport

toString

public final String toString(Object value)
Description copied from interface: Converter
Converts the supplied object to text. If value is null, null will be returned. If value is not an instance of the this converter's type, a ConversionException will be thrown.

Specified by:
toString in interface Converter
Parameters:
value - an instance of the editor type
Returns:
the text equivalent of the value

toObject

public final Object toObject(String text)
Description copied from interface: Converter
Converts the supplied text in to an instance of the editor type. If text is null, null will be returned.

Specified by:
toObject in interface Converter
Parameters:
text - the text to convertToObject
Returns:
an instance of the editor type

convertToString

protected String convertToString(Object value)
Converts the supplied object to text. The supplied object will always be an instance of the editor type, and specifically will never be null or a String (unless this is the String editor).

Parameters:
value - an instance of the editor type
Returns:
the text equivalent of the value

convertToObject

protected abstract Object convertToObject(String text)
                                   throws Exception
Converts the supplied text in to an instance of the editor type. The text will never be null, and trim() will already have been called.

Parameters:
text - The text to convertToObject
Returns:
An instance of the converted type
Throws:
Exception - Conversion failed


Copyright © 2008-2011 Sonatype. All Rights Reserved.