Class NativeMaterializer
- All Implemented Interfaces:
TreeGenerator
This class implements both TreeTraversal and TreeGenerator,
allowing it to act as a self-contained transformation engine. It traverses a
source structure using its NodeVisitor capabilities and consumes its
own traversal events via its NodeGenerator implementation to
construct a Object tree in memory.
The class is stateful and designed for a single transformation. It can be
reused by calling the reset() method.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.apicatalog.tree.io.TreeTraversal
TreeTraversal.Context -
Field Summary
FieldsFields inherited from class com.apicatalog.tree.io.TreeTraversal
adapters, currentNode, currentNodeContext, currentNodeType, depth, entryComparator, maxDepth, maxVisited, stack, UNLIMITED_DEPTH, UNLIMITED_NODES, visited -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBegins a new list (or array) structure.voidbeginMap()Begins a new map (or object) structure.voidbeginSet()Begins a new set structure.voidbinaryValue(byte[] node) Adds a binary data value to the current context.voidbooleanValue(boolean node) Adds a boolean value to the current context.voidend()Ends the current map or collection structure.features()static Objectstatic Objectnode(Object node, TreeAdapter adapter) voidAdds a null value to the current context.voidnumericValue(double node) Adds a double-precision floating-point value to the current context.voidnumericValue(long node) Adds a long integer value.voidnumericValue(BigDecimal node) Adds an arbitrary-precision decimal value to the current context.voidnumericValue(BigInteger node) Adds an arbitrary-precision integer value.object()Returns the fully materializedObjectafter a successful traversal.reset()Resets the visitor's internal state, clearing the traversal stack and counters.static Objectscalar(Object node, TreeAdapter adapter) voidstringValue(String node) Adds a string value.structure(Object node, TreeAdapter adapter) The primary entry point for materialization.protected voidInternal dispatcher that places a newly createdObjectinto the correct position within the structure being built.Methods inherited from class com.apicatalog.tree.io.TreeTraversal
adapter, maxDepth, maxDepth, maxVisited, maxVisited, next, next, node, nodeContext, nodeType, root, traverse, traverse, visited
-
Field Details
-
structures
-
object
-
-
Constructor Details
-
NativeMaterializer
public NativeMaterializer()
-
-
Method Details
-
features
- Specified by:
featuresin interfaceTreeGenerator
-
node
- Throws:
TreeIOException
-
node
- Throws:
TreeIOException
-
scalar
- Throws:
TreeIOException
-
structure
The primary entry point for materialization. Traverses the given source node.- Parameters:
node- the source root node to traverseadapter- the adapter for interpreting the source node's structure- Returns:
- the fully materialized object
- Throws:
TreeIOException- if an error occurs during generation
-
object
Returns the fully materializedObjectafter a successful traversal.- Returns:
- the resulting
Object, ornullif traversal has not completed
-
reset
Resets the visitor's internal state, clearing the traversal stack and counters. The visitor can be reused after calling this method, but a new root node must be set usingTreeTraversal.root(Object, TreeAdapter).Clears the partially built structure and the internal builder stack, allowing the instance to be reused for a new materialization.
- Overrides:
resetin classTreeTraversal- Returns:
- this instance, for chaining.
-
nullValue
Adds a null value to the current context.- Specified by:
nullValuein interfaceTreeGenerator- Throws:
TreeIOException- if an I/O error occurs during construction.
-
booleanValue
Adds a boolean value to the current context.- Specified by:
booleanValuein interfaceTreeGenerator- Parameters:
node- the boolean value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
stringValue
Adds a string value. Depending on the context, this could represent a map key, a value associated with a key, or an element in a collection.If the current context is a
PROPERTY_KEY, the string is pushed onto the builder stack to be used as a key. Otherwise, it creates aStringvalue.- Specified by:
stringValuein interfaceTreeGenerator- Parameters:
node- the non-null string value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
numericValue
Adds a long integer value. Depending on the context, this could represent a map key (in formats like CBOR), a value, or a collection element.- Specified by:
numericValuein interfaceTreeGenerator- Parameters:
node- the long value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
numericValue
Adds an arbitrary-precision integer value. Depending on the context, this could represent a map key, a value, or a collection element.- Specified by:
numericValuein interfaceTreeGenerator- Parameters:
node- the non-null BigInteger value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
numericValue
Adds a double-precision floating-point value to the current context.- Specified by:
numericValuein interfaceTreeGenerator- Parameters:
node- the double value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
numericValue
Adds an arbitrary-precision decimal value to the current context.- Specified by:
numericValuein interfaceTreeGenerator- Parameters:
node- the non-null BigDecimal value to add.- Throws:
TreeIOException- if an I/O error occurs during construction.
-
binaryValue
Adds a binary data value to the current context. The specific encoding (e.g., Base64 for JSON, or direct bytes for CBOR) is determined by the underlying implementation.- Specified by:
binaryValuein interfaceTreeGenerator- Parameters:
node- the non-null byte array to add.- Throws:
UnsupportedOperationException- alwaysTreeIOException- if an I/O error occurs during construction.
-
beginMap
Begins a new map (or object) structure. After this call, the generator expects a sequence of key-value pairs.The type of a key is determined by the target format. For formats like JSON, keys are strings added via
Every call to this method must be matched by a corresponding call toTreeGenerator.stringValue(String). For others, like CBOR, keys can also be other types.TreeGenerator.end().- Specified by:
beginMapin interfaceTreeGenerator- Throws:
TreeIOException- if an I/O error occurs during construction.
-
beginList
Begins a new list (or array) structure. An ordered collection that allows duplicates. After this call, subsequent calls are expected to be the elements of the list. Every call to this method must be matched by a corresponding call toTreeGenerator.end().- Specified by:
beginListin interfaceTreeGenerator- Throws:
TreeIOException- if an I/O error occurs during construction.
-
beginSet
Begins a new set structure. An unordered collection of unique elements. After this call, subsequent calls are expected to be the elements of the set. Every call to this method must be matched by a corresponding call toTreeGenerator.end().- Specified by:
beginSetin interfaceTreeGenerator- Throws:
TreeIOException- if an I/O error occurs during construction.
-
end
Ends the current map or collection structure. This call must match a precedingTreeGenerator.beginMap()orTreeGenerator.beginList().Finalizes the current
MaporList, pops it from the stack, builds the finalObject, and attaches it to its parent structure if one exists.- Specified by:
endin interfaceTreeGenerator- Throws:
TreeIOException- if an I/O error occurs during construction.
-
value
Internal dispatcher that places a newly createdObjectinto the correct position within the structure being built.- Parameters:
value- theObjectto place
-