Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

List all EJB methods  RSS feed

 
D Hankins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been asked to periodically list - preferably in spreadsheet form - the public interface of our app's back end, its business tier. Specifically, what's wanted is a list of all the EJB methods that our app exposes publically.

Starting from a list of classes, this is pretty easy - the Reflection API provides all I need.

But getting that initial list of EJB classes in not so simple. There is apparently no method in the Java core classes to list a class's subsclasses, or all the classes in a package (either of which would suit).

I've googled this until the cows came home, and all I found were some kludges that go looking in the filesystem. Is there no better way to get a list of all the subclasses of a class, or all the classes in a package?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12089
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered Javadoc? It comes with your Java compiler, generates all the API information for you, for all your classes and all their methods (you can specify what visibility you want reported), provides grouping by packages, and lists found subclasses etc.

In case you have never seen the output of Javadoc before, here is the Javadoc from the J2SE source code, jumping directly to IOException. You can see packages in the top left hand corner, all classes in the bottom right hand corner, and the information for the class itself in the right hand side. You can see what the IOException extends, what interfaces it implements, and a whole list of classes that extend it.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36432
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of EJB? If 2.x, you could parse the deployment descriptor.
 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ OP
or all the classes in a package

isn't a package is folder in explorer. use file io.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the file i/o for this isn't a good option. Remember theoretically classes can be loaded from anywhere and its the classloader which is responsible for that.

Specifically, what's wanted is a list of all the EJB methods that our app exposes publically.


If you look at this more closely, it's exactly what each application server has to do too. It has to find out the business interfaces exposed by the EJBs and the business methods. As Jeanne said, this can be done if you either have access to the ejb-jar.xml files or for EJB3.x, if you know the bean implementation class (although it's not straightforward for EJB3.x which allows the annotations to be specified not just on the impl class but even the interfaces). Overall, it's just a matter of finding out the business interface of a bean (can be done easily by parsing ejb-jar.xml) and then listing the methods on that interface.
 
D Hankins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all who replied.
Andrew Monkhouse wrote:Have you considered Javadoc?

Yes. Parsing the output of Javadoc to produce the kind of spreadsheet that's wanted would be a pretty big job. I was really looking for something simple like:

public static List<Class> getSubclasses(Class targetClass);
Jeanne Boyarsky wrote:What version of EJB? If 2.x, you could parse the deployment descriptor.

Yeah, I could, except that there's no guarantee that a particular EJB method is actually in the descriptor; an EJB method that's omitted from the descriptor produces a warning but can still be called.
Jaikiran Pai wrote:Overall, it's just a matter of finding out the business interface of a bean (can be done easily by parsing ejb-jar.xml) and then listing the methods on that interface.

Ah, but getting a list of the beans when ejb-jar.xml isn't guaranteed to contain them - aye, there's the rub.

Again, thanks all for the help so far.

D
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!