Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

List all EJB methods

 
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?
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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.
 
author & internet detective
Posts: 40213
818
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of EJB? If 2.x, you could parse the deployment descriptor.
 
greenhorn
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.
 
Sheriff
Posts: 10445
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic