You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Taha Hafeez <ta...@gmail.com> on 2010/11/05 03:19:34 UTC
Services and generics
Hi
I have a generic service GenericDao<E> and all Dao's extend from it.. Now i
want to get a service based on generic type.
As generics are not present at runtime so I think this is very unlikely. So
this is what I have done
I created another service GenericDaoFinder as
public interface GenericDaoFinder {
<E> GenericDaoFinder(Class<E> type);
}
Now in Module I contribute services to it as
public static void contributeGenericDaoFinder(MappedConfiguration<Class<?>,
GenericDao<?>> configuration,
UserDao userDao, SomethingDao somethingDao){
configuration.add(User.class, userDao);
configuration.add(Something.class, somethingDao);
}
Is there a better way ??
regards
Taha
Re: Services and generics
Posted by Taha Hafeez <ta...@gmail.com>.
Will try it out...
Thanks
taha
On Fri, Nov 5, 2010 at 9:01 AM, Josh Canfield <jo...@gmail.com>wrote:
> Real generic support is coming in 5.3. There is a patch on the dev list if
> your brave.
> On 4 Nov 2010 19:20, "Taha Hafeez" <ta...@gmail.com> wrote:
> > Hi
> >
> > I have a generic service GenericDao<E> and all Dao's extend from it.. Now
> i
> > want to get a service based on generic type.
> > As generics are not present at runtime so I think this is very unlikely.
> So
> > this is what I have done
> >
> > I created another service GenericDaoFinder as
> >
> > public interface GenericDaoFinder {
> > <E> GenericDaoFinder(Class<E> type);
> > }
> >
> > Now in Module I contribute services to it as
> >
> > public static void
> contributeGenericDaoFinder(MappedConfiguration<Class<?>,
> > GenericDao<?>> configuration,
> > UserDao userDao, SomethingDao somethingDao){
> > configuration.add(User.class, userDao);
> > configuration.add(Something.class, somethingDao);
> > }
> >
> > Is there a better way ??
> >
> > regards
> > Taha
>
Re: Services and generics
Posted by Josh Canfield <jo...@gmail.com>.
Real generic support is coming in 5.3. There is a patch on the dev list if
your brave.
On 4 Nov 2010 19:20, "Taha Hafeez" <ta...@gmail.com> wrote:
> Hi
>
> I have a generic service GenericDao<E> and all Dao's extend from it.. Now
i
> want to get a service based on generic type.
> As generics are not present at runtime so I think this is very unlikely.
So
> this is what I have done
>
> I created another service GenericDaoFinder as
>
> public interface GenericDaoFinder {
> <E> GenericDaoFinder(Class<E> type);
> }
>
> Now in Module I contribute services to it as
>
> public static void
contributeGenericDaoFinder(MappedConfiguration<Class<?>,
> GenericDao<?>> configuration,
> UserDao userDao, SomethingDao somethingDao){
> configuration.add(User.class, userDao);
> configuration.add(Something.class, somethingDao);
> }
>
> Is there a better way ??
>
> regards
> Taha