• Post Reply Bookmark Topic Watch Topic
  • New Topic

API for getting the all the implementation classes of an interface  RSS feed

 
kay jee
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey folks
howdy
I need an API to get all the implementation classes of an interface in a project.
please help
 
Ritika Saxena
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kay jee

Can you please elaborate a bit more on what you want. Your requirement is not clear to me....
 
kay jee
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritika

If you use eclipse then you might be aware that if I do ctrl+t on any interface/class name then I get the implementation hierarchy of that class.

I need a java API which will do the same job for me. Are you aware of any?

Thanks
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, there is no general solution to what you want.

You cannot enumerate all the classes that are "in your application" (i.e. available to be loaded). You cannot enumerate all the classes that have been loaded. At least, you can't via a standard ClassLoader anyway. If you created a custom ClassLoader and used it exclusively throughout your application, you could - if you were able to implement those facilities in your custom ClassLoader.

Because of the above, you cannot enumerate the subset of classes that implement a particular interface.

Eclipse can do this because it knows what classes are in your project, and can hence iterate through them and see which ones implement a given interface.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apaches Discovery project does something like this.Finding concrete classes of some interface.
 
kay jee
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rahul and Peter. Will get back if I get around it.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:
Apaches Discovery project does something like this.Finding concrete classes of some interface.


I see Apache Discovery Web Site but I don't get it.

What does this really give you? What is this "JDK 1.3+ style discovery" that they talk about on the first page?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:

I see Apache Discovery Web Site but I don't get it.

I have never used this package.But read that its used for finding all the concrete implementation of the given interface , based on certain conditions.
The issue in the post sounded to me something similar so thought of giving a pointer to this.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:

I have never used this package.But read that its used for finding all the concrete implementation of the given interface , based on certain conditions.


No, it doesn't find *all* implementations of a generic interface. It finds *one* implementation - one that is registered by special means (such as a system property or similar).
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:

What is this "JDK 1.3+ style discovery" that they talk about on the first page?


As far as I know, this involves some special files in the META-INF folder of a jar file, that define what concrete implementations of an abstract service (=interface) are provided by that jar file.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See documentation here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!