commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <simone.trip...@gmail.com>
Subject [digester] extension annottaion proposal
Date Sat, 03 Oct 2009 20:32:17 GMT
Hi all commons folks!!!
I've been happily using the digester package since the 1.6 release, I
found it very easy to use and absolutely one of the best way to parse
quickly XML documents and mapping them to Java objects :)

Even if using the XML rule declaration, or coding Digester rules, is
absolutely very very easy, times ago I started implementing as a PoC
[1], in my spare time, a facility tool able to create Digester
instances automatically... taking inspiration by Google-Guice and
JPA's annotations, I wonder: "why can't we generate the Digester's
Rules through Java5 annotations?" What I realized in my mind was the
phrase "Basically, the Digester package lets you configure an XML ->
Java object mapping module, which triggers certain actions called
rules whenever a particular pattern of nested XML elements is
recognized."

So, my idea is: simply given an Annotated Class, we wanted to inspect
it, and extract all the needed to generate the rules - in this way, we
could save time writing the rules manually and reduce the errors while
binding properties and methods'name, arguments etc, etc.

I mean, for example, given the following XML snippet

<web-app>
[...]
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>application</param-name>
            <param-value>org.apache.struts.example.ApplicationResources</param-value>
        </init-param>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
    </servlet>
[...]
</web-app>

has to be mapped to the following object

@ObjectCreate("web-app/servlet")
public final class ServletBean {

    @BeanPropertySetter("web-app/servlet/servlet-name")
    private String servletName;

    @BeanPropertySetter("web-app/servlet/servlet-class")
    private String servletClass;

    private final Map<String, String> initParams = new HashMap<String,
String>();

    public String getServletName() {
        return this.servletName;
    }

    public void setServletName(String servletName) {
        this.servletName = servletName;
    }

    public String getServletClass() {
        return this.servletClass;
    }

    public void setServletClass(String servletClass) {
        this.servletClass = servletClass;
    }

    @CallMethod("web-app/servlet/init-param")
    public void
addInitParam(@CallParam("web-app/servlet/init-param/param-name")
String name,
            @CallParam("web-app/servlet/init-param/param-value") String value) {
        this.initParams.put(name, value);
    }

    [...]

}

and a special DigesterLoader is able to create Digester rules simply
by analizing the ServletBean class:

Digester digester = DigesterLoader.createDigester(ServletBean.class);

And that's all!

While publishing this work on the Web (already licensed under the
Apache 2.0 License) I wonder whether or not the
Apache Community might be interested on this... would this be of
interested to the community? is there anybody else out there
in the community worked on something similar? I would more than happy to
collaborate and find a way to merge the work into a bigger project eventually.

I aim to achieve a mature version of the project quicker and better; and
ultimately after submitting the proposal to the Commons Commettee as Digester
extension we would like to  find ways grow the work in an official module of the
distribution or a sub-project.

Last, I would personally be really happy to contribute to the ASF in any way and
maintain the above work if necessary.

Thanks in advance, best regards!!!
Simone Tripodi

[1] http://code.google.com/p/digester-annotations/

-- 
http://www.google.com/profiles/simone.tripodi

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message