Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any ideas to develop a web framework without any xml configuration?

 
Haulyn Jason
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all
I am working on a task to develop a simple web framework without any configuration. Below is the details:

We need to achieve the two goal:
1. we supply an interface, when a class implement the interface, this class is a http service class via http to invoke a default method.
2. we supply an Annotation, when a method in any class refers to this Annotation, this method will auto bind to a web service.

the problem is:
1.with out configuration as xml or properties, how can I find all the classes implement my interface in the runtime classpath?
2.the same as the first one, how can I find all the classes refer to my Annotation?

Thanks very much.
 
Haulyn Jason
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe, from the classloader, it is impossible to find all the implementation.

but I just want to achieve my goal, any ideas?

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with using an interface is that you can't find out which class implements it until you instantiate it. (At least not with the standard Java API; there are libraries like BCEL and Javassist that can provide that information by looking directly at the class file.)

I'd say that using annotations is preferable. If the annotation has a RetentionPolicy of RUNTIME then your code can find out about it at -well- runtime by looking at the Class object of the class in question. You may want to iterate through the contents of the WEB-INF/classes and WEB-INF/lib directories at startup time to find all such classes.

Check out the open source Stripes web framework as an example of how such configuration can be done completely based on annotations. I find it very convenient to use.
 
Haulyn Jason
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you.
I am seeing Stripes now, it looks well.

If it is possible to use annotations, the next is I need to try to integrate Google Guice as DI and Factory.

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one book available on Stripes has a section on how to integrate Guice and Stripes. Code example "email_33" -downloadable from that web site- is a ready-to-run web app that shows this in action (although it may be a bit hard to follow w/o reading the book chapter). But if you're serious about Stripes, then $23 for a PDF or $36 for paper is well spent; I can recommend the book.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic