Examples of MethodMatcher


Examples of org.springframework.aop.MethodMatcher

  public void testMatchWithTypePattern() throws Exception {
    String expression = "execution(* *..TestBean.*Age(..))";

    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();

    assertMatchesTestBeanClass(classFilter);

    // not currently testable in a reliable fashion
    //assertDoesNotMatchStringClass(classFilter);

    assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
    assertMatchesGetAge(methodMatcher);
    assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

  public void testMatchWithArgs() throws Exception {
    String expression = "execution(void org.springframework.beans.TestBean.setSomeNumber(Number)) && args(Double)";

    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();

    assertMatchesTestBeanClass(classFilter);

    // not currently testable in a reliable fashion
    //assertDoesNotMatchStringClass(classFilter);

    assertTrue("Should match with setSomeNumber with Double input",
        methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)}));
    assertFalse("Should not match setSomeNumber with Integer input",
        methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)}));
    assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null));
    assertTrue("Should be a runtime match", methodMatcher.isRuntime());
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

    ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", new Class[] { int.class });
    IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
  }

  public void testDefaultMatchesAll() throws Exception {
    MethodMatcher defaultMm = MethodMatcher.TRUE;
    assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
    assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

  public void testMethodMatcherTrueSerializable() throws Exception {
    assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
  }

  public void testSingle() throws Exception {
    MethodMatcher defaultMm = MethodMatcher.TRUE;
    assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
    assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
    defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get"));

    assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
    assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

    assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
  }

 
  public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
    MethodMatcher mm1 = MethodMatcher.TRUE;
    MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
    MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
    assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
    assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
    assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
    // Knock out dynamic part
    intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
    assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
    assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
    assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

    assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
    assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
  }
 
  public void testStaticMethodMatcherUnion() throws Exception {
    MethodMatcher getterMatcher = new StartsWithMatcher("get");
    MethodMatcher setterMatcher = new StartsWithMatcher("set");
    MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher);
   
    assertFalse("Union is a static matcher", union.isRuntime());
    assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
    assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
    assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class));

  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

                classes.add(clazz);
            }
        }

        final Pointcut pointcut = (Pointcut) applicationContext.getBean(pointcutBeanName);
        final MethodMatcher methodMatcher = pointcut.getMethodMatcher();
        for(final Class clazz : classes){
                for(final Method method: clazz.getDeclaredMethods()){
                    if(Modifier.isPublic(method.getModifiers())){
                        if(methodMatcher.matches(method, clazz,method.getParameterTypes())){
                            if(LOGGER.isDebugEnabled()){
                                LOGGER.debug("method matches pointcut : "+method);
                            }
                            MethodInvocationStats emptyMethodInvocationStats = new MethodInvocationStats();
                            emptyMethodInvocationStats.setHits(new AtomicLong(-1));
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

    Assert.notNull(pc, "Pointcut must not be null");
    if (!pc.getClassFilter().matches(targetClass)) {
      return false;
    }

    MethodMatcher methodMatcher = pc.getMethodMatcher();
    IntroductionAwareMethodMatcher introductionAwareMethodMatcher = null;
    if (methodMatcher instanceof IntroductionAwareMethodMatcher) {
      introductionAwareMethodMatcher = (IntroductionAwareMethodMatcher) methodMatcher;
    }

    Set<Class<?>> classes = new LinkedHashSet<Class<?>>(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
    classes.add(targetClass);
    for (Class<?> clazz : classes) {
      Method[] methods = clazz.getMethods();
      for (Method method : methods) {
        if ((introductionAwareMethodMatcher != null &&
            introductionAwareMethodMatcher.matches(method, targetClass, hasIntroductions)) ||
            methodMatcher.matches(method, targetClass)) {
          return true;
        }
      }
    }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

    if (pointcut == Pointcut.TRUE) {
      return true;
    }
    if (pointcut.getClassFilter().matches(targetClass)) {
      // Only check if it gets past first hurdle.
      MethodMatcher mm = pointcut.getMethodMatcher();
      if (mm.matches(method, targetClass)) {
        // We may need additional runtime (argument) check.
        return (!mm.isRuntime() || mm.matches(method, targetClass, args));
      }
    }
    return false;
  }
View Full Code Here

Examples of org.springframework.aop.MethodMatcher

      if (advisor instanceof PointcutAdvisor) {
        // Add it conditionally.
        PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
        if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
          MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
          MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
          if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
            if (mm.isRuntime()) {
              // Creating a new object instance in the getInterceptors() method
              // isn't a problem as we normally cache created chains.
              for (MethodInterceptor interceptor : interceptors) {
                interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
              }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.