BeanIO 2.0.4

org.beanio.internal.parser.format.xml
Class XmlSelectorWrapper

java.lang.Object
  extended by org.beanio.internal.util.TreeNode<Component>
      extended by org.beanio.internal.parser.Component
          extended by org.beanio.internal.parser.ParserComponent
              extended by org.beanio.internal.parser.format.xml.XmlSelectorWrapper
All Implemented Interfaces:
Cloneable, Iterable<Component>, XmlNode, Parser, Selector, Replicateable

public class XmlSelectorWrapper
extends ParserComponent
implements Selector, XmlNode

Since:
2.0
Author:
Kevin Seim

Field Summary
 
Fields inherited from interface org.beanio.internal.parser.Selector
COUNT_KEY
 
Fields inherited from interface org.beanio.internal.parser.format.xml.XmlNode
XML_TYPE_ATTRIBUTE, XML_TYPE_ELEMENT, XML_TYPE_NONE, XML_TYPE_TEXT
 
Constructor Summary
XmlSelectorWrapper()
          Constructs a new XmlSelectorWrapper.
 
Method Summary
 void clearValue(ParsingContext context)
          Clears the current property value.
 Selector close(ParsingContext context)
          Checks for any unsatisfied components before the stream is closed.
 Document createBaseDocument()
          Creates a DOM made up of all XmlSelectorWrapper descendants that wrap a group or record.
 int getCount(ParsingContext context)
          Returns the number of times this component was matched within the current iteration of its parent component.
 int getDepth()
           
protected  String getKey(String namespace, String name)
          Returns a Map key for accessing state information for this Node.
 String getLocalName()
          Returns the XML local name for this node.
 int getMaxOccurs()
          Returns the maximum number of occurrences of this component (within the context of its parent).
 int getMinOccurs()
          Returns the minimum number of occurrences of this component (within the context of its parent).
 String getNamespace()
          Returns the namespace of this node.
 int getOrder()
          Returns the order of this component (within the context of its parent).
 String getPrefix()
          Returns the namespace prefix for marshaling this node, or null if the namespace should override the default namespace.
 Property getProperty()
          Returns the Property mapped to this component, or null if there is no property mapping.
 int getSize()
          Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.
 int getType()
          Returns the XML node type.
 Object getValue(ParsingContext context)
          Returns the unmarshalled property value.
 boolean hasContent(ParsingContext context)
          Returns whether this parser or any of its descendant have content for marshalling.
 boolean isGroup()
           
 boolean isIdentifier()
          Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.
 boolean isLazy()
          Returns whether this node must exist during unmarshalling.
 boolean isMaxOccursReached(ParsingContext context)
          Returns whether this component has reached its maximum occurrences.
 boolean isNamespaceAware()
          Returns true if a namespace was configured for this node, and is therefore used to unmarshal and marshal the node.
 boolean isNillable()
          Returns whether this node is nillable.
 boolean isRecordGroup()
          Returns whether this component is a record group.
 boolean isRepeating()
          Returns whether this node may repeat in the context of its immediate parent.
 boolean marshal(MarshallingContext context)
          Marshals a record.
 Selector matchAny(UnmarshallingContext context)
          Finds a parser that matches the input record.
 boolean matches(UnmarshallingContext context)
          Returns whether this parser and its children match a record being unmarshalled.
 Selector matchNext(MarshallingContext context)
          Finds a parser for marshalling a bean object.
 Selector matchNext(UnmarshallingContext context)
          Finds a parser for unmarshalling a record based on the current state of the stream.
 void registerLocals(Set<ParserLocal<?>> locals)
          Called by a stream to register variables stored in the parsing context.
 void reset(ParsingContext context)
          Resets the component count of this Selector's children.
 void restoreState(ParsingContext context, String namespace, Map<String,Object> state)
          Restores a Map of previously stored state information.
 void setCount(ParsingContext context, int count)
          Sets the number of times this component was matched within the current iteration of its parent component.
 void setDepth(int depth)
           
 void setGroup(boolean group)
           
 void setLocalName(String localName)
           
 void setNamespace(String namespace)
           
 void setNamespaceAware(boolean namespaceAware)
           
 void setPrefix(String prefix)
           
 void setValue(ParsingContext context, Object value)
          Sets the property value for marshaling.
 void skip(UnmarshallingContext context)
          Skips a record or group of records.
protected  void toParamString(StringBuilder s)
          Called by TreeNode.toString() to append node parameters to the output.
 boolean unmarshal(UnmarshallingContext context)
          Unmarshals a record.
 void updateState(ParsingContext context, String namespace, Map<String,Object> state)
          Updates a Map with the current state of the Marshaller.
 
Methods inherited from class org.beanio.internal.parser.ParserComponent
isSupportedChild
 
Methods inherited from class org.beanio.internal.util.TreeNode
add, clone, find, getChildren, getFirst, getName, iterator, print, setName, size, sort, toString, updateReferences
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.beanio.internal.parser.Parser
getName
 

Constructor Detail

XmlSelectorWrapper

public XmlSelectorWrapper()
Constructs a new XmlSelectorWrapper.

Method Detail

createBaseDocument

public Document createBaseDocument()
Creates a DOM made up of all XmlSelectorWrapper descendants that wrap a group or record.

Returns:
the created Document

marshal

public boolean marshal(MarshallingContext context)
                throws IOException
Description copied from interface: Parser
Marshals a record.

Specified by:
marshal in interface Parser
Parameters:
context - the MarshallingContext
Returns:
whether a value was marshalled
Throws:
IOException - if an I/O error occurs

unmarshal

public boolean unmarshal(UnmarshallingContext context)
Description copied from interface: Parser
Unmarshals a record.

Specified by:
unmarshal in interface Parser
Parameters:
context - the UnmarshallingContext
Returns:
true if this component was present in the unmarshalled record, or false otherwise

skip

public void skip(UnmarshallingContext context)
Description copied from interface: Selector
Skips a record or group of records.

Specified by:
skip in interface Selector
Parameters:
context - the UnmarshallingContext

matchNext

public Selector matchNext(MarshallingContext context)
Description copied from interface: Selector
Finds a parser for marshalling a bean object. If matched by this Selector, the method should set the bean object on the property tree and return itself.

Specified by:
matchNext in interface Selector
Parameters:
context - the MarshallingContext
Returns:
the matched Selector for marshalling the bean object

matchNext

public Selector matchNext(UnmarshallingContext context)
Description copied from interface: Selector
Finds a parser for unmarshalling a record based on the current state of the stream.

Specified by:
matchNext in interface Selector
Parameters:
context - the UnmarshallingContext
Returns:
the matched Selector for unmarshalling the record

matchAny

public Selector matchAny(UnmarshallingContext context)
Description copied from interface: Selector
Finds a parser that matches the input record. This method is invoked when Selector.matchNext(UnmarshallingContext) returns null, in order to differentiate between unexpected and unidentified record types.

Specified by:
matchAny in interface Selector
Parameters:
context - the UnmarshallingContext
Returns:
the matched Selector

matches

public boolean matches(UnmarshallingContext context)
Description copied from interface: Parser
Returns whether this parser and its children match a record being unmarshalled.

Specified by:
matches in interface Parser
Parameters:
context - the UnmarshallingContext
Returns:
true if matched, false otherwise

updateState

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

Specified by:
updateState in interface Selector
Parameters:
namespace - a String to prefix all state keys with
state - the Map to update with the latest state
context - the ParsingContext
Since:
1.2

restoreState

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

Specified by:
restoreState in interface Selector
Parameters:
namespace - a String to prefix all state keys with
state - the Map containing the state to restore
context - the ParsingContext
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

getValue

public Object getValue(ParsingContext context)
Description copied from interface: Parser
Returns the unmarshalled property value.

Specified by:
getValue in interface Parser
Parameters:
context - the ParsingContext
Returns:
the property value

setValue

public void setValue(ParsingContext context,
                     Object value)
Description copied from interface: Parser
Sets the property value for marshaling.

Specified by:
setValue in interface Parser
Parameters:
context - the ParsingContext
value - the property value

getSize

public int getSize()
Description copied from interface: Parser
Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.

The concept of size is dependent on the stream format. The size of an element in a fixed length stream format is determined by the length of the element in characters, while other stream formats calculate size based on the number of fields. Some stream formats, such as XML, may ignore size settings.

Specified by:
getSize in interface Parser
Returns:
the size of this parser element

close

public Selector close(ParsingContext context)
Description copied from interface: Selector
Checks for any unsatisfied components before the stream is closed.

Specified by:
close in interface Selector
Parameters:
context - the ParsingContext
Returns:
the first unsatisfied node

reset

public void reset(ParsingContext context)
Description copied from interface: Selector
Resets the component count of this Selector's children.

Specified by:
reset in interface Selector
Parameters:
context - the ParsingContext

getCount

public int getCount(ParsingContext context)
Description copied from interface: Selector
Returns the number of times this component was matched within the current iteration of its parent component.

Specified by:
getCount in interface Selector
Parameters:
context - the ParsingContext
Returns:
the match count

setCount

public void setCount(ParsingContext context,
                     int count)
Description copied from interface: Selector
Sets the number of times this component was matched within the current iteration of its parent component.

Specified by:
setCount in interface Selector
Parameters:
context - the ParsingContext
count - the new match count

getMinOccurs

public int getMinOccurs()
Description copied from interface: Selector
Returns the minimum number of occurrences of this component (within the context of its parent).

Specified by:
getMinOccurs in interface Selector
Returns:
the minimum occurrences

getMaxOccurs

public int getMaxOccurs()
Description copied from interface: Selector
Returns the maximum number of occurrences of this component (within the context of its parent).

Specified by:
getMaxOccurs in interface Selector
Returns:
the maximum occurrences

getOrder

public int getOrder()
Description copied from interface: Selector
Returns the order of this component (within the context of its parent).

Specified by:
getOrder in interface Selector
Returns:
the component order

isMaxOccursReached

public boolean isMaxOccursReached(ParsingContext context)
Description copied from interface: Selector
Returns whether this component has reached its maximum occurrences.

Specified by:
isMaxOccursReached in interface Selector
Parameters:
context - the ParsingContext
Returns:
true if maximum occurrences has been reached

clearValue

public void clearValue(ParsingContext context)
Description copied from interface: Parser
Clears the current property value.

Specified by:
clearValue in interface Parser
Parameters:
context - the ParsingContext

isIdentifier

public boolean isIdentifier()
Description copied from interface: Parser
Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.

Specified by:
isIdentifier in interface Parser
Returns:
true if this parser or any descendant is used to identify a record

isGroup

public boolean isGroup()

setGroup

public void setGroup(boolean group)

isLazy

public boolean isLazy()
Description copied from interface: Parser
Returns whether this node must exist during unmarshalling.

Specified by:
isLazy in interface Parser
Returns:
true if this node is optional during unmarshalling, false otherwise

getLocalName

public String getLocalName()
Description copied from interface: XmlNode
Returns the XML local name for this node.

Specified by:
getLocalName in interface XmlNode
Returns:
the XML local name

setLocalName

public void setLocalName(String localName)

getNamespace

public String getNamespace()
Description copied from interface: XmlNode
Returns the namespace of this node. If there is no namespace for this node, or this node is not namespace aware, null is returned.

Specified by:
getNamespace in interface XmlNode
Returns:
the XML namespace of this node

setNamespace

public void setNamespace(String namespace)
Parameters:
namespace -

getPrefix

public String getPrefix()
Description copied from interface: XmlNode
Returns the namespace prefix for marshaling this node, or null if the namespace should override the default namespace.

Specified by:
getPrefix in interface XmlNode
Returns:
the namespace prefix

setPrefix

public void setPrefix(String prefix)
Parameters:
prefix -

isNamespaceAware

public boolean isNamespaceAware()
Description copied from interface: XmlNode
Returns true if a namespace was configured for this node, and is therefore used to unmarshal and marshal the node.

Specified by:
isNamespaceAware in interface XmlNode
Returns:
true if this node uses a namespace for matching and formatting this node

setNamespaceAware

public void setNamespaceAware(boolean namespaceAware)
Parameters:
namespaceAware -

getType

public int getType()
Description copied from interface: XmlNode
Returns the XML node type.

Specified by:
getType in interface XmlNode
Returns:
one of XmlNode.XML_TYPE_NONE, XmlNode.XML_TYPE_ELEMENT, XmlNode.XML_TYPE_ATTRIBUTE, or XmlNode.XML_TYPE_TEXT

isNillable

public boolean isNillable()
Description copied from interface: XmlNode
Returns whether this node is nillable.

Specified by:
isNillable in interface XmlNode
Returns:
true if this node is nillable

isRepeating

public boolean isRepeating()
Description copied from interface: XmlNode
Returns whether this node may repeat in the context of its immediate parent.

Specified by:
isRepeating in interface XmlNode
Returns:
true if this node repeats, false otherwise

getProperty

public Property getProperty()
Description copied from interface: Selector
Returns the Property mapped to this component, or null if there is no property mapping.

Specified by:
getProperty in interface Selector
Returns:
the Property mapped to this component

hasContent

public boolean hasContent(ParsingContext context)
Description copied from interface: Parser
Returns whether this parser or any of its descendant have content for marshalling.

Specified by:
hasContent in interface Parser
Parameters:
context - the ParsingContext
Returns:
true if there is content for marshalling, false otherwise

isRecordGroup

public boolean isRecordGroup()
Description copied from interface: Selector
Returns whether this component is a record group.

Specified by:
isRecordGroup in interface Selector
Returns:
true if this component is a record group, false otherwise

getDepth

public int getDepth()

setDepth

public void setDepth(int depth)

registerLocals

public void registerLocals(Set<ParserLocal<?>> locals)
Description copied from class: Component
Called by a stream to register variables stored in the parsing context. This method should be overridden by subclasses that need to register one or more parser context variables.

Overrides:
registerLocals in class Component
Parameters:
locals - set of local variables

toParamString

protected void toParamString(StringBuilder s)
Description copied from class: TreeNode
Called by TreeNode.toString() to append node parameters to the output.

Overrides:
toParamString in class TreeNode<Component>
Parameters:
s - the output to append

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim