org.milyn.delivery.dom.serialize
Class ContextObjectSerializationUnit

java.lang.Object
  extended by org.milyn.delivery.dom.serialize.ContextObjectSerializationUnit
All Implemented Interfaces:
ContentHandler, SerializationUnit, SAXElementVisitor, SAXVisitAfter, SAXVisitBefore, SAXVisitChildren, SAXVisitor, Visitor

public class ContextObjectSerializationUnit
extends Object
implements SerializationUnit, SAXElementVisitor

ExecutionContext object serializer.

Outputs an object bound to the ExecutionContext. The location of the object (context key) must be specified on the "key" attribute.

Author:
tom.fennelly@gmail.com

Constructor Summary
ContextObjectSerializationUnit()
           
 
Method Summary
static Element createElement(Document ownerDocument, String key)
          Utility method for creating a <context-object/> element.
static String getContextKey(Element element)
           
static boolean isContextObjectElement(Element element)
           
 void onChildElement(SAXElement element, SAXElement childElement, ExecutionContext executionContext)
          Process the onChildElement event for the targeted element.
 void onChildText(SAXElement element, SAXText text, ExecutionContext executionContext)
          Process the onChildText event for the targeted element.
 void visitAfter(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element after visiting its child elements.
 void visitBefore(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element before visiting its child elements.
 boolean writeChildElements()
          Write the child elements of the element this SerializationUnit is being applied to.
 void writeElementCDATA(CDATASection cdata, Writer writer, ExecutionContext executionContext)
          Write element CDATA section.
 void writeElementComment(Comment comment, Writer writer, ExecutionContext executionContext)
          Write element comment.
 void writeElementEnd(Element element, Writer writer, ExecutionContext executionContext)
          Write the element end portion; close the element.
 void writeElementEntityRef(EntityReference entityRef, Writer writer, ExecutionContext executionContext)
          Write element entity reference object.
 void writeElementNode(Node node, Writer writer, ExecutionContext executionContext)
          Write element Node object.
 void writeElementStart(Element element, Writer writer, ExecutionContext executionContext)
          Write the element start portion; the element name and it's attributes.
 void writeElementText(Text text, Writer writer, ExecutionContext executionContext)
          Write element text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextObjectSerializationUnit

public ContextObjectSerializationUnit()
Method Detail

writeElementStart

public void writeElementStart(Element element,
                              Writer writer,
                              ExecutionContext executionContext)
                       throws IOException
Description copied from interface: SerializationUnit
Write the element start portion; the element name and it's attributes.

EG: <a href="http://www.x.com">

Specified by:
writeElementStart in interface SerializationUnit
Parameters:
element - The element start to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

getContextKey

public static String getContextKey(Element element)

writeElementEnd

public void writeElementEnd(Element element,
                            Writer writer,
                            ExecutionContext executionContext)
                     throws IOException
Description copied from interface: SerializationUnit
Write the element end portion; close the element.

EG: </a>

Specified by:
writeElementEnd in interface SerializationUnit
Parameters:
element - The element end to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeElementText

public void writeElementText(Text text,
                             Writer writer,
                             ExecutionContext executionContext)
                      throws IOException
Description copied from interface: SerializationUnit
Write element text.

Specified by:
writeElementText in interface SerializationUnit
Parameters:
text - The Text object to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeElementComment

public void writeElementComment(Comment comment,
                                Writer writer,
                                ExecutionContext executionContext)
                         throws IOException
Description copied from interface: SerializationUnit
Write element comment.

Specified by:
writeElementComment in interface SerializationUnit
Parameters:
comment - The comment o write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeElementEntityRef

public void writeElementEntityRef(EntityReference entityRef,
                                  Writer writer,
                                  ExecutionContext executionContext)
                           throws IOException
Description copied from interface: SerializationUnit
Write element entity reference object.

Specified by:
writeElementEntityRef in interface SerializationUnit
Parameters:
entityRef - The entity reference to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeElementCDATA

public void writeElementCDATA(CDATASection cdata,
                              Writer writer,
                              ExecutionContext executionContext)
                       throws IOException
Description copied from interface: SerializationUnit
Write element CDATA section.

Specified by:
writeElementCDATA in interface SerializationUnit
Parameters:
cdata - The CDATA section to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeElementNode

public void writeElementNode(Node node,
                             Writer writer,
                             ExecutionContext executionContext)
                      throws IOException
Description copied from interface: SerializationUnit
Write element Node object.

Called to write DOM types not covered by the other methods on this interface.

Specified by:
writeElementNode in interface SerializationUnit
Parameters:
node - The node to write.
writer - The writer to be written to.
executionContext - ExecutionContext instance for the delivery context.
Throws:
IOException - Exception writing output.

writeChildElements

public boolean writeChildElements()
Description copied from interface: SerializationUnit
Write the child elements of the element this SerializationUnit is being applied to.

Specified by:
writeChildElements in interface SerializationUnit
Returns:
True if the child elements are to be writen, otherwise false.

createElement

public static Element createElement(Document ownerDocument,
                                    String key)
Utility method for creating a <context-object/> element.

Parameters:
ownerDocument - The owner document.
key - The context key.
Returns:
The <context-object/> element.

isContextObjectElement

public static boolean isContextObjectElement(Element element)

visitBefore

public void visitBefore(SAXElement element,
                        ExecutionContext executionContext)
                 throws SmooksException,
                        IOException
Description copied from interface: SAXVisitBefore
Visit the supplied element before visiting its child elements.

Specified by:
visitBefore in interface SAXVisitBefore
Parameters:
element - The SAX element being visited.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

onChildText

public void onChildText(SAXElement element,
                        SAXText text,
                        ExecutionContext executionContext)
                 throws SmooksException,
                        IOException
Description copied from interface: SAXVisitChildren
Process the onChildText event for the targeted element.

Be careful when caching element data. This is not a DOM.

Specified by:
onChildText in interface SAXVisitChildren
Parameters:
element - The element containing the text (parent). The targeted element.
text - The text.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

onChildElement

public void onChildElement(SAXElement element,
                           SAXElement childElement,
                           ExecutionContext executionContext)
                    throws SmooksException,
                           IOException
Description copied from interface: SAXVisitChildren
Process the onChildElement event for the targeted element.

Be careful when caching element data. This is not a DOM.

Specified by:
onChildElement in interface SAXVisitChildren
Parameters:
element - The element containing the child element (parent). The targeted element.
childElement - The child element just added to the targeted element.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

visitAfter

public void visitAfter(SAXElement element,
                       ExecutionContext executionContext)
                throws SmooksException,
                       IOException
Description copied from interface: SAXVisitAfter
Visit the supplied element after visiting its child elements.

Specified by:
visitAfter in interface SAXVisitAfter
Parameters:
element - The SAX element being visited.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.


Copyright © 2008. All Rights Reserved.