[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Re: Accessing original instance from introduction
|
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;
> }
> }
>
> }
>