Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: Accessing original instance from introduction

Strangely enough this almost equivalent aj definition (below) works
fine. AFAICS the only difference is the @this(Injected)  pointcut
clause in the after deserialization advice. Of course, I didn't
include it in the annotated-style example because it wouldn't match
any join point (remember that even the more permissive *
*.readResolve() just matched DeserializationSupportImpl.readResolve(),
but never (@Injected *).readResolve()). I think there is a subtle
semantic difference between both versions, maybe this is a bug, I
don't know. What do you think?

Regards
-Carlos

public aspect InjectorAspect {

    after(Object injected) :
        execution(Object DeserializationSupport+.readResolve() throws
ObjectStreamException) &&
        @this(Injected) && this(injected) {
        injector.injectAll(injected);
    }

    declare parents: @Injected Serializable+ implements DeserializationSupport;

    interface DeserializationSupport extends Serializable {
    }

    public Object DeserializationSupport.readResolve() throws
ObjectStreamException {
        return this;
    }
}

On Jan 11, 2008 3:58 AM, Carlos Pita <carlosjosepita@xxxxxxxxx> wrote:
> One more thing, doing this
>
>  @After("execution(* (@Injected java.io.Serializable+).readResolve())
> && this(injected)")
>
> doesn't intercept deserialization, it's not a solution. Even:
>
>  @After("execution(* *.readResolve()) && this(injected)")
>
> is only intercepting joinpoints where this instanceof
> DeserializationSupportImpl, but not an @Injected.
>
>
> Regards,
> Carlos
>
>
> On Jan 11, 2008 3:50 AM, Carlos Pita <carlosjosepita@xxxxxxxxx> wrote:
> > Hi all,
> >
> > I'm trying to intercept object deserialization when the object happens
> > to be an instanceof Serializable which is annotated with @Injected. In
> > order to do this I introduced an interface implementing readResolve(),
> > which is part of the deserialization protocol. Then I adviced this
> > introduced method. The advice is in fact executed upon
> > deserialization, but in that context 'this' is the introduced object,
> > not the one being deserialized (the one annotated with @Injected). I
> > need to get the list of methods of the original object in order to
> > inject dependencies on it, but I'm not able because I can only reach
> > the introduced one, which is a completely different one. Is there any
> > way to do this? Below is the related code. Any help would be very
> > appreciated.
> >
> > Regards
> > -Carlos
> >
> > public class InjectorAspect {
> >
> >     @After("execution(*
> > InjectorAspect.DeserializationSupport+.readResolve()) &&
> > this(injected)")
> >     public void afterDeserialization(Object injected) {
> >         injector.injectAll(injected); // <--- HERE injected is
> > DeserializationSupportImpl, not @Injected !
> >     }
> >
> >     @DeclareParents(value="@Injected java.io.Serializable+",
> > defaultImpl=DeserializationSupportImpl.class)
> >     private DeserializationSupport deserializationSupport;
> >
> >     public interface DeserializationSupport extends Serializable {
> >         public Object readResolve() throws ObjectStreamException;
> >     }
> >
> >     public static class DeserializationSupportImpl implements
> > DeserializationSupport {
> >         public Object readResolve() throws ObjectStreamException {
> >             return this;
> >         }
> >     }
> >
> > }
> >
>


Back to the top