net.sf.joost.instruction
Class NodeBase

java.lang.Object
  extended by net.sf.joost.instruction.AbstractInstruction
      extended by net.sf.joost.instruction.NodeBase
All Implemented Interfaces:
Cloneable, Constants
Direct Known Subclasses:
AnalyzeTextFactory.Instance, AssignFactory.Instance, AttributeFactory.Instance, CdataFactory.Instance, ChooseFactory.Instance, CommentFactory.Instance, CopyFactory.Instance, DoctypeFactory.Instance, ElementEndFactory.Instance, ElementFactory.Instance, ElementStartFactory.Instance, ElseFactory.Instance, ForEachFactory.Instance, GroupBase, IfFactory.Instance, LitElementFactory.Instance, MatchFactory.Instance, MessageFactory.Instance, NoMatchFactory.Instance, NSAliasFactory.Instance, OtherwiseFactory.Instance, PIFactory.Instance, ProcessBase, ResultBufferFactory.Instance, ResultDocumentFactory.Instance, ScriptFactory.Instance, TemplateBase, TextFactory.Instance, TextNode, ValueOfFactory.Instance, VariableBase, WhenFactory.Instance, WhileFactory.Instance, WithParamFactory.Instance

public abstract class NodeBase
extends AbstractInstruction
implements Constants

Abstract base class for all instances of nodes in the STX transformation sheet

Version:
$Revision: 2.15 $ $Date: 2008/10/04 17:13:14 $
Author:
Oliver Becker

Nested Class Summary
 class NodeBase.End
          Generic class that represents the end of an element in the STX transformation sheet (the end tag).
 
Field Summary
protected  AbstractInstruction lastChild
          The reference to the last child, needed for inserting additional nodes while parsing the transformation sheet.
protected  Stack localFieldStack
          Stack for storing local fields from this or derived classes
protected  AbstractInstruction nodeEnd
          The reference to the end instruction.
 NodeBase parent
          The parent of this node
 boolean preserveSpace
          true if the attribute xml:space on the nearest ancestor element was set to preserve, false otherwise.
 String publicId
          The public identifier of the transformation sheet
 String qName
          The qualified name of this node
protected  Vector scopedVariables
          The names of local declared variables of this element, available only if this node has stx:variable children
 String systemId
          The system identifier of the transformation sheet
 
Fields inherited from class net.sf.joost.instruction.AbstractInstruction
colNo, lineNo, next
 
Fields inherited from interface net.sf.joost.Constants
DEBUG, DEFAULT_ENCODING, FEAT_NS, FEAT_NSPREFIX, FEATURE_URI_PREFIX, FUNC_NS, JOOST_EXT_NS, PR_ATTRIBUTES, PR_BUFFER, PR_CHILDREN, PR_CONTINUE, PR_ERROR, PR_SELF, PR_SIBLINGS, STX_NS
 
Constructor Summary
protected NodeBase(String qName, NodeBase parent, ParseContext context, boolean mayHaveChildren)
           
 
Method Summary
 boolean compile(int pass, ParseContext context)
          This method may be overwritten to perform compilation tasks (for example optimization) on this node.
protected  void declareVariable(String name)
          Store the name of a variable as local for this node.
 NodeBase getNode()
           
 AbstractInstruction getNodeEnd()
          Getter for nodeEnd used by Processor.processEvent().
 void insert(NodeBase node)
          Insert a new node as a child of this element
protected  void mayDropEnd()
          Removes (if possible) the end node (nodeEnd) of this instruction from the execution chain.
protected  void onDeepCopy(AbstractInstruction copy, HashMap copies)
          Callback that will be called when a clone of this instance has been created.
 short process(Context context)
          Save local variables if needed.
 boolean processable()
           
protected  short processEnd(Context context)
          Called when the end tag will be processed.
 void setEndLocation(ParseContext context)
          Notify this node about its end location (taken from ParseContext.locator in the context parameter)
 String toString()
           
 
Methods inherited from class net.sf.joost.instruction.AbstractInstruction
deepCopy, deepHashtableCopy, deepTemplateArrayCopy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

qName

public String qName
The qualified name of this node


parent

public NodeBase parent
The parent of this node


lastChild

protected AbstractInstruction lastChild
The reference to the last child, needed for inserting additional nodes while parsing the transformation sheet.


nodeEnd

protected AbstractInstruction nodeEnd
The reference to the end instruction. null means: must be an empty element.


publicId

public String publicId
The public identifier of the transformation sheet


systemId

public String systemId
The system identifier of the transformation sheet


preserveSpace

public boolean preserveSpace
true if the attribute xml:space on the nearest ancestor element was set to preserve, false otherwise. This field is set in the Parser object.


scopedVariables

protected Vector scopedVariables
The names of local declared variables of this element, available only if this node has stx:variable children


localFieldStack

protected Stack localFieldStack
Stack for storing local fields from this or derived classes

Constructor Detail

NodeBase

protected NodeBase(String qName,
                   NodeBase parent,
                   ParseContext context,
                   boolean mayHaveChildren)
Method Detail

getNode

public final NodeBase getNode()
Specified by:
getNode in class AbstractInstruction
Returns:
the node this instruction belongs to

insert

public void insert(NodeBase node)
            throws SAXParseException
Insert a new node as a child of this element

Parameters:
node - the node to be inserted
Throws:
SAXParseException

setEndLocation

public final void setEndLocation(ParseContext context)
Notify this node about its end location (taken from ParseContext.locator in the context parameter)

Parameters:
context - the current parse context

compile

public boolean compile(int pass,
                       ParseContext context)
                throws SAXException
This method may be overwritten to perform compilation tasks (for example optimization) on this node. compile will be called with a parameter 0 directly after parsing the node, i.e. after parsing all children. The invocation with bigger pass parameters happens not before the whole transformation sheet has been completely parsed.

Parameters:
pass - the number of invocations already performed on this node
context - the parse context
Returns:
true if another invocation in the next pass is necessary, false if the compiling is complete. This instance returns false.
Throws:
SAXException

mayDropEnd

protected final void mayDropEnd()
Removes (if possible) the end node (nodeEnd) of this instruction from the execution chain. May be invoked from compile(int, ParseContext) of concrete instructions only if processEnd(Context) hasn't been overridden.


declareVariable

protected final void declareVariable(String name)
Store the name of a variable as local for this node.

Parameters:
name - the variable name

processable

public boolean processable()
Returns:
true if process(net.sf.joost.stx.Context) can be invoked on this node, and false otherwise

process

public short process(Context context)
              throws SAXException
Save local variables if needed.

Specified by:
process in class AbstractInstruction
Parameters:
context - the current context
Returns:
Constants.PR_CONTINUE
Throws:
SAXException - if an error occurs (in a derived class)

processEnd

protected short processEnd(Context context)
                    throws SAXException
Called when the end tag will be processed. This instance removes local variables declared in this node.

Parameters:
context - the current context
Returns:
Constants.PR_CONTINUE
Throws:
SAXException - if an error occurs (in a derived class)

getNodeEnd

public final AbstractInstruction getNodeEnd()
Getter for nodeEnd used by Processor.processEvent().

Returns:
a final ref on AbstractInstruction

onDeepCopy

protected void onDeepCopy(AbstractInstruction copy,
                          HashMap copies)
Description copied from class: AbstractInstruction
Callback that will be called when a clone of this instance has been created. To be overridden in subclasses.

Overrides:
onDeepCopy in class AbstractInstruction
Parameters:
copy - the created clones
copies - the map of already copied objects

toString

public String toString()
Overrides:
toString in class Object