Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Problem getting started

  1. #11
    Join Date
    Aug 2004
    Location
    India
    Posts
    16

    Default

    Quote Originally Posted by gpoirier
    I meant slower Execution. Using a regular expression is slower then just returning true. Might not be a huge difference, especially if the method's gonna do DB stuff, but there's no real gain for using RegexpMethodPointcutAdvisor when you want to match all methods. It also adds uneeded configuration code.
    I am sure about the RegexpMethodPointcutAdvisor , I have not been aware of regular expression as the word . Do you mean the following snippet
    return new MethodMatcher() {
    public boolean matches(Method arg0, Class arg1) {
    if (arg0.getName().indexOf("meth") == 0)
    return true;
    return false;
    }
    can be replaced by
    return new MethodMatcher() {
    public boolean matches(Method arg0, Class arg1) {
    //if (arg0.getName().indexOf("meth") == 0)
    return true;
    }
    Rgds
    Vicky

  2. #12
    Join Date
    Aug 2004
    Location
    India
    Posts
    16

    Default

    Quote Originally Posted by gpoirier
    I meant slower Execution. Using a regular expression is slower then just returning true. Might not be a huge difference, especially if the method's gonna do DB stuff, but there's no real gain for using RegexpMethodPointcutAdvisor when you want to match all methods. It also adds uneeded configuration code.
    Should not the Introduciton Advisor be used in the case of matching all the methods ?

    Rgds
    Vicky

  3. #13
    Join Date
    Aug 2004
    Posts
    6

    Default Solution

    Wow this is a great forum - thanks to everyone for the help and advice.

    It's working fine now

  4. #14

    Default

    Jeff,

    I'm glad we could help you. However, I also forgot a last thing that I'm not sure
    you were aware. For your MyBeforeAdvice to work on multiple target instances, your
    advice/advisor must be a prototype, otherwise the same advice instance will be used
    for each target, thus only on one of your targets would init be called.


    Vickyk,

    Quote Originally Posted by vickyk
    I am sure about the RegexpMethodPointcutAdvisor , I have not been aware of regular expression as the word . Do you mean the following snippet
    [...]
    can be replaced by
    [...]
    No, what I meant is replacing the XML code:

    Code:
    <bean id="beforeAdvice" class="MyBeforeAdvice"/>
    
    <bean id="beforeAdvisor"
    class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    <property name="advice"><ref local="beforeAdvice"/></property>
    <property name="pattern"><value>.*</value></property>
    </bean>
    
    <bean id="test1" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces"><value>TestBean</value></property>
    <property name="target"><bean class="TestBeanImpl"/></property>
    <property name="interceptorNames">
    <list>
    <value>beforeAdvisor</value>
    </list>
    </property>
    </bean>
    by
    Code:
    <bean id="beforeAdvice" class="MyBeforeAdvice"/>
    
    <bean id="test1" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces"><value>TestBean</value></property>
    <property name="target"><bean class="TestBeanImpl"/></property>
    <property name="interceptorNames">
    <list>
    <value>beforeAdvice</value>
    </list>
    </property>
    </bean>
    And previously, for the Advice/Advisor thing, I meant that instead of the
    MyAdvisor defined in Jeff's post, he could use the following code, with the
    new XML snippet I mentionned above. But I considering the name change from
    MyBeforeAdvice in the first post, to MyAdvisor in the second, I guess it's
    what he did at first, except with the XML snippet using the RegexpMethodPointcutAdvisor.

    Code:
    public class MyBeforeAdvice implements MethodBeforeAdvice &#123;
      private boolean initialised = false;
      
      public synchronized void before&#40;Method method, Object&#91;&#93; args, Object target&#41; throws Throwable &#123;
        if &#40;!initialised && target instanceof Initializable&#41; &#123;
          Initializable i = &#40;Initializable&#41;o;
          i.init&#40;&#41;;
          initialised = true;
        &#125;
      &#125;
    &#125;
    Quote Originally Posted by vickyk
    Should not the Introduciton Advisor be used in the case of matching all the methods ?
    The purpose of the Introduction Advisor is to add interfaces to a target, it isn't for interception of existing methods.

Similar Threads

  1. Replies: 1
    Last Post: Jul 5th, 2005, 03:48 AM
  2. Replies: 1
    Last Post: Jun 30th, 2005, 12:56 AM
  3. pagination and continuation problem in SWF
    By yfmoan in forum Web Flow
    Replies: 6
    Last Post: Jun 29th, 2005, 03:42 AM
  4. Replies: 0
    Last Post: Feb 16th, 2005, 01:45 PM
  5. Lazy Load Problem when Doing UnitTest
    By yoshi in forum Data
    Replies: 7
    Last Post: Sep 29th, 2004, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •