Hello !

I created an object instance of a Class with custom annotations using
Guice.
But the created instance did not retain any of the annotations on my
class.

I have copied the example am trying to run at the end of this message.
Any idea what's happening here?

Cheers!
Nirav

/**************** CODE START ******************/

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import uk.co.netdev.cie2.rest.gui.GuiBT;
import uk.co.netdev.cie2.util.CieSecurity;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.matcher.Matchers;

public class GuiceAOP {

        @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)
        public @interface CheckCiePermissions {}

        public class CieSecurityModule extends CieSecurity{
                @Override
                protected void configure() {
                        bindInterceptor(Matchers.any(), Matchers.annotatedWith
(CheckCiePermissions.class), new SecurityInterceptor());
                }
        }

        public static class SecurityInterceptor implements MethodInterceptor
{
                  public Object invoke(MethodInvocation invocation) throws 
Throwable
{
                          System.out.println("Security Interceptor Invoked");
                          return invocation.proceed();
                  }}


        public static class TestGuice{
                @CheckCiePermissions
                @GuiBT
                public String sayHello(){
                        return "Hello";
                }
        }

        public static void main(String[] args) {
                GuiceAOP guiceTest = new GuiceAOP();
                Injector injector = Guice.createInjector(guiceTest.new
CieSecurityModule());

                TestGuice test = injector.getInstance(TestGuice.class);
                for(Method method : test.getClass().getMethods()){
                        for(Annotation annot : method.getAnnotations()){
                                System.out.println("Object created using Guice: 
" +
annot.annotationType().getName());
                        }
                }

                TestGuice test2 = new TestGuice();
                for(Method method : test2.getClass().getMethods()){
                        for(Annotation annot : method.getAnnotations()){
                                System.out.println("Object created using new(): 
" +
annot.annotationType().getName());
                        }
                }

        }

}


/**************** CODE END ******************/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to