/**
  * 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
  *
  * @param targetType The type of objects to create, must be a concrete class
  * @param collectionToPopulate A collection to populate with new instances of targetType
  * @param collectionBindingSource A CollectionDataBindingSource
  * @since 2.3
  */
 public static <T> void bindToCollection(
     final Class<T> targetType,
     final Collection<T> collectionToPopulate,
     final CollectionDataBindingSource collectionBindingSource)
     throws InstantiationException, IllegalAccessException {
   final GrailsApplication application = Holders.findApplication();
   GrailsDomainClass domain = null;
   if (application != null) {
     domain =
         (GrailsDomainClass)
             application.getArtefact(DomainClassArtefactHandler.TYPE, targetType.getName());
   }
   final List<DataBindingSource> dataBindingSources =
       collectionBindingSource.getDataBindingSources();
   for (final DataBindingSource dataBindingSource : dataBindingSources) {
     final T newObject = targetType.newInstance();
     bindObjectToDomainInstance(
         domain,
         newObject,
         dataBindingSource,
         getBindingIncludeList(newObject),
         Collections.emptyList(),
         null);
     collectionToPopulate.add(newObject);
   }
 }
 /**
  * Binds the given source object to the given target object performing type conversion if
  * necessary
  *
  * @param object The object to bind to
  * @param source The source object
  * @param include The list of properties to include
  * @param exclude The list of properties to exclude
  * @param filter The prefix to filter by
  * @return A BindingResult or null if it wasn't successful
  */
 public static BindingResult bindObjectToInstance(
     Object object, Object source, List include, List exclude, String filter) {
   if (include == null && exclude == null) {
     include = getBindingIncludeList(object);
   }
   GrailsApplication application = Holders.findApplication();
   GrailsDomainClass domain = null;
   if (application != null) {
     domain =
         (GrailsDomainClass)
             application.getArtefact(DomainClassArtefactHandler.TYPE, object.getClass().getName());
   }
   return bindObjectToDomainInstance(domain, object, source, include, exclude, filter);
 }
 /**
  * Return whether the constraint is valid for the owning class
  *
  * @return true if it is
  */
 public boolean isValid() {
   if (applicationContext.containsBean("sessionFactory")) {
     GrailsApplication grailsApplication =
         applicationContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
     GrailsDomainClass domainClass =
         (GrailsDomainClass)
             grailsApplication.getArtefact(
                 DomainClassArtefactHandler.TYPE, constraintOwningClass.getName());
     if (domainClass != null) {
       String mappingStrategy = domainClass.getMappingStrategy();
       return mappingStrategy.equals(GrailsDomainClass.GORM)
           || mappingStrategy.equals(AbstractGrailsHibernateDomainClass.HIBERNATE);
     }
   }
   return false;
 }