Hi Kevin,

You can rewrite your Foo class as:

public class Foo implements MagicClass {
  @Trace
  @Secured
  public void bar() {
  }
}

Then, associate a generator for sub-types of MagicClass and use
GWT.create to instantiate a new Foo.

GWT.create(Foo.class);

So your generator will be called. It can generate a FooImpl class that
extends the Foo class and override the bar method as follow:

public class FooImpl extends Foo {
  public void bar() {
    Log.log("begin of bar");
    try {
      SecurityContext.checkAuthorized();
      super.bar();
    }
    finally {
      Log.log("end of bar");
    }
  }
}

Where "Log.log" print some logs and "SecurityContext.checkAuthorized"
throws an error is the user is not authorized. This could be funny and
not really hard to do.

Olivier

On 11 juin, 18:09, Kevin Qiu <kevin.jing....@gmail.com> wrote:
> Hi,
>
> I know GWT can generate Java source code with deferred binding. But
> sometimes, I don't want to generate a new implementation, but based on some
> annotations, I want to have the ability of injecting code at compile time.
>
> e.g., with the class below
>
> public class Foo {
>   @Log
>   public void bar() {
>     @CheckPermission
>     dosomething();
>   }
>
> }
>
> At compile time, I want to have the ability to get the annotations available
> on items, and inject code according to my application logic. So here, the
> compiler should see:
> public class Foo {
>   public void bar() {
>     log("begin");
>     if (hasPermission()) {
>       doSomething();
>     } else {
>       error();
>     }
>   }
>
> }
>
> with the extra code being injected. I'm wondering if anything in GWT allows
> me to do that?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to