Class XmlSelectorWrapper
- java.lang.Object
-
- org.beanio.internal.util.TreeNode<Component>
-
- org.beanio.internal.parser.Component
-
- org.beanio.internal.parser.ParserComponent
-
- org.beanio.internal.parser.format.xml.XmlSelectorWrapper
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Iterable<Component>,XmlNode,Parser,Selector,Replicateable
public class XmlSelectorWrapper extends ParserComponent implements Selector, XmlNode
- Since:
- 2.0
-
-
Field Summary
-
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
Constructors Constructor Description XmlSelectorWrapper()Constructs a newXmlSelectorWrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearValue(ParsingContext context)Clears the current property value.Selectorclose(ParsingContext context)Checks for any unsatisfied components before the stream is closed.org.w3c.dom.DocumentcreateBaseDocument()Creates a DOM made up of allXmlSelectorWrapperdescendants that wrap a group or record.intgetCount(ParsingContext context)Returns the number of times this component was matched within the current iteration of its parent component.intgetDepth()protected java.lang.StringgetKey(java.lang.String namespace, java.lang.String name)Returns a Map key for accessing state information for this Node.java.lang.StringgetLocalName()Returns the XML local name for this node.intgetMaxOccurs()Returns the maximum number of occurrences of this component (within the context of its parent).intgetMinOccurs()Returns the minimum number of occurrences of this component (within the context of its parent).java.lang.StringgetNamespace()Returns the namespace of this node.intgetOrder()Returns the order of this component (within the context of its parent).java.lang.StringgetPrefix()Returns the namespace prefix for marshaling this node, ornullif the namespace should override the default namespace.PropertygetProperty()Returns thePropertymapped to this component, or null if there is no property mapping.intgetSize()Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.intgetType()Returns the XML node type.java.lang.ObjectgetValue(ParsingContext context)Returns the unmarshalled property value.booleanhasContent(ParsingContext context)Returns whether this parser or any of its descendant have content for marshalling.booleanisGroup()booleanisIdentifier()Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.booleanisMaxOccursReached(ParsingContext context)Returns whether this component has reached its maximum occurrences.booleanisNamespaceAware()Returnstrueif a namespace was configured for this node, and is therefore used to unmarshal and marshal the node.booleanisNillable()Returns whether this node is nillable.booleanisOptional()Returns whether this node must exist during unmarshalling.booleanisRecordGroup()Returns whether this component is a record group.booleanisRepeating()Returns whether this node may repeat in the context of its immediate parent.booleanmarshal(MarshallingContext context)Marshals a record.SelectormatchAny(UnmarshallingContext context)Finds a parser that matches the input record.booleanmatches(UnmarshallingContext context)Returns whether this parser and its children match a record being unmarshalled.SelectormatchNext(MarshallingContext context)Finds a parser for marshalling a bean object.SelectormatchNext(UnmarshallingContext context)Finds a parser for unmarshalling a record based on the current state of the stream.voidregisterLocals(java.util.Set<ParserLocal<?>> locals)Called by a stream to register variables stored in the parsing context.voidreset(ParsingContext context)Resets the component count of this Selector's children.voidrestoreState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)Restores a Map of previously stored state information.voidsetCount(ParsingContext context, int count)Sets the number of times this component was matched within the current iteration of its parent component.voidsetDepth(int depth)voidsetGroup(boolean group)voidsetLocalName(java.lang.String localName)voidsetNamespace(java.lang.String namespace)voidsetNamespaceAware(boolean namespaceAware)voidsetPrefix(java.lang.String prefix)voidsetValue(ParsingContext context, java.lang.Object value)Sets the property value for marshaling.voidskip(UnmarshallingContext context)Skips a record or group of records.protected voidtoParamString(java.lang.StringBuilder s)Called byTreeNode.toString()to append node parameters to the output.booleanunmarshal(UnmarshallingContext context)Unmarshals a record.voidupdateState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.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, isDescendant, iterator, print, print, setName, size, sort, toString, updateReferences
-
-
-
-
Method Detail
-
createBaseDocument
public org.w3c.dom.Document createBaseDocument()
Creates a DOM made up of allXmlSelectorWrapperdescendants that wrap a group or record.- Returns:
- the created
Document
-
marshal
public boolean marshal(MarshallingContext context) throws java.io.IOException
Description copied from interface:ParserMarshals a record.- Specified by:
marshalin interfaceParser- Parameters:
context- theMarshallingContext- Returns:
- whether a value was marshalled
- Throws:
java.io.IOException- if an I/O error occurs
-
unmarshal
public boolean unmarshal(UnmarshallingContext context)
Description copied from interface:ParserUnmarshals a record.- Specified by:
unmarshalin interfaceParser- Parameters:
context- theUnmarshallingContext- Returns:
trueif this component was present in the unmarshalled record, orfalseotherwise
-
skip
public void skip(UnmarshallingContext context)
Description copied from interface:SelectorSkips a record or group of records.- Specified by:
skipin interfaceSelector- Parameters:
context- theUnmarshallingContext
-
matchNext
public Selector matchNext(MarshallingContext context)
Description copied from interface:SelectorFinds 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:
matchNextin interfaceSelector- Parameters:
context- theMarshallingContext- Returns:
- the matched
Selectorfor marshalling the bean object
-
matchNext
public Selector matchNext(UnmarshallingContext context)
Description copied from interface:SelectorFinds a parser for unmarshalling a record based on the current state of the stream.- Specified by:
matchNextin interfaceSelector- Parameters:
context- theUnmarshallingContext- Returns:
- the matched
Selectorfor unmarshalling the record
-
matchAny
public Selector matchAny(UnmarshallingContext context)
Description copied from interface:SelectorFinds a parser that matches the input record. This method is invoked whenSelector.matchNext(UnmarshallingContext)returns null, in order to differentiate between unexpected and unidentified record types.- Specified by:
matchAnyin interfaceSelector- Parameters:
context- theUnmarshallingContext- Returns:
- the matched
Selector
-
matches
public boolean matches(UnmarshallingContext context)
Description copied from interface:ParserReturns whether this parser and its children match a record being unmarshalled.- Specified by:
matchesin interfaceParser- Parameters:
context- theUnmarshallingContext- Returns:
- true if matched, false otherwise
-
updateState
public void updateState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Updates a Map with the current state of the Marshaller. Used for creating restartable Writers for Spring Batch.- Specified by:
updateStatein interfaceSelector- Parameters:
namespace- a String to prefix all state keys withstate- the Map to update with the latest statecontext- theParsingContext- Since:
- 1.2
-
restoreState
public void restoreState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Restores a Map of previously stored state information. Used for restarting XML writers from Spring Batch.- Specified by:
restoreStatein interfaceSelector- Parameters:
namespace- a String to prefix all state keys withstate- the Map containing the state to restorecontext- theParsingContext- Since:
- 1.2
-
getKey
protected java.lang.String getKey(java.lang.String namespace, java.lang.String name)Returns a Map key for accessing state information for this Node.- Parameters:
namespace- the assigned namespace for the keyname- the state information to access- Returns:
- the fully qualified key
-
getValue
public java.lang.Object getValue(ParsingContext context)
Description copied from interface:ParserReturns the unmarshalled property value.- Specified by:
getValuein interfaceParser- Parameters:
context- theParsingContext- Returns:
- the property value
-
setValue
public void setValue(ParsingContext context, java.lang.Object value)
Description copied from interface:ParserSets the property value for marshaling.- Specified by:
setValuein interfaceParser- Parameters:
context- theParsingContextvalue- the property value
-
getSize
public int getSize()
Description copied from interface:ParserReturns 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.
-
close
public Selector close(ParsingContext context)
Description copied from interface:SelectorChecks for any unsatisfied components before the stream is closed.- Specified by:
closein interfaceSelector- Parameters:
context- theParsingContext- Returns:
- the first unsatisfied node
-
reset
public void reset(ParsingContext context)
Description copied from interface:SelectorResets the component count of this Selector's children.- Specified by:
resetin interfaceSelector- Parameters:
context- theParsingContext
-
getCount
public int getCount(ParsingContext context)
Description copied from interface:SelectorReturns the number of times this component was matched within the current iteration of its parent component.- Specified by:
getCountin interfaceSelector- Parameters:
context- theParsingContext- Returns:
- the match count
-
setCount
public void setCount(ParsingContext context, int count)
Description copied from interface:SelectorSets the number of times this component was matched within the current iteration of its parent component.- Specified by:
setCountin interfaceSelector- Parameters:
context- theParsingContextcount- the new match count
-
getMinOccurs
public int getMinOccurs()
Description copied from interface:SelectorReturns the minimum number of occurrences of this component (within the context of its parent).- Specified by:
getMinOccursin interfaceSelector- Returns:
- the minimum occurrences
-
getMaxOccurs
public int getMaxOccurs()
Description copied from interface:SelectorReturns the maximum number of occurrences of this component (within the context of its parent).- Specified by:
getMaxOccursin interfaceSelector- Returns:
- the maximum occurrences
-
getOrder
public int getOrder()
Description copied from interface:SelectorReturns the order of this component (within the context of its parent).
-
isMaxOccursReached
public boolean isMaxOccursReached(ParsingContext context)
Description copied from interface:SelectorReturns whether this component has reached its maximum occurrences.- Specified by:
isMaxOccursReachedin interfaceSelector- Parameters:
context- theParsingContext- Returns:
- true if maximum occurrences has been reached
-
clearValue
public void clearValue(ParsingContext context)
Description copied from interface:ParserClears the current property value.- Specified by:
clearValuein interfaceParser- Parameters:
context- theParsingContext
-
isIdentifier
public boolean isIdentifier()
Description copied from interface:ParserReturns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.- Specified by:
isIdentifierin interfaceParser- Returns:
- true if this parser or any descendant is used to identify a record
-
isGroup
public boolean isGroup()
-
setGroup
public void setGroup(boolean group)
-
isOptional
public boolean isOptional()
Description copied from interface:ParserReturns whether this node must exist during unmarshalling.- Specified by:
isOptionalin interfaceParser- Returns:
- true if this node is optional during unmarshalling, false otherwise
-
getLocalName
public java.lang.String getLocalName()
Description copied from interface:XmlNodeReturns the XML local name for this node.- Specified by:
getLocalNamein interfaceXmlNode- Returns:
- the XML local name
-
setLocalName
public void setLocalName(java.lang.String localName)
-
getNamespace
public java.lang.String getNamespace()
Description copied from interface:XmlNodeReturns the namespace of this node. If there is no namespace for this node, or this node is not namespace aware,nullis returned.- Specified by:
getNamespacein interfaceXmlNode- Returns:
- the XML namespace of this node
-
setNamespace
public void setNamespace(java.lang.String namespace)
- Parameters:
namespace-
-
getPrefix
public java.lang.String getPrefix()
Description copied from interface:XmlNodeReturns the namespace prefix for marshaling this node, ornullif the namespace should override the default namespace.
-
setPrefix
public void setPrefix(java.lang.String prefix)
- Parameters:
prefix-
-
isNamespaceAware
public boolean isNamespaceAware()
Description copied from interface:XmlNodeReturnstrueif a namespace was configured for this node, and is therefore used to unmarshal and marshal the node.- Specified by:
isNamespaceAwarein interfaceXmlNode- Returns:
trueif 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:XmlNodeReturns the XML node type.- Specified by:
getTypein interfaceXmlNode- Returns:
- one of
XmlNode.XML_TYPE_NONE,XmlNode.XML_TYPE_ELEMENT,XmlNode.XML_TYPE_ATTRIBUTE, orXmlNode.XML_TYPE_TEXT
-
isNillable
public boolean isNillable()
Description copied from interface:XmlNodeReturns whether this node is nillable.- Specified by:
isNillablein interfaceXmlNode- Returns:
trueif this node is nillable
-
isRepeating
public boolean isRepeating()
Description copied from interface:XmlNodeReturns whether this node may repeat in the context of its immediate parent.- Specified by:
isRepeatingin interfaceXmlNode- Returns:
- true if this node repeats, false otherwise
-
getProperty
public Property getProperty()
Description copied from interface:SelectorReturns thePropertymapped to this component, or null if there is no property mapping.- Specified by:
getPropertyin interfaceSelector- Returns:
- the
Propertymapped to this component
-
hasContent
public boolean hasContent(ParsingContext context)
Description copied from interface:ParserReturns whether this parser or any of its descendant have content for marshalling.- Specified by:
hasContentin interfaceParser- Parameters:
context- theParsingContext- Returns:
- true if there is content for marshalling, false otherwise
-
isRecordGroup
public boolean isRecordGroup()
Description copied from interface:SelectorReturns whether this component is a record group.- Specified by:
isRecordGroupin interfaceSelector- 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(java.util.Set<ParserLocal<?>> locals)
Description copied from class:ComponentCalled 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:
registerLocalsin classComponent- Parameters:
locals- set of local variables
-
toParamString
protected void toParamString(java.lang.StringBuilder s)
Description copied from class:TreeNodeCalled byTreeNode.toString()to append node parameters to the output.- Overrides:
toParamStringin classTreeNode<Component>- Parameters:
s- the output to append
-
-