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 Cache Object

This class supports the concept of a "cache" object which can be get and set through the getCache() and setCache(Object) methods. The cache object can be used by SAXVisitor implementations to store information between calls to the SAXVisitor event methods.

Obviously we could have implemented this cache as a straightforward Map, but that forces you to do silly things in situations where you wish to (for example) store a List, or a single Object reference of some other type.

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(String namespaceURI, String localName, String qName, Attributes attributes, SAXElement parent)
          Public constructor.
 
Method Summary
 Attributes getAttributes()
          Get the element attributes.
 Object getCache()
          Get the element cache object.
 QName getName()
          Get the element naming details.
 SAXElement getParent()
          Get parent element.
 Writer getWriter(SAXVisitor visitor)
          Get the writer to which this element should be writen to.
 void setAttributes(Attributes attributes)
          Set the element attributes.
 void setCache(Object cache)
          Set the element cache object.
 void setName(QName name)
          Set the naming details for the Element.
 void setWriter(Writer writer, SAXVisitor visitor)
          Set the writer to which this element should be writen to.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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.
Method Detail

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.

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.

getCache

public Object getCache()
Get the element cache object.

Returns:
The element cache Object.

setCache

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

Parameters:
cache - The element cache Object.

getParent

public SAXElement getParent()
Get parent element.

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008. All Rights Reserved.