Package org.springframework.aop

Examples of org.springframework.aop.MethodMatcher


  public void testMatchExplicit() {
    String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";

    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);
    assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
  }
View Full Code Here


  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

  public void testMatchWithArgs() throws Exception {
    String expression = "execution(void org.springframework.tests.sample.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

   * @return a composable pointcut that builds on the original AspectJ expression pointcut
   * @see #getPointcut()
   */
  public final Pointcut buildSafePointcut() {
    Pointcut pc = getPointcut();
    MethodMatcher safeMethodMatcher = MethodMatchers.intersection(
        new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
    return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
  }
View Full Code Here

  public static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasIntroductions) {
    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 HashSet<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

         *  Classpath scanning based on java package pattern name, e.q. "com.blogspot.ostas.myapp"
         */
    @Override
    public void afterPropertiesSet() throws Exception {
        final Pointcut pointcut = (Pointcut) applicationContext.getBean(pointcutBeanName);
        final MethodMatcher methodMatcher = pointcut.getMethodMatcher();
        final List<Class> pojoClasses = adviceNotifier.getClassList();
        for(final Class pojoClass: pojoClasses){
                for(final Method method: pojoClass.getDeclaredMethods()){
                    if(Modifier.isPublic(method.getModifiers())){
                        if(methodMatcher.matches(method,pojoClass,method.getParameterTypes())){
                            if(LOGGER.isDebugEnabled()){
                                LOGGER.debug("method matches pointcut : "+method);
                            }
                            MethodInvocationStats emptyMethodInvocationStats = new MethodInvocationStats();
                            emptyMethodInvocationStats.setHits(new AtomicLong(-1));
View Full Code Here

    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

  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

    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

    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

TOP

Related Classes of org.springframework.aop.MethodMatcher

Copyright © 2018 www.massapicom. 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.