Example usage for org.aspectj.weaver.tools PointcutExpression matchesMethodExecution

List of usage examples for org.aspectj.weaver.tools PointcutExpression matchesMethodExecution

Introduction

In this page you can find the example usage for org.aspectj.weaver.tools PointcutExpression matchesMethodExecution.

Prototype

ShadowMatch matchesMethodExecution(Method aMethod);

Source Link

Document

Determine whether or not this pointcut matches the execution of a given method.

Usage

From source file:org.gaixie.micrite.security.filter.AspectJMethodMatcher.java

License:Open Source License

public boolean match(String pattern, Method method) {
    pattern = "execution(" + pattern + ")";
    PointcutExpression pe = pointcutParser.parsePointcutExpression(pattern);
    ShadowMatch match = pe.matchesMethodExecution(method);
    return match.alwaysMatches();
}

From source file:org.springframework.aop.aspectj.AspectJExpressionPointcut.java

License:Apache License

private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
    // Avoid lock contention for known Methods through concurrent access...
    ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
    if (shadowMatch == null) {
        synchronized (this.shadowMatchCache) {
            // Not found - now check again with full lock...
            PointcutExpression fallbackExpression = null;
            Method methodToMatch = targetMethod;
            shadowMatch = this.shadowMatchCache.get(targetMethod);
            if (shadowMatch == null) {
                try {
                    shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
                } catch (ReflectionWorldException ex) {
                    // Failed to introspect target method, probably because it has been loaded
                    // in a special ClassLoader. Let's try the declaring ClassLoader instead...
                    try {
                        fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
                        if (fallbackExpression != null) {
                            shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
                        }//from  w w w  .  j a  v  a 2s.c o  m
                    } catch (ReflectionWorldException ex2) {
                        fallbackExpression = null;
                    }
                }
                if (shadowMatch == null && targetMethod != originalMethod) {
                    methodToMatch = originalMethod;
                    try {
                        shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
                    } catch (ReflectionWorldException ex3) {
                        // Could neither introspect the target class nor the proxy class ->
                        // let's try the original method's declaring class before we give up...
                        try {
                            fallbackExpression = getFallbackPointcutExpression(
                                    methodToMatch.getDeclaringClass());
                            if (fallbackExpression != null) {
                                shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
                            }
                        } catch (ReflectionWorldException ex4) {
                            fallbackExpression = null;
                        }
                    }
                }
                if (shadowMatch == null) {
                    shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
                } else if (shadowMatch.maybeMatches() && fallbackExpression != null) {
                    shadowMatch = new DefensiveShadowMatch(shadowMatch,
                            fallbackExpression.matchesMethodExecution(methodToMatch));
                }
                this.shadowMatchCache.put(targetMethod, shadowMatch);
            }
        }
    }
    return shadowMatch;
}