001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.cache.jcache.interceptor; 018 019import java.io.Serializable; 020import java.lang.reflect.Method; 021 022import org.springframework.aop.support.StaticMethodMatcherPointcut; 023import org.springframework.lang.Nullable; 024import org.springframework.util.ObjectUtils; 025 026/** 027 * A Pointcut that matches if the underlying {@link JCacheOperationSource} 028 * has an operation for a given method. 029 * 030 * @author Stephane Nicoll 031 * @since 4.1 032 */ 033@SuppressWarnings("serial") 034public abstract class JCacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { 035 036 @Override 037 public boolean matches(Method method, Class<?> targetClass) { 038 JCacheOperationSource cas = getCacheOperationSource(); 039 return (cas != null && cas.getCacheOperation(method, targetClass) != null); 040 } 041 042 /** 043 * Obtain the underlying {@link JCacheOperationSource} (may be {@code null}). 044 * To be implemented by subclasses. 045 */ 046 @Nullable 047 protected abstract JCacheOperationSource getCacheOperationSource(); 048 049 050 @Override 051 public boolean equals(@Nullable Object other) { 052 if (this == other) { 053 return true; 054 } 055 if (!(other instanceof JCacheOperationSourcePointcut)) { 056 return false; 057 } 058 JCacheOperationSourcePointcut otherPc = (JCacheOperationSourcePointcut) other; 059 return ObjectUtils.nullSafeEquals(getCacheOperationSource(), otherPc.getCacheOperationSource()); 060 } 061 062 @Override 063 public int hashCode() { 064 return JCacheOperationSourcePointcut.class.hashCode(); 065 } 066 067 @Override 068 public String toString() { 069 return getClass().getName() + ": " + getCacheOperationSource(); 070 } 071 072}