Hi Brian, 

well, yes.

I want to stick with the advised classes, as I want aspects to be 
triggered as expected. 

The original implementation in AbstractStepsFactory does not discover 
proxy advised classes:
   ...
        for (Method method : ((Class<?>) type).getMethods()) {
                for (Annotation annotation : method.getAnnotations()) {
...
method.getAnnotations() returns empty array for methods from proxied 
classes. 

So I implemented a quick hack like
    protected boolean hasAnnotatedMethods(final Type type)
    {
        if (type instanceof Class<?>)
        {
            Class<?> target = (Class<?>) type;
            while (target != null)
            {
                for (Method method : target.getMethods())
                {
                    // using spring's helper class to lookup 
annotations...
                    for (Annotation annotation : AnnotationUtils.
getAnnotations(method))
                    {
                        if 
(annotation.annotationType().getName().startsWith(
                            "org.jbehave.core.annotations"))
                        {
                            return true;
                        }
                    }
                }
                // not found? try super class!
                target = target.getSuperclass();
            }
        }
        return false;
    }

which inspects the superclasses too and therefore the proxied classes get 
added to the list of steps. 
BTW, your unwrap-method looks far more elegant :-)

But: 

As they are still wrapped into a proxy, the step matching logic in 
StepCandidate and Step class won't succeed.  :-( 
method.isAnnotationPresent(...) won't work. 
And maybe there are even more places in JBehave code where the method 
matching wouldn't work then. 

So for now, I'll give aspect weaving with AspectJ a try. 
I'll let you know if that works... 

regards



Mit freundlichen Grüßen

Christian Zulehner
Im Auftrag der Porsche Informatik GmbH


[email protected]

Porsche Informatik Gesellschaft m.b.H. | A – 5101 Bergheim | 
Handelszentrum 7 
Sitz: Salzburg | FN 72830 d / Landesgericht Salzburg | DVR 88439 | UID ATU 
36773309
http://www.porscheinformatik.at/



Von:    "Brian Repko" <[email protected]>
An:     [email protected]
Datum:  21.11.2011 23:25
Betreff:        Re: [jbehave-user] Annotated methods and aspect 
orientation...



 
Christian,
 
Are you looking to do something like this...
 
public Object unwrap(Object o) {
  Object result = o;
  if (Advised.class.isInstance(o)) {
    try { ((Advised)o).getTargetSource().getTarget();
      result =
    } catch (Exception e) {
      result = o;
    }
  }
  return result;
}
 
...within the process of turning your CandidateSteps into Steps?  I think 
that this would be doable
as an extension to the SpringStepsFactory but its been a while since I've 
been in the JBehave code
as to know where that is needed.
 
You want the parsing to use the unwrapped object but the actual usage to 
use the wrapped object.
Do I have that correct?
 
Brian
 
----- Original message -----
From: "Mauro Talevi" <[email protected]>
To: [email protected]
Date: Mon, 21 Nov 2011 20:55:44 +0100
Subject: Re: [jbehave-user] Annotated methods and aspect orientation...
 
Yes, decoupling AOP from the DI is a good idea.

Sounds like we could provide an extension module to support AOP.

I would suggest creating a simple example that reproduces the problem and 
shows what you're trying to do.

Cheers

On 21/11/2011 16:45, Christian Zulehner wrote: 
Hi, 

after some more investigation, I skipped hope for a quick fix... :-( 

Changing e.g. the SpringStepsFactory fixes only the step creation, but NOT 
the handling/matching logic. 
So this would need even more stuff  to be fixed/changed. 
And thinking of unspecified behaviour when overriding method based 
annotations, 
I guess this needs more conceptual work to be done, before implementing 
some quick hacks...  :-(

I guess I'll give the AspectJ code weaving a try, instead of using 
Spring-AOP proxies... 




Mit freundlichen Grüßen

Christian Zulehner
Im Auftrag der Porsche Informatik GmbH


[email protected]

Porsche Informatik Gesellschaft m.b.H. | A – 5101 Bergheim | 
Handelszentrum 7
Sitz: Salzburg | FN 72830 d / Landesgericht Salzburg | DVR 88439 | UID ATU 
36773309
http://www.porscheinformatik.at/



Von:        Mauro Talevi <[email protected]>
An:        [email protected]
Datum:        21.11.2011 14:36
Betreff:        Re: [jbehave-user] Annotated methods and aspect 
orientation...



Hi Christian,

aop has not been a use case considered so far, so it may well be that
it requires some updates to get it working.

A Jira issue detailing the problem and a patch for it would be most
welcome.

Ideally, you should add both a unit test that reproduces the problem
(in core if it affects AbstractStepsFactory) and an example (e.g. in
trader-spring) that we can use as integration test.

Cheers




On Mon Nov 21 14:32:03 2011, Christian Zulehner wrote:
> Hi all,
>
> currently I'm struggling to get JBehave to work together with aspect
> orientated programming (AspectJ) and Spring.
>
> The problem seems to be, that the hasAnnotatedMethodsin
> AbstractStepsFactoryis not able to discover methods, which are already
> wrapped into an aspect proxy, e.g. logging, exception handling..
>
> IIRC @Inherited only works for annotated types, adding this to the
> @Give, @When, ... won't change anything.
> So, my guess is to update the implementaiton of hasAnnotatedMethodsto
> take super-methods into account...
>
> Did anyone had a similar problem?
> Is this a known issue?
> If so, should I file a Jira entry? (Together with a fix?)
>
>
>
> Mit freundlichen Grüßen
>
> Christian Zulehner
> Im Auftrag der Porsche Informatik GmbH
>
> Porsche Informatik Gesellschaft m.b.H. | A – 5101 Bergheim |
> Handelszentrum 7
> Sitz: Salzburg | FN 72830 d / Landesgericht Salzburg | DVR 88439 | UID
> ATU 36773309
> _http://www.porscheinformatik.at/_



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


 
 
---
Brian Repko
LearnThinkCode, Inc.
email: [email protected]
phone: +1 612 229 6779

Reply via email to