|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.beans.PropertyEditorSupport org.springframework.beans.propertyeditors.CustomMapEditor
public class CustomMapEditor
Property editor for Maps, converting any source Map to a given target Map type.
Map
,
SortedMap
Constructor Summary | |
---|---|
CustomMapEditor(Class mapType)
Create a new CustomMapEditor for the given target type, keeping an incoming null as-is. |
|
CustomMapEditor(Class mapType,
boolean nullAsEmptyMap)
Create a new CustomMapEditor for the given target type. |
Method Summary | |
---|---|
protected boolean |
alwaysCreateNewMap()
Return whether to always create a new Map, even if the type of the passed-in Map already matches. |
protected Object |
convertKey(Object key)
Hook to convert each encountered Map key. |
protected Object |
convertValue(Object value)
Hook to convert each encountered Map value. |
protected Map |
createMap(Class mapType,
int initialCapacity)
Create a Map of the given type, with the given initial capacity (if supported by the Map type). |
String |
getAsText()
This implementation returns null to indicate that
there is no appropriate text representation. |
void |
setAsText(String text)
Convert the given text value to a Map with a single element. |
void |
setValue(Object value)
Convert the given value to a Map of the target type. |
Methods inherited from class java.beans.PropertyEditorSupport |
---|
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, supportsCustomEditor |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CustomMapEditor(Class mapType)
null
as-is.
mapType
- the target type, which needs to be a
sub-interface of Map or a concrete Map classMap
,
HashMap
,
TreeMap
,
CollectionFactory.createLinkedMapIfPossible(int)
public CustomMapEditor(Class mapType, boolean nullAsEmptyMap)
If the incoming value is of the given type, it will be used as-is. If it is a different Map type or an array, it will be converted to a default implementation of the given Map type. If the value is anything else, a target Map with that single value will be created.
The default Map implementations are: ArrayList for List, TreeSet for SortedSet, and LinkedHashSet or HashSet for Set.
mapType
- the target type, which needs to be a
sub-interface of Map or a concrete Map classnullAsEmptyMap
- ap whether to convert an incoming null
value to an empty Map (of the appropriate type)Map
,
HashMap
,
TreeMap
,
CollectionFactory.createLinkedMapIfPossible(int)
Method Detail |
---|
public void setAsText(String text) throws IllegalArgumentException
setAsText
in interface PropertyEditor
setAsText
in class PropertyEditorSupport
IllegalArgumentException
public void setValue(Object value)
setValue
in interface PropertyEditor
setValue
in class PropertyEditorSupport
protected Map createMap(Class mapType, int initialCapacity)
mapType
- a sub-interface of MapinitialCapacity
- the initial capacity
protected boolean alwaysCreateNewMap()
Default is "false"; can be overridden to enforce creation of a new Map, for example to convert elements in any case.
convertKey(java.lang.Object)
,
convertValue(java.lang.Object)
protected Object convertKey(Object key)
Can be overridden to perform conversion of certain keys, for example from String to Integer.
Only called if actually creating a new Map!
This is by default not the case if the type of the passed-in Map
already matches. Override alwaysCreateNewMap()
to
enforce creating a new Map in every case.
key
- the source key
alwaysCreateNewMap()
protected Object convertValue(Object value)
Can be overridden to perform conversion of certain values, for example from String to Integer.
Only called if actually creating a new Map!
This is by default not the case if the type of the passed-in Map
already matches. Override alwaysCreateNewMap()
to
enforce creating a new Map in every case.
value
- the source value
alwaysCreateNewMap()
public String getAsText()
null
to indicate that
there is no appropriate text representation.
getAsText
in interface PropertyEditor
getAsText
in class PropertyEditorSupport
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |