org.springframework.beans.propertyeditors
Class CharacterEditor

java.lang.Object
  extended by java.beans.PropertyEditorSupport
      extended by org.springframework.beans.propertyeditors.CharacterEditor
All Implemented Interfaces:
java.beans.PropertyEditor

public class CharacterEditor
extends java.beans.PropertyEditorSupport

Editor for a Character, to populate a property of type Character or char from a String value.

Note that the JDK does not contain a default property editor for char! BeanWrapperImpl will register this editor by default.

Also supports conversion from a Unicode character sequence; e.g. u0041 ('A').

Since:
1.2
Author:
Juergen Hoeller, Rob Harrop, Rick Evans
See Also:
Character, BeanWrapperImpl

Field Summary
private  boolean allowEmpty
           
private static int UNICODE_LENGTH
          The length of a Unicode character sequence.
private static java.lang.String UNICODE_PREFIX
          The prefix that identifies a string as being a Unicode character sequence.
 
Constructor Summary
CharacterEditor(boolean allowEmpty)
          Create a new CharacterEditor instance.
 
Method Summary
 java.lang.String getAsText()
           
private  boolean isUnicodeCharacterSequence(java.lang.String sequence)
           
 void setAsText(java.lang.String text)
           
private  void setAsUnicode(java.lang.String text)
           
 
Methods inherited from class java.beans.PropertyEditorSupport
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNICODE_PREFIX

private static final java.lang.String UNICODE_PREFIX
The prefix that identifies a string as being a Unicode character sequence.

See Also:
Constant Field Values

UNICODE_LENGTH

private static final int UNICODE_LENGTH
The length of a Unicode character sequence.

See Also:
Constant Field Values

allowEmpty

private final boolean allowEmpty
Constructor Detail

CharacterEditor

public CharacterEditor(boolean allowEmpty)
Create a new CharacterEditor instance.

The "allowEmpty" parameter controls whether an empty String is to be allowed in parsing, i.e. be interpreted as the null value when text is being converted. If false, an IllegalArgumentException will be thrown at that time.

Parameters:
allowEmpty - if empty strings are to be allowed
Method Detail

setAsText

public void setAsText(java.lang.String text)
               throws java.lang.IllegalArgumentException
Specified by:
setAsText in interface java.beans.PropertyEditor
Overrides:
setAsText in class java.beans.PropertyEditorSupport
Throws:
java.lang.IllegalArgumentException

getAsText

public java.lang.String getAsText()
Specified by:
getAsText in interface java.beans.PropertyEditor
Overrides:
getAsText in class java.beans.PropertyEditorSupport

isUnicodeCharacterSequence

private boolean isUnicodeCharacterSequence(java.lang.String sequence)

setAsUnicode

private void setAsUnicode(java.lang.String text)