aspose file tools*
The moose likes Java in General and the fly likes Any ideas to develop a web framework without any xml configuration? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Any ideas to develop a web framework without any xml configuration?" Watch "Any ideas to develop a web framework without any xml configuration?" New topic
Author

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

Haulyn Jason
Ranch Hand

Joined: Jul 24, 2007
Posts: 37
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.


Mama always said, "Life is like a box of chocolates; you never know what you're gonna get. And then you have to get medieval on somebody's buttocks."
http://www.haulynjason.net/
Haulyn Jason
Ranch Hand

Joined: Jul 24, 2007
Posts: 37
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
Marshal

Joined: Mar 22, 2005
Posts: 41475
    
  51
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.


Ping & DNS - my free Android networking tools app
Haulyn Jason
Ranch Hand

Joined: Jul 24, 2007
Posts: 37
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
Marshal

Joined: Mar 22, 2005
Posts: 41475
    
  51
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any ideas to develop a web framework without any xml configuration?