Element Construction Set Design

The Element Construction Set is designed from the bottom up to be an object oriented abstraction of tag generation. This document describes how the framework generates tags.

The image above represents the object layout of the framework. As you can see, the two core classes which make up 90% of the framework internals are the Element and ElementAttributes classes. The ElementAttributes class contains set* methods that are global for all HTML 4.0 elements, such as setTitle(), setID(), setClass(), etc. This is where the output() methods that generate the actual tags reside. It also implements the AttributeRegistry interface. The Element class implements the ElementFactory interface. This is where the toString() methods reside. The toString() methods simply call the output() methods within the ElementAttributes class.

There are two different types of Elements, there are SinglePartElements (SPE) and MultiPartElements (MPE). The difference is that SPE's never have a closing portion of their tag. For example, an <IMG> tag does not have a </IMG> tag, but a <HTML> tag has a </HTML> tag. When creating your own elements classes, it is generally a simple decision to use either SPE or MPE as the class that you will be extending.

Implementing your own tags is relatively simple, first you should decide if you want a SPE or a MPE. Once you have decided that, we suggest that you copy an existing element and modify it for your own needs. Generally, the instance constructor (the part at the top of the class file that is only in { } brackets) is the location of the definition of the tag:


{
    setElementType("th");
}
You can simply change the "th" to be "mytag". After you have done that, it is just a matter of defining what attributes (if any) that your tag will have. It is fairly easy to determine how this code works by looking at the existing examples. Please note that in most cases, you do not need to understand anything about the underlying API above the MPE and SPE classes. If you do need to know, feel free to look at the code or also see how the other tags are implemented. If you have further questions, please subscribe to the ECS mailing list and we will attempt to answer your questions there.

The Document class is a wrapper for the Html, Head, Title and Body elements. It allows you to easily create Html "documents" for use in your application. This class is not intended to in any way represent the Document object model (ie: DOM), it is simply a helper class.

Comments/Questions

Comments/Questions about the design and implementation should be sent to the ECS mailing list.



Copyright (c) 1999 The Java Apache Project.
$Id$
All rights reserved.