public class VisitorAdapter extends Object implements Visitor
Visitor
implementations that are
only interested in a subset of the elements within a document.
This implementation will walk the entire tree of elements. Derived classes
need only override the methods of interest. Derived classes should be careful
to always call the super
implementation of the following methods to
ensure they do not break the document walking. Calling super
for all
methods is encouraged.
visit(List)
visitArray(String, List)
visitDocument(String, List)
visitJavaScript(String, String, Document)
As a further aid to Visitor
implementations only interested in the
names of elements, this class will call the visitName(String)
method
for each element visited.
Constructor and Description |
---|
VisitorAdapter()
Creates a new VisitorAdapter.
|
Modifier and Type | Method and Description |
---|---|
void |
visit(List<Element> elements)
Visit the root document.
|
void |
visitArray(String name,
List<Element> elements)
Visits an array of elements.
|
void |
visitBinary(String name,
byte subType,
byte[] data)
Visits a binary element.
|
void |
visitBoolean(String name,
boolean value)
Visits a boolean element.
|
void |
visitDBPointer(String name,
String databaseName,
String collectionName,
ObjectId id)
Visits a deprecated DBPointer element.
|
void |
visitDocument(String name,
List<Element> elements)
Visits a sub-document element.
|
void |
visitDouble(String name,
double value)
Visits a double element.
|
void |
visitInteger(String name,
int value)
Visits a integer (32-bit signed) element.
|
void |
visitJavaScript(String name,
String code)
Visits a JavaScript element.
|
void |
visitJavaScript(String name,
String code,
Document scope)
Visits a JavaScript with Scope element.
|
void |
visitLong(String name,
long value)
Visits a long (64-bit signed) element.
|
void |
visitMaxKey(String name)
Visits a minimum key value element.
|
void |
visitMinKey(String name)
Visits a minimum key value element.
|
void |
visitMongoTimestamp(String name,
long value)
Visits a MongoDB Timestamp element.
|
protected void |
visitName(String name)
Extension point for
Visitor implementation only interested in the
name of the elements. |
void |
visitNull(String name)
Visits a
null valued element. |
void |
visitObjectId(String name,
ObjectId id)
Visits an ObjectId element.
|
void |
visitRegularExpression(String name,
String pattern,
String options)
Visits a regular expression element.
|
void |
visitString(String name,
String value)
Visits a string element.
|
void |
visitSymbol(String name,
String symbol)
Visits a symbol element.
|
void |
visitTimestamp(String name,
long timestamp)
Visits a timestamp element.
|
public void visit(List<Element> elements)
Implementations of Document
may see a significant performance
enhancement if they ensure that the list of elements is the same list.
(Identify check instead of Object.equals(Object)
.
Overridden to iterate over the elements of the document.
public void visitArray(String name, List<Element> elements)
The ArrayElement
implementation ensures that the list of elements
is always the same list. Visitors may use this fact to cache intermediate
results.
Overridden to visit the name of the element and then iterate over the elements of the array.
visitArray
in interface Visitor
name
- The name of the element.elements
- The elements in the array.public void visitBinary(String name, byte subType, byte[] data)
Overridden to visit the name of the element.
visitBinary
in interface Visitor
name
- The name of the element.subType
- The binary data sub type.data
- The binary data.public void visitBoolean(String name, boolean value)
Overridden to visit the name of the element.
visitBoolean
in interface Visitor
name
- The name of the element.value
- The boolean value.public void visitDBPointer(String name, String databaseName, String collectionName, ObjectId id)
Overridden to visit the name of the element.
visitDBPointer
in interface Visitor
name
- The name of the element.databaseName
- The name of the database containing the document.collectionName
- The name of the collection containing the document.id
- The id for the document.public void visitDocument(String name, List<Element> elements)
The DocumentElement
implementation ensures that the list of
elements is always the same list. Visitors may use this fact to cache
intermediate results.
Overridden to visit the name of the element and then iterate over the elements of the document element.
visitDocument
in interface Visitor
name
- The name of the element.elements
- The sub elements of the document.public void visitDouble(String name, double value)
Overridden to visit the name of the element.
visitDouble
in interface Visitor
name
- The name of the element.value
- The double value.public void visitInteger(String name, int value)
Overridden to visit the name of the element.
visitInteger
in interface Visitor
name
- The name of the element.value
- The integer value.public void visitJavaScript(String name, String code)
Overridden to visit the name of the element.
visitJavaScript
in interface Visitor
name
- The name of the element.code
- The java script code.public void visitJavaScript(String name, String code, Document scope)
Overridden to visit the name of the element.
visitJavaScript
in interface Visitor
name
- The name of the element.code
- The java script code.scope
- The scope for the JacaScript code.public void visitLong(String name, long value)
Overridden to visit the name of the element.
public void visitMaxKey(String name)
Overridden to visit the name of the element.
visitMaxKey
in interface Visitor
name
- The name of the element.public void visitMinKey(String name)
Overridden to visit the name of the element.
visitMinKey
in interface Visitor
name
- The name of the element.public void visitMongoTimestamp(String name, long value)
Overridden to visit the name of the element.
visitMongoTimestamp
in interface Visitor
name
- The name of the element.value
- The mongoDB timstamp value.public void visitNull(String name)
null
valued element.
Overridden to visit the name of the element.
public void visitObjectId(String name, ObjectId id)
Overridden to visit the name of the element.
visitObjectId
in interface Visitor
name
- The name of the element.id
- The object id.public void visitRegularExpression(String name, String pattern, String options)
Overridden to visit the name of the element.
visitRegularExpression
in interface Visitor
name
- The name of the element.pattern
- The pattern for the regular expression.options
- The regular expression options. See the BSON specification for
details.public void visitString(String name, String value)
Overridden to visit the name of the element.
visitString
in interface Visitor
name
- The name of the element.value
- The string value.public void visitSymbol(String name, String symbol)
Overridden to visit the name of the element.
visitSymbol
in interface Visitor
name
- The name of the element.symbol
- The symbol value.public void visitTimestamp(String name, long timestamp)
Overridden to visit the name of the element.
visitTimestamp
in interface Visitor
name
- The name of the element.timestamp
- The number of milliseconds since the Unix epoch.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.