org.milyn.delivery.sax
Class SAXElement

java.lang.Object
  extended by org.milyn.delivery.sax.SAXElement

public class SAXElement
extends Object

Element details as described by the SAX even model API.

SAXVisitor implementations will be passed an instance of this class for each of the event methods of SAXVisitor implementations.

Element Writing/Serialization

Each SAXElement instance has a writer set on it. SAXVisitor implementations can take care of serializing the elements at which they are targeted themselves. Alternatively, they can use the WriterUtil class.

SAXVisitor implementations can also control the serialization of their "child elements" by setting the writter on the SAXElement instance they receive. This works because Smooks passes the writer instance that's set on a SAXElement instance to all of the SAXElement instances created for child elements.

Only one SAXVisitor can have access to the writer for any individual SAXElement. The first visitor to request access to the writer via the getWriter(SAXVisitor) method "owns" the writer for that element. Any other visitors requesting access to get or change the writer will result in a SAXWriterAccessException being thrown. In this situation, you need to restructure the offending Smooks configuration and eliminate one of the visitors attempting to gain access to the writer. If developing a new visitor, you probably need to change the visitor to also implement the SAXVisitBefore interface and use that event method to acquire ownership of the element writer through a call to getWriter(SAXVisitor).

Author:
tom.fennelly@gmail.com

Constructor Summary
SAXElement(QName name, Attributes attributes, SAXElement parent)
          Public constructor.
SAXElement(String namespaceURI, String localName, String qName, Attributes attributes, SAXElement parent)
          Public constructor.
 
Method Summary
 void accumulateText()
          Turn on text accumulation for this SAXElement.
 boolean equals(Object obj)
           
 String getAttribute(String attribute)
          Get the named attribute from this element.
 String getAttribute(String namespaceURI, String attribute)
          Get the named attribute from this element.
 Attributes getAttributes()
          Get the element attributes.
 Object getCache()
          Deprecated. Use getCache(SAXVisitor).
 Object getCache(SAXVisitor visitor)
          Get the element cache object.
 QName getName()
          Get the element naming details.
 SAXElement getParent()
          Get parent element.
 List<SAXText> getText()
          Get the child text list associated with this SAXElement.
 String getTextContent()
          Get the SAXText objects associated with this SAXElement, as an accumulated String.
 Writer getWriter(SAXVisitor visitor)
          Get the writer to which this element should be writen to.
 int hashCode()
           
 boolean isWriterOwner(SAXVisitor visitor)
          Is the supplied SAXVisitor the owner of the Writer associated with this SAXElement instance.
 void setAttributes(Attributes attributes)
          Set the element attributes.
 void setCache(Object cache)
          Deprecated. Use setCache(SAXVisitor, Object).
 void setCache(SAXVisitor visitor, Object cache)
          Set the element cache object.
 void setName(QName name)
          Set the naming details for the Element.
 void setParent(SAXElement parent)
          Set parent element.
 void setWriter(Writer writer, SAXVisitor visitor)
          Set the writer to which this element should be writen to.
 Element toDOMElement(Document document)
          Create a DOM Element instance from this SAXElement instance.
static QName toQName(String namespaceURI, String localName, String qName)
          Create a QName instance from the supplied element naming parameters.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SAXElement

public SAXElement(String namespaceURI,
                  String localName,
                  String qName,
                  Attributes attributes,
                  SAXElement parent)
Public constructor.

Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
parent - Parent element, or null if the element is the document root element.

SAXElement

public SAXElement(QName name,
                  Attributes attributes,
                  SAXElement parent)
Public constructor.

Parameters:
name - The element QName.
attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
parent - Parent element, or null if the element is the document root element.
Method Detail

toQName

public static QName toQName(String namespaceURI,
                            String localName,
                            String qName)
Create a QName instance from the supplied element naming parameters.

Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
Returns:
A QName instance representing the element named by the supplied parameters.

accumulateText

public void accumulateText()
Turn on text accumulation for this SAXElement.

For performance reasons, Text accumulation is not on by default.


getText

public List<SAXText> getText()
Get the child text list associated with this SAXElement.

Returns:
The child text list associated with this SAXElement, or null if this SAXElement is not accumulating text.
See Also:
accumulateText()

getTextContent

public String getTextContent()
                      throws SmooksException
Get the SAXText objects associated with this SAXElement, as an accumulated String.

This method will produce a string containing all TextType SAXText objects associated with this SAXElement. If you need to filter out specific TextType SAXText objects, use the getText() method and manually produce a String.

Returns:
The SAXText objects associated with this SAXElement, as an accumulated String.
Throws:
SmooksException - This SAXElement instance does not have text accumulation turned on.
See Also:
accumulateText()

getWriter

public Writer getWriter(SAXVisitor visitor)
                 throws SAXWriterAccessException
Get the writer to which this element should be writen to.

See element writing.

Parameters:
visitor - The visitor requesting access to element writer.
Returns:
The element writer.
Throws:
SAXWriterAccessException - Invalid access request for the element writer. See element writing.

setWriter

public void setWriter(Writer writer,
                      SAXVisitor visitor)
               throws SAXWriterAccessException
Set the writer to which this element should be writen to.

See element writing.

Parameters:
writer - The element writer.
visitor - The visitor requesting to set the element writer.
Throws:
SAXWriterAccessException - Invalid access request for the element writer. See element writing.

isWriterOwner

public boolean isWriterOwner(SAXVisitor visitor)
Is the supplied SAXVisitor the owner of the Writer associated with this SAXElement instance.

See element writing.

Parameters:
visitor - The visitor being checked.
Returns:
True if the SAXVisitor owns the Writer associated with this SAXElement instance, otherwise false.

getName

public QName getName()
Get the element naming details.

Returns:
Element naming details.

setName

public void setName(QName name)
Set the naming details for the Element.

Parameters:
name - The element naming details.

getAttributes

public Attributes getAttributes()
Get the element attributes.

Returns:
Element attributes.

setAttributes

public void setAttributes(Attributes attributes)
Set the element attributes.

Parameters:
attributes - The element attributes.

getAttribute

public String getAttribute(String attribute)
Get the named attribute from this element.

Parameters:
attribute - The attribute name.
Returns:
The attribute value, or an empty string if the attribute is not specified.

getAttribute

public String getAttribute(String namespaceURI,
                           String attribute)
Get the named attribute from this element.

Parameters:
namespaceURI - The namespace URI of the required attribute.
attribute - The attribute name.
Returns:
The attribute value, or an empty string if the attribute is not specified.

getCache

public Object getCache()
Deprecated. Use getCache(SAXVisitor).

Get the element cache object.

Returns:
The element cache Object.

setCache

public void setCache(Object cache)
Deprecated. Use setCache(SAXVisitor, Object).

Set the element cache object.

Parameters:
cache - The element cache Object.

getCache

public Object getCache(SAXVisitor visitor)
Get the element cache object.

Parameters:
visitor - The SAXElement instance associated with the cache object.
Returns:
The element cache Object.

setCache

public void setCache(SAXVisitor visitor,
                     Object cache)
Set the element cache object.

Parameters:
visitor - The SAXElement instance to which the cache object is to be associated.
cache - The element cache Object.

getParent

public SAXElement getParent()
Get parent element.

Returns:
Parent element, or null if it's the documnent root.

setParent

public void setParent(SAXElement parent)
Set parent element.

Parameters:
parent - Parent element, or null if it's the documnent root.

toString

public String toString()
Overrides:
toString in class Object

equals

public final boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

toDOMElement

public Element toDOMElement(Document document)
Create a DOM Element instance from this SAXElement instance.

Parameters:
document - The document to use to create the DOM Element.
Returns:
The DOM Element.


Copyright © 2009. All Rights Reserved.