Java Reference
In-Depth Information
public boolean
isComposite() {
return
true; }
public
Element firstChild() {
return
child; }
public void
addChild(Element newChild) {
if
(child
##
null
)
child
#
newChild;
else
{
Element currentChild;
currentChild
#
child;
while
(currentChild.hasNext())
currentChild
#
currentChild.nextSibling();
currentChild.addSibling(newChild);
}
}
public
String getClosingTag() {
return
"</"
!
tag
!
">"; }
public void
serialize(PrintWriter os){
os.print(getOpeningTag());
Element currentChild;
CurrentChild
#
firstChild();
while
(currentChild!
#
null
){
currentChild.serialize(os);
currentChild
#
currentChild.nextSibling();
}
os.println(getClosingTag());
}
}
The remaining classes extend either
Element
or
Component
. They repre-
sent concrete elements that appear in HTML pages.
public
class Br
extends
Element {
public
Br(){
super
(
null
, "BR"); }
}
public class
Link
extends
Composite {
public
Link(String href){
super
(href,"A");
}
public
String getOpeningTag() {
return
"<"
!
tag
!
" href
#
\""
!
info
!
"\" >"; }
}
public class
Ul
extends
Composite {
public
Ul(){
super
(
null
,"UL");
}
}
public class
Head
extends
Element {
public
Head(String title){
super
(title, "HEAD");
}