<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>RE: [doom-interest] The JDOM Model, Chapter 15 of Processing XML with Java</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT size=2><FONT
face=Tahoma>-----Original Message-----<SPAN class=174310117-06052002><FONT
face=Arial color=#0000ff> </FONT></SPAN></FONT></FONT></DIV>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT size=2><FONT
face=Tahoma><SPAN class=174310117-06052002></SPAN></FONT></FONT><FONT
size=2><FONT face=Tahoma><SPAN
class=174310117-06052002> </SPAN></FONT>> 1. What is a
node?</FONT> <FONT size=2><SPAN class=174310117-06052002><FONT face=Arial
color=#0000ff> </FONT></SPAN></FONT></DIV>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT size=2>I don't
know. I do know it has one parent, and zero to N children, though.
So how about an interface to describe it. Then all the concrete classes
we like so much can implement it as best fits their specific
tasks.</FONT></DIV>
<P><FONT size=2>public interface Node{</FONT>
<BR> <FONT size=2>public Node []
children = get Children(); // * more later....</FONT>
<BR> <FONT size=2>public Node parent
= get Parent();</FONT> <BR><FONT size=2>}<SPAN class=174310117-06052002><FONT
face=Arial color=#0000ff> </FONT></SPAN></FONT></P></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>Another way of thinking of interfaces is that
it defines the set of methods that are needed for a general machinery
to do interesting things. This is the way I think of the xxxModel interfaces in
Swing: The define the methods I need to implement to make a custom class
viewable through a Jxxx.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>For JDOM nodes, the interesting operations are adding
them, moving them around, deleting them and externalising them. With methods for
each of these, it should be possible to make a custom class that may be inserted
in a JDOM tree, and that will be written out as valid XML. It does not bother me
that it will not be reconstructed as this custom node, as long as I can replace
the corresponding nodes with my custom node after the JDOM tree has been
built.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>A public interface for these operations will
include:</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>public interface Node {</SPAN></FONT></DIV><FONT><SPAN
class=174310117-06052002>
<DIV dir=ltr><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=174310117-06052002> public List getChildren(); // return
a list of children</SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=174310117-06052002> </SPAN> public boolean
addChild(Node child); // return false if invalid to add
child</FONT></FONT></FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002> public boolean removeChild(Node
child); // return false if child is not a child of this node</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002> public boolean validate(); //
'global' check of sub-tree</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002> public void output(SAXHandler
handler); // generate SAX events for this node</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>}</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>The most interesting method is the last one, which
makes it possible to drive SAX filters and transformations. An alternative to
returning a List would be to include int getLength() and Node getChild()
methods, and perhaps an </SPAN></FONT><FONT face=Arial color=#0000ff
size=2><SPAN class=174310117-06052002>Iterator getChildren()
method.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>It might be that we would end up with DOM if we
continue this process, but for new-comers like me it is interesting to
understand what is required of such an interface for different
purposes.</SPAN></FONT><FONT size=+0><SPAN
class=174310117-06052002></DIV></SPAN></FONT></SPAN></FONT></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<P><FONT size=2>This is one of the two major complaints I have about
JDOM. Lack of common interfaces. I think fixing it requires
two things. A clear specification of what those interfaces should be,
and a major refactoring of the code base to implement the specification.<SPAN
class=174310117-06052002><FONT face=Arial
color=#0000ff> </FONT></SPAN></FONT></P></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>If we could agree on a set of criteria for
measuring the "goodness" of the refactored code base, we could make a contest of
the "best" node interface definition :-)</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002></SPAN></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002>Hallvard</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#0000ff size=2><SPAN
class=174310117-06052002></SPAN></FONT> </DIV></BODY></HTML>