/**
  * Validates the specified {@link CacheOperation}.
  *
  * <p>Throws an {@link IllegalStateException} if the state of the operation is invalid. As there
  * might be multiple sources for default values, this ensure that the operation is in a proper
  * state before being returned.
  *
  * @param ae the annotated element of the cache operation
  * @param operation the {@link CacheOperation} to validate
  */
 private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) {
   if (StringUtils.hasText(operation.getKey())
       && StringUtils.hasText(operation.getKeyGenerator())) {
     throw new IllegalStateException(
         "Invalid cache annotation configuration on '"
             + ae.toString()
             + "'. Both 'key' and 'keyGenerator' attributes have been set. "
             + "These attributes are mutually exclusive: either set the SpEL expression used to"
             + "compute the key at runtime or set the name of the KeyGenerator bean to use.");
   }
   if (StringUtils.hasText(operation.getCacheManager())
       && StringUtils.hasText(operation.getCacheResolver())) {
     throw new IllegalStateException(
         "Invalid cache annotation configuration on '"
             + ae.toString()
             + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. "
             + "These attributes are mutually exclusive: the cache manager is used to configure a"
             + "default cache resolver if none is set. If a cache resolver is set, the cache manager"
             + "won't be used.");
   }
 }
 protected Collection<Cache> getCaches(CacheOperation operation) {
   Set<String> cacheNames = operation.getCacheNames();
   Collection<Cache> caches = new ArrayList<Cache>(cacheNames.size());
   for (String name : cacheNames) {
     Cache cache = getCacheManager().getCache(name);
     if (cache == null) {
       throw new IllegalArgumentException(
           "Cannot find cache named [" + name + "] for " + operation);
     }
     caches.add(cache);
   }
   return caches;
 }
    /**
     * Apply the defaults to the specified {@link CacheOperation}.
     *
     * @param operation the operation to update
     */
    public void applyDefault(CacheOperation operation) {
      if (operation.getCacheNames().isEmpty() && this.cacheNames != null) {
        operation.setCacheNames(this.cacheNames);
      }
      if (!StringUtils.hasText(operation.getKey())
          && !StringUtils.hasText(operation.getKeyGenerator())
          && StringUtils.hasText(this.keyGenerator)) {
        operation.setKeyGenerator(this.keyGenerator);
      }

      if (StringUtils.hasText(operation.getCacheManager())
          || StringUtils.hasText(operation.getCacheResolver())) {
        // One of these is set so we should not inherit anything
      } else if (StringUtils.hasText(this.cacheResolver)) {
        operation.setCacheResolver(this.cacheResolver);
      } else if (StringUtils.hasText(this.cacheManager)) {
        operation.setCacheManager(this.cacheManager);
      }
    }