Doesn't work for me:
public class InitParamImplTest {
    private static final String SOMETHING = "something";

    @Retention(RetentionPolicy.RUNTIME)
    public static @interface MyParam {
        String value();
    }

    public class MyParamImpl extends InitParamImpl implements MyParam {
        public MyParamImpl(String value) {
            super(value, MyParam.class);
        }
    }

    @MyParam(SOMETHING)
    public int x;

    @Test
    public final void annotationEquals() throws Exception {
        final MyParam annotation1 = InitParamImplTest.class
                .getField("x")
                .getAnnotation(MyParam.class);

        final MyParam annotation2 = new MyParamImpl(SOMETHING);

        assert annotation2.equals(annotation1) : "equal annotations are not
equal";
    }

}

It fails the assertion. Note that if you change the expression around:

        assert annotation1.equals(annotation2) : "equal annotations are not
equal";

It will work because you are no longer using InitParamImpl's equals()
method, rather the JVM annotation impl's. Perhaps this is where you are
being thrown off?

Dhanji.

On Wed, Sep 3, 2008 at 4:53 AM, Simone Tripodi <[EMAIL PROTECTED]>wrote:

>
> Hi Dhanji,
> I need a suggestion - I implemented an annotation impl
> (http://code.google.com/p/injectlet/source/browse/#svn/trunk) where
> the method equals uses the obj.getClass() and it's currently working.
> Is there a reason why it works - maybe because it's a special case -
> or do we must blame ourselves?
> Thanks in advance!
> Best regards,
> Simone
>
> 2008/9/2 Simone Tripodi <[EMAIL PROTECTED]>:
> > Hi Dhanji
> > of course you're right, I didn't test the code since I "developed" it
> > directly in my mail client ;)
> > Best,
> > Simone
> >
> > 2008/9/2 Dhanji R. Prasanna <[EMAIL PROTECTED]>:
> >>
> >> note that this impl of equals will always return false because of
> >> obj.getClass().
> >>
> >> Dhanji.
> >>
> >> On 9/1/08, Simone Tripodi <[EMAIL PROTECTED]> wrote:
> >>>
> >>> Hi Elek,
> >>> as Robbie suggested you - and reading oldest posts here in the group
> >>> you can understand that Robbie always knows the best solution - if you
> >>> choice the second way (and you still need help) I've prepared for you
> >>> the implementation you need:
> >>>
> >>>
> >>> public class PersistenceContextImpl implements PersistenceContext {
> >>>
> >>>     private String unitName;
> >>>
> >>>     public PersistenceContextImpl(String unitName) {
> >>>         this.unitName = unitName;
> >>>     }
> >>>
> >>>     public Class<? extends Annotation> annotationType() {
> >>>         return PersistenceContext.class;
> >>>     }
> >>>
> >>>     @Override
> >>>     public boolean equals(Object obj) {
> >>>         if (this == obj) {
> >>>             return true;
> >>>         }
> >>>
> >>>         if ((obj == null) || (obj.getClass() !=
> PersistenceContext.class)) {
> >>>             return false;
> >>>         }
> >>>
> >>>         PersistenceContext other = (PersistenceContext) obj;
> >>>         return unitName.equals(other.unitName());
> >>>     }
> >>>
> >>>     @Override
> >>>     public int hashCode() {
> >>>         return (127 * "unitName".hashCode() ^ unitName.hashCode());
> >>>     }
> >>>
> >>>     public String unitName() {
> >>>         return unitName;
> >>>     }
> >>>
> >>> }
> >>>
> >>>
> >>> Now you're able to bind EntityManager in this way:
> >>>
> >>> binder.bind(EntityManager.class).annotatedWith(new
> >>> PersistenceContextImpl("Test1PU")).toProvider(new
> >>> EntityManagerProvider(directory1));
> >>>
> >>> binder.bind(EntityManager.class).annotatedWith(new
> >>> PersistenceContextImpl("Test2PU")).toProvider(new
> >>> EntityManagerProvider(directory2));
> >>>
> >>> I hope this helps!
> >>> Best regards,
> >>> Simone
> >>>
> >>> 2008/8/31 Robbie Vanbrabant <[EMAIL PROTECTED]>:
> >>>> The easy answer: consider using Warp Persist (http://www.wideplay.com)
> for
> >>>> guicy persistence. Although support for multiple persistence units is
> not
> >>>> implemented in 1.0, we have have experimental support for it in the
> trunk.
> >>>> If you depend on that functionality let me know and we will help you
> get
> >>>> started.
> >>>>
> >>>> The other answer would be yes, you can do that. Have a look at how
> Guice
> >>>> implements Names.named(...). You basically have to bind to annotation
> >>>> instances instead of types, and you do that by subclassing the
> annotation
> >>>> and binding to an instance of that subclass.
> >>>>
> >>>> Hope this helps,
> >>>> Robbie
> >>>>
> >>>> On Sun, Aug 31, 2008 at 6:59 PM, elek <[EMAIL PROTECTED]> wrote:
> >>>>>
> >>>>> Hi,
> >>>>>
> >>>>> Is there any way to inject dynamic values to a class according to the
> >>>>> annotation parameters with Guice?
> >>>>> Eg.: I have the following fields in a class:
> >>>>>
> >>>>> @PersistenceContext(unitName="Test1PU")
> >>>>> EntityManager em1;
> >>>>>
> >>>>> @PersistenceContext(unitName="Test2PU")
> >>>>> EntityManager em2;
> >>>>>
> >>>>> An I would like to inject different EntityManager instances.
> >>>>> Unfortunately I can't access the annotation or the original Field
> over
> >>>>> the the Provider interface:
> >>>>>
> >>>>>
> >>>>>
> binder.bind(EntityManager.class).annotatedWith(PersistenceContext.class).toProvider(new
> >>>>> EntityManagerProvider(directory, ???unitName value???));
> >>>>>
> >>>>> Is there any solution for it?
> >>>>>
> >>>>> Thanks:
> >>>>> m.
> >>>>>
> >>>>
> >>>>
> >>>> >
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
> >>> My GoogleCode profile: http://code.google.com/u/simone.tripodi/
> >>> My Sourceforge: https://sourceforge.net/users/stripodi
> >>> My Picasa: http://picasaweb.google.com/simone.tripodi/
> >>> My Tube: http://www.youtube.com/user/stripodi
> >>> My Del.icio.us: http://del.icio.us/simone.tripodi
> >>>
> >>> >
> >>>
> >>
> >> >>
> >>
> >
> >
> >
> > --
> > My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
> > My GoogleCode profile: http://code.google.com/u/simone.tripodi/
> > My Sourceforge: https://sourceforge.net/users/stripodi
> > My Picasa: http://picasaweb.google.com/simone.tripodi/
> > My Tube: http://www.youtube.com/user/stripodi
> > My Del.icio.us: http://del.icio.us/simone.tripodi
> >
>
>
>
> --
> My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
> My GoogleCode profile: http://code.google.com/u/simone.tripodi/
> My Sourceforge: https://sourceforge.net/users/stripodi
> My Picasa: http://picasaweb.google.com/simone.tripodi/
> My Tube: http://www.youtube.com/user/stripodi
> My Del.icio.us: http://del.icio.us/simone.tripodi
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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