javax.servlet.jsp.tagext
Class Tag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.Tag

public abstract class Tag
extends java.lang.Object

Actions in a Tag Library are defined through subclasses of Tag.


Field Summary
protected  BodyJspWriter bodyOut
           
static int EVAL_BODY
          Return value for doStartTag() and doAfterBody(): (re)evaluate the inner body of the tag.
static int EVAL_PAGE
          Return value for doEndTag(): continue evaluating the page
protected  PageContext pageContext
           
static int SKIP_BODY
          Return value for doStartTag() and doAfterBody(): skip the inner body of the tag.
static int SKIP_PAGE
          Return value for doEndTag(): skip the remaining evaluation of the page
protected  TagData tagData
           
 
Constructor Summary
Tag(java.lang.String libraryPrefix, java.lang.String tagName)
          Default constructor, all subclasses are required to only define a public constructor with the same signature, and to call the superclass constructor.
 
Method Summary
 int doAfterBody()
          Actions after some body has been evaluated.
 void doBeforeBody()
          Actions before some body is to be evaluated.
 int doEndTag()
          Process the end tag.
 int doStartTag()
          Process the start tag for this instance.
static Tag findAncestorWithClass(Tag from, java.lang.Class klass)
          Find the instance of a given class type that is closest to a given instance.
protected  BodyJspWriter getBodyOut()
           
 java.lang.String getLibraryPrefix()
           
 PageContext getPageContext()
          return the PageContext for this tag
 Tag getParent()
           
protected  JspWriter getPreviousOut()
           
 TagData getTagData()
          return the immmutable TagData for this tag
 java.lang.String getTagId()
           
 java.lang.String getTagName()
           
 java.lang.Object getValue(java.lang.String key)
           
 void initialize(Tag parent, TagData tagData, PageContext pc)
          Initialize a Tag instance so it can be (re)used.
 void release()
          Release a Tag instance so it can be (re)used.
 void setBodyOut(BodyJspWriter b)
          Set the BodyJspWriter.
 void setValue(java.lang.String key, java.lang.Object value)
          set a user defined value on the Tag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVAL_BODY

public static final int EVAL_BODY
Return value for doStartTag() and doAfterBody(): (re)evaluate the inner body of the tag.

SKIP_BODY

public static final int SKIP_BODY
Return value for doStartTag() and doAfterBody(): skip the inner body of the tag.

EVAL_PAGE

public static final int EVAL_PAGE
Return value for doEndTag(): continue evaluating the page

SKIP_PAGE

public static final int SKIP_PAGE
Return value for doEndTag(): skip the remaining evaluation of the page

bodyOut

protected BodyJspWriter bodyOut

pageContext

protected PageContext pageContext

tagData

protected TagData tagData
Constructor Detail

Tag

public Tag(java.lang.String libraryPrefix,
           java.lang.String tagName)
Default constructor, all subclasses are required to only define a public constructor with the same signature, and to call the superclass constructor. This constructor is called by the code generated by the JSP translator.
Parameters:
libraryPrefix - The namespace prefix used for this library. For example "jsp:".
tagName - The name of the element or yag, for example "useBean"
Method Detail

findAncestorWithClass

public static final Tag findAncestorWithClass(Tag from,
                                              java.lang.Class klass)
Find the instance of a given class type that is closest to a given instance. This class is used for coordination among cooperating tags.
Parameters:
the - subclass of Tag or interface to be matched
Returns:
the nearest ancestor that implements the interface or is an instance of the class specified

initialize

public void initialize(Tag parent,
                       TagData tagData,
                       PageContext pc)
Initialize a Tag instance so it can be (re)used. A freshly created tag instance has to be prepared by invoking this method before invoking doStartTag(). A tag instance that has been used and released by invoking release(), must be reinitialized by invoking this method.

Extreme care should be taken if this method is to be modified or interposed as it maintains invariants that are global to the whole page, specifically the parent Tag link list. initialize() is not frequently changed or interposed by the Tag author.

Parameters:
parent - the parent extension tag for this tag or null
tagData - attribute data for this tag instance
pc - PageContext for this tag instance.

release

public void release()
Release a Tag instance so it can be (re)used.

Extreme care should be taken if this method is to be modified or interposed as it maintains invariants that are global to the whole page, specifically the parent Tag link list. initialize() is not frequently changed or interposed by the Tag author.


doStartTag

public int doStartTag()
               throws JspException
Process the start tag for this instance. The doStartTag() method assumes that initialize() has been invoked before. When this method is invoked, the body has not yet been invoked.

doEndTag

public int doEndTag()
             throws JspException
Process the end tag. This method will be called on all Tag objects. Returns an indication of whether the rest of the page should be evaluated or skipped. All instance state associated with this instance must be reset. The release() method should be called after this invocation.
Returns:
SKIP_PAGE if the rest of the page should be skipped, and EVAL_PAGE if the evaluation of the page should continue.

setBodyOut

public void setBodyOut(BodyJspWriter b)
Set the BodyJspWriter. It will be invoked at most once per action invocation. Will not be invoked if there is no body evaluation. Frequently it is not redefined by Tag author.
Parameters:
b - the BodyJspWriter

doBeforeBody

public void doBeforeBody()
                  throws JspError
Actions before some body is to be evaluated. Not invoked in empty tags or in tags returning false in doStartTag() This method is invoked before every body evaluation. The companion method doAfterBody() is invoked after every body evaluation. The triple "doBeforeBody() -- BODY -- doAfterBody()" is invoked initially if doStartTag() returned EVAL_BODY, and it is repeated as long as the doAfterBody() evaluation returns EVAL_BODY. The method re-invocations may be lead to different actions because there might have been some changes to shared state, or because of external computation.

doAfterBody

public int doAfterBody()
                throws JspError
Actions after some body has been evaluated. Not invoked in empty tags or in tags returning false in doStartTag() This method is invoked after every body evaluation. The companion method doBeforeBody() is invoked before every body evaluation. The triple "doBeforeBody() -- BODY -- doAfterBody()" is invoked initially if doStartTag() returned EVAL_BODY, and it is repeated as long as the doAfterBody() evaluation returns EVAL_BODY. The method re-invocations may be lead to different actions because there might have been some changes to shared state, or because of external computation.

getParent

public Tag getParent()
Returns:
the parent extension tag instance or null

getTagId

public java.lang.String getTagId()
Returns:
the value of the id or null

getLibraryPrefix

public java.lang.String getLibraryPrefix()
Returns:
the library prefix being used with this tag

getTagName

public java.lang.String getTagName()
Returns:
the tag name

getTagData

public TagData getTagData()
return the immmutable TagData for this tag
Returns:
the TagData for this Tag

getPageContext

public PageContext getPageContext()
return the PageContext for this tag
Returns:
the PageContext for this Tag

setValue

public void setValue(java.lang.String key,
                     java.lang.Object value)
set a user defined value on the Tag
Parameters:
key - the name of the user defined value
value - the value to be associated

getValue

public java.lang.Object getValue(java.lang.String key)
Returns:
the value associated with the key

getPreviousOut

protected final JspWriter getPreviousOut()
Returns:
the value of the "out" JspWriter prior to pushing a BodyJspWriter

getBodyOut

protected final BodyJspWriter getBodyOut()
Returns:
the value of the current "out" JspWriter