Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.support;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.springframework.aop.MethodMatcher;
/**
* Static methods useful for composing MethodMatchers. A MethodMatcher may be
* evaluated statically (based on method and target class) or need further
* evaluation dynamically (based on arguments at the time of method invocation).
*
* @author Rod Johnson
* @since 11.11.2003
*/
public abstract class MethodMatchers {
public static MethodMatcher union(MethodMatcher a, MethodMatcher b) {
return new UnionMethodMatcher(a, b);
}
public static MethodMatcher intersection(MethodMatcher a, MethodMatcher b) {
return new IntersectionMethodMatcher(a, b);
}
private static class UnionMethodMatcher implements MethodMatcher, Serializable {
private MethodMatcher a;
private MethodMatcher b;
private UnionMethodMatcher(MethodMatcher a, MethodMatcher b) {
this.a = a;
this.b = b;
}
public boolean matches(Method method, Class targetClass) {
return a.matches(method, targetClass) || b.matches(method, targetClass);
}
public boolean isRuntime() {
return a.isRuntime() || b.isRuntime();
}
public boolean matches(Method method, Class targetClass, Object[] args) {
return a.matches(method, targetClass, args) || b.matches(method, targetClass, args);
}
}
private static class IntersectionMethodMatcher implements MethodMatcher, Serializable {
private MethodMatcher a;
private MethodMatcher b;
private IntersectionMethodMatcher(MethodMatcher a, MethodMatcher b) {
this.a = a;
this.b = b;
}
public boolean matches(Method method, Class targetClass) {
return a.matches(method, targetClass) && b.matches(method, targetClass);
}
public boolean isRuntime() {
return a.isRuntime() || b.isRuntime();
}
public boolean matches(Method method, Class targetClass, Object[] args) {
// Because a dynamic intersection may be composed of a static and dynamic part,
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
// it will probably be an unsupported operation.
boolean aMatches = a.isRuntime() ? a.matches(method, targetClass, args) : a.matches(method, targetClass);
boolean bMatches = b.isRuntime() ? b.matches(method, targetClass, args) : b.matches(method, targetClass);
return aMatches && bMatches;
}
}
}