org.springframework.beans.propertyeditors
Class CustomCollectionEditor

java.lang.Object
  extended byjava.beans.PropertyEditorSupport
      extended byorg.springframework.beans.propertyeditors.CustomCollectionEditor
All Implemented Interfaces:
PropertyEditor

public class CustomCollectionEditor
extends PropertyEditorSupport

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.

Since:
1.1.3
Author:
Juergen Hoeller
See Also:
Collection, Set, SortedSet, List

Constructor Summary
CustomCollectionEditor(Class collectionType)
          Create a new CustomCollectionEditor for the given target type.
 
Method Summary
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).
 void setAsText(String text)
          Convert the given text value to a Collection with a single element.
 void setValue(Object value)
          Convert the given value to a Collection of the target type.
 
Methods inherited from class java.beans.PropertyEditorSupport
addPropertyChangeListener, firePropertyChange, getAsText, getCustomEditor, getJavaInitializationString, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, supportsCustomEditor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomCollectionEditor

public CustomCollectionEditor(Class collectionType)
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 a sub-interface of Collection
See Also:
Collection, ArrayList, TreeSet, CollectionFactory.createLinkedSetIfPossible(int)
Method Detail

setAsText

public void setAsText(String text)
               throws IllegalArgumentException
Convert the given text value to a Collection with a single element.

Throws:
IllegalArgumentException

setValue

public void setValue(Object value)
Convert the given value to a Collection of the target type.


createCollection

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).

Parameters:
collectionType - a sub-interface of Collection
initialCapacity - the initial capacity
Returns:
the new Collection instance


Copyright (C) 2003-2004 The Spring Framework Project.