public static < T > void bindToCollection ( final Class < T > targetType , final Collection < T > collectionToPopulate , final CollectionDataBindingSource collectionBindingSource ) throws InstantiationException , IllegalAccessException { final GrailsApplication application = Holders . findApplication ( ) ; PersistentEntity entity = null ; if ( application != null ) { try { entity = application . getMappingContext ( ) . getPersistentEntity ( targetType . getClass ( ) . getName ( ) ) ; } catch ( GrailsConfigurationException e ) { //no-op } } final List < DataBindingSource > dataBindingSources = collectionBindingSource . getDataBindingSources ( ) ; for ( final DataBindingSource dataBindingSource : dataBindingSources ) { final T newObject = targetType . newInstance ( ) ; bindObjectToDomainInstance ( entity , newObject , dataBindingSource , getBindingIncludeList ( newObject ) , Collections . emptyList ( ) , null ) ; collectionToPopulate . add ( newObject ) ; } }
For each DataBindingSource provided by collectionBindingSource a new instance of targetType is created data binding is imposed on that instance with the DataBindingSource and the instance is added to the end of collectionToPopulate