Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] complete code weaving

Hi,
I have a question about the AspectJ weaving. Simply put, I've tried a lot of different tests and I just can't get what I'm trying to achieve. The weaving concept is great, what I wanted to do was actually weave a piece of code upon project build into each and every class, sort of in an "inline" way. Using staticinitialization, I got what I wanted, that being for now, a simple print at console on class init.

Problem is that weaving in from an aspect class actually only puts a reference call to the aspect class. What I need is for it to copy the entire code snipet in the original class. So I am here with my question, is it possible to actually weave the entire new method or is it always going to be just a reference call.

here is a piece of my basic code.

public aspect testaspect
{
   pointcut staticInit() : staticinitialization(Test1);
before() : staticInit() {
       System.out.println("Loading class (aop block)");
   }
}

The reason I'm try to do this is because we want to couple this with obfuscation to increase the difficulty of hacking our code. By referencing to the method instead of copying the whole code snipet, we insert a sole point of failure. If the would-be hacker finds the refenrence call, he could just find that acpect class and change that. Whilst the way I want it, he would have to hack his way through every class.

just to show you, if I pass my .class inside JAD, this is what I get:

public class Test1
{
   public Test1(String _name)
   {
       name = _name;
   }
   public String getName()
   {
       return name;
   }
   private String name;
   static
   {
       *testaspect.aspectOf().ajc$before$testaspect$1$3e7a161f();*
       System.out.println("Loading class Test1 (static block)");
   }
}

you can see in the static part that *testaspect.aspectOf().ajc$before$testaspect$1$3e7a161f();* is a reference to my aspect instead of being what I would like to have which would be this:

public class Test1
{
   public Test1(String _name)
   {
       name = _name;
   }
   public String getName()
   {
       return name;
   }
   private String name;
   static
   {
       *System.out.println("Loading class (aop block 1)");*
       System.out.println("Loading class Test1 (static block)");
   }
}

Thank you very much for your time,
If it's not at all possible, I have other means of doing it but this was my favorite so I hope it's possible.

Frank


Back to the top