[jdom-interest] Ideas for API changes

Noam Tamim noamt at yahoo.com
Sat Apr 28 15:08:56 PDT 2001


Hi.

I'd like to suggest some changes to the JDOM API. The first two are more
significant, the others are just a matter of convenience:

* Make the classes Attribute, CDATA, Comment, DocType, Document, Element,
Entity, ProcessingInstruction implement a common interface "Item":

interface Item extends Serializable, Cloneable {
    String getSerializedForm();
    // maybe some other methods..
}

This will allow a developer to use all those objects with a common class
name, and not "Object".

* Change overloaded versions of Element.addContent(..) to a single
addContent(Item) method.

* Supply every Item with a "serializedForm" constructor, i.e.
Element elt=new Element("<locale language=\"English\" country=\"US\"/>");
will create a new Element "locale" with the Attributes "language" and
"country".
Since the regular constructor already takes a String parameter, maybe it's
better to make it a static constructing method.
As an alternative, maybe "Item" should be an abstract class rather than an
interface:
public abstract class Item {
    public abstract String getSerializedForm();

    public static Element getElement(String serialForm) {
        // build a new Element from serailForm
    }
    // getAttribute, getComment, etc.
}

* Change addContent() to add().

* Add two static methods to Attribute, to convert a Map of String:String 
to a List of Attributes and vice-versa. Can be handy.

 - or -

* Add a new "JDOMUtils" class that will include some convenience methods
like the above.



 - Noam.







More information about the jdom-interest mailing list