| java.lang.Object java.beans.PropertyEditorSupport org.springframework.beans.propertyeditors.CustomCollectionEditor
CustomCollectionEditor | public class CustomCollectionEditor extends PropertyEditorSupport (Code) | | Property editor for Collections, converting any source Collection
to a given target Collection type.
By default registered for Set, SortedSet and List,
to automatically convert any given Collection to one of those
target types if the type does not match the target property.
author: Juergen Hoeller since: 1.1.3 See Also: java.util.Collection See Also: java.util.Set See Also: java.util.SortedSet See Also: java.util.List |
Constructor Summary | |
public | CustomCollectionEditor(Class collectionType) Create a new CustomCollectionEditor for the given target type,
keeping an incoming null as-is. | public | CustomCollectionEditor(Class collectionType, boolean nullAsEmptyCollection) Create a new CustomCollectionEditor for the given target type. |
Method Summary | |
protected boolean | alwaysCreateNewCollection() Return whether to always create a new Collection,
even if the type of the passed-in Collection already matches. | protected Object | convertElement(Object element) Hook to convert each encountered Collection/array element.
The default implementation simply returns the passed-in element as-is.
Can be overridden to perform conversion of certain elements,
for example String to Integer if a String array comes in and
should be converted to a Set of Integer objects.
Only called if actually creating a new Collection!
This is by default not the case if the type of the passed-in Collection
already matches. | protected Collection | createCollection(Class collectionType, int initialCapacity) Create a Collection of the given type, with the given
initial capacity (if supported by the Collection type). | public String | getAsText() This implementation returns null to indicate that
there is no appropriate text representation. | public void | setAsText(String text) Convert the given text value to a Collection with a single element. | public void | setValue(Object value) Convert the given value to a Collection of the target type. |
CustomCollectionEditor | public CustomCollectionEditor(Class collectionType, boolean nullAsEmptyCollection)(Code) | | Create a new CustomCollectionEditor for the given target type.
If the incoming value is of the given type, it will be used as-is.
If it is a different Collection type or an array, it will be converted
to a default implementation of the given Collection type.
If the value is anything else, a target Collection with that single
value will be created.
The default Collection implementations are: ArrayList for List,
TreeSet for SortedSet, and LinkedHashSet or HashSet for Set.
Parameters: collectionType - the target type, which needs to be asub-interface of Collection or a concrete Collection class Parameters: nullAsEmptyCollection - whether to convert an incoming null value to an empty Collection (of the appropriate type) See Also: java.util.Collection See Also: java.util.ArrayList See Also: java.util.TreeSet See Also: org.springframework.core.CollectionFactory.createLinkedSetIfPossible |
alwaysCreateNewCollection | protected boolean alwaysCreateNewCollection()(Code) | | Return whether to always create a new Collection,
even if the type of the passed-in Collection already matches.
Default is "false"; can be overridden to enforce creation of a
new Collection, for example to convert elements in any case.
See Also: CustomCollectionEditor.convertElement |
convertElement | protected Object convertElement(Object element)(Code) | | Hook to convert each encountered Collection/array element.
The default implementation simply returns the passed-in element as-is.
Can be overridden to perform conversion of certain elements,
for example String to Integer if a String array comes in and
should be converted to a Set of Integer objects.
Only called if actually creating a new Collection!
This is by default not the case if the type of the passed-in Collection
already matches. Override
CustomCollectionEditor.alwaysCreateNewCollection() to
enforce creating a new Collection in every case.
Parameters: element - the source element the element to be used in the target Collection See Also: CustomCollectionEditor.alwaysCreateNewCollection() |
createCollection | protected Collection createCollection(Class collectionType, int initialCapacity)(Code) | | Create a Collection of the given type, with the given
initial capacity (if supported by the Collection type).
Parameters: collectionType - a sub-interface of Collection Parameters: initialCapacity - the initial capacity the new Collection instance |
getAsText | public String getAsText()(Code) | | This implementation returns null to indicate that
there is no appropriate text representation.
|
setValue | public void setValue(Object value)(Code) | | Convert the given value to a Collection of the target type.
|
|
|