[jdom-interest] Re: Proposal: JDOM event based processing

James Strachan james at metastuff.com
Tue Nov 7 03:18:35 PST 2000

From: "Joseph Bowbeer" <jozart at csi.com>
> I think this idea has potential.  It might simplify some things I may
> want to do.


> Suggestions:
> 1. Implement your SAXProcessor as an XMLFilter so it can be plugged into
> a filter chain.

Yes - I want to go in that direction. The proposal mentioned using XPath to
define the nodeset of the subtree but I'd like to allow other more general
methods of filtering / routing / transforming SAX events to Element

At the implementation level I'd like a fairly abstract general way of
connecting SAX event filters / routers to Element factories which can then
call the ElementHandlers.

It would be kinda nice to implement a simple XML transformation framework in
Java such that XPath is the declarative bit to specify the nodesets for
processing and Java ElementHandlers do the object orientated / procedural
transformation / processing logic.

> 2. Add the XPath expression to the event so one event handler can handle
> several different Element events unambiguously.
> 3. Use Beans-style naming to aid introspection.  This way, Element event
> listeners and Element event sources can be connected auto-visually using
> IDEs.

I'm not too sure about 2 and 3 yet. Basically I was just concerned about
performance and didn't want to introduce extra event objects unless
absolutely necessary. This is also why I didn't put the Element tree into a
Document object 'holder' in the ElementHandler interface.

I was thinking that for the ElementHandler the Element itself would be the
'event' in a bean sense (though since Event doesn't derive from EventObject
it wouldn't follow the Bean component model).

For Bean builders and the like we could have adapters to the Bean style way
of doing things so that you only incur the cost of the extra bean event
objects when you are doing things in a bean way.

e.g. here's off the top of my head the adapters to plug in Bean builders to
the ElementHandler world...

package org.jdom.bean;
import org.jdom.*;
import java.util.*;

/** Bean Element listener */
public interface ElementListener extends EventListener {
    public void onElement( ElementEvent event );

/** Bean Element event object */
public class ElementEvent extends EventObject {
    private Element element;
    private String xpath;

    public ElementEvent( SAXProcessor source, String xpath, Element
element ) {
        super( source );
        this.xpath = xpath;
        this.element = element ;
    public String getXPath() {
        return xpath;
    public Element getElement() {
        return element;

/** Adapts ElementHandler to Bean ElementListener */
public class BeanElementHandler implements ElementHandler {
    private SAXProcessor processor;
    private ElementListener listener;
    private String xpath;

    public void handle( Element element ) {
        ElementEvent event = new ElementEvent( processor, xpath., element );
        listener.onElement( event );


James Strachan
email: james at metastuff.com
web: http://www.metastuff.com

If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.

More information about the jdom-interest mailing list