[jdom-interest] Parents - why do we need them?

Noam Tamim noamt at yahoo.com
Sat Jun 30 03:21:09 PDT 2001


> a fairly unambiguous API for changes.  There are several tactics
> possible when changing the value of a shared attribute:

This behavior is the one I want:

> 2) if a SharedAttribute value is changed, change its value everywhere.

That's the idea: you add the same SharedAttribute object to all of the
relevant Elements in the tree. In my case, I was building html tables.
I want every <table> to have the same border attribute, for example,
border=1. So I have many tables in my document, all of them look like that
when outputted:
<table border="1" />

When I still have that Document in memory, if I decide that I want the
border width to be 3. So I just call borderAttr.setValue("3"), and voila:
<table border="3" />

That's the whole idea of "Shared"; my target was definitely not memory
optimization, but the ability to change the attributes of many elements with
a single call. Another approach could be to use an Attribute that uses a
StringBuffer for the value, and exposes it - so I can use the same
StringBuffer for many Attributes, and change it later.


 - Noam.








More information about the jdom-interest mailing list