BeanIO 1.2.3

org.beanio.parser.xml
Class Marshaller

java.lang.Object
  extended by org.beanio.parser.xml.Marshaller
Direct Known Subclasses:
GroupMarshaller, RecordMarshaller

public abstract class Marshaller
extends Object

Base class for XML group and record node marshallers.

A Marshaller instance implements a linked list of child marshallers and holds a reference to a parent marshaller to form a tree that defines the structure of the XML document being marshalled.

Since:
1.1
Author:
Kevin Seim

Field Summary
protected  int count
           
 
Constructor Summary
Marshaller(Marshaller parent, NodeDefinition definition)
          Constructs a new Marshaller.
 
Method Summary
 void addChild(Marshaller child)
          Adds a child to this marshaler.
abstract  Node createHierarchy(Document document)
          Recursively creates the XML hierarchy of group nodes.
 int getCount()
          Returns the number of times this node has been marshaled.
 Marshaller getFirstChild()
          Returns the first child of this marshaler, or null if this marshaler does not have any children.
protected  String getKey(String namespace, String name)
          Returns a Map key for accessing state information for this Node.
 Marshaller getNextSibling()
          Returns the next sibling to this marshaler, or null if none exists.
 NodeDefinition getNodeDefinition()
          Returns the node definition wrapped by this marshaler.
 Marshaller getParent()
          Returns this marshaler's parent marshaler.
 boolean isMaxOccursReached()
          Returns whether the marshal count of this node has reached the configured maximum occurrences.
 void removeAllChildren()
          Removes all children of this marshaler.
abstract  void reset()
          Resets the occurrences of this node and/or its children.
 void restoreState(String namespace, Map<String,Object> state)
          Restores a Map of previously stored state information.
 void updateState(String namespace, Map<String,Object> state)
          Updates a Map with the current state of the Marshaller.
abstract  boolean write(RecordWriter out, String recordName, Object bean)
          Marshals this node to a RecordWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected int count
Constructor Detail

Marshaller

public Marshaller(Marshaller parent,
                  NodeDefinition definition)
Constructs a new Marshaller.

Parameters:
parent - the parent Marshaller node
definition - the node definition marshaled by this marshaler
Method Detail

getNodeDefinition

public NodeDefinition getNodeDefinition()
Returns the node definition wrapped by this marshaler.

Returns:
the node definition

getCount

public int getCount()
Returns the number of times this node has been marshaled. The count is reset each time its parent group is repeated.

Returns:
the number of times this node has been marshaled

isMaxOccursReached

public boolean isMaxOccursReached()
Returns whether the marshal count of this node has reached the configured maximum occurrences.

Returns:
true if the maximum occurrences of this node has been reached

reset

public abstract void reset()
Resets the occurrences of this node and/or its children.


createHierarchy

public abstract Node createHierarchy(Document document)
Recursively creates the XML hierarchy of group nodes.

Parameters:
document - the document object model to append
Returns:
the parent document node

write

public abstract boolean write(RecordWriter out,
                              String recordName,
                              Object bean)
                       throws IOException
Marshals this node to a RecordWriter.

Parameters:
out - the RecordWriter to write to
recordName - the name of the record to marshal (may be null if unknown)
bean - the record bean to marshal
Returns:
true if the bean was marshal by this node or one of its children, false otherwise
Throws:
IOException - if an I/O error is thrown by the RecordWriter

getParent

public Marshaller getParent()
Returns this marshaler's parent marshaler.

Returns:
the parent marshaler

addChild

public void addChild(Marshaller child)
Adds a child to this marshaler.

Parameters:
child - the child Marshaller to add

getFirstChild

public Marshaller getFirstChild()
Returns the first child of this marshaler, or null if this marshaler does not have any children.

Returns:
the first child of this marshaler

getNextSibling

public Marshaller getNextSibling()
Returns the next sibling to this marshaler, or null if none exists.

Returns:
the next sibling Marshaller to this marshaler

removeAllChildren

public void removeAllChildren()
Removes all children of this marshaler.


updateState

public void updateState(String namespace,
                        Map<String,Object> state)
Updates a Map with the current state of the Marshaller. Used for creating restartable Writers for Spring Batch.

Parameters:
namespace - a String to prefix all state keys with
state - the Map to update with the latest state
Since:
1.2

restoreState

public void restoreState(String namespace,
                         Map<String,Object> state)
Restores a Map of previously stored state information. Used for restarting XML writers from Spring Batch.

Parameters:
namespace - a String to prefix all state keys with
state - the Map containing the state to restore
Since:
1.2

getKey

protected String getKey(String namespace,
                        String name)
Returns a Map key for accessing state information for this Node.

Parameters:
namespace - the assigned namespace for the key
name - the state information to access
Returns:
the fully qualified key

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim