Package org.bson
Class BasicBSONCallback
- java.lang.Object
-
- org.bson.BasicBSONCallback
-
- All Implemented Interfaces:
BSONCallback
- Direct Known Subclasses:
DefaultDBCallback
,JSONCallback
public class BasicBSONCallback extends Object implements BSONCallback
An implementation ofBsonCallback
that creates an instance of BSONObject.
-
-
Constructor Summary
Constructors Constructor Description BasicBSONCallback()
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
_put(String name, Object value)
Puts a new value into the document.Object
arrayDone()
Called the end of the array, and returns the completed array.void
arrayStart()
Signals the start of a BSON array.void
arrayStart(String name)
Signals the start of a BSON array, with its field name.BSONObject
create()
Factory method for creating a new BSONObject.BSONObject
create(boolean array, List<String> path)
Helper method to create either a BSON Object or a BSON List depending upon whether thearray
parameter is true or not.BSONCallback
createBSONCallback()
Factory method for BSONCallbacks.protected BSONObject
createList()
Factory method for creating a new BSON List.protected BSONObject
cur()
Gets the current valueprotected String
curName()
Gets the name of the current fieldObject
get()
Returns the finished top-level Document.void
gotBinary(String name, byte type, byte[] data)
Called when reading a field with aBsonType.BINARY
value.void
gotBinaryArray(String name, byte[] data)
Deprecated.void
gotBoolean(String name, boolean value)
Called when reading a field with aBsonType.BOOLEAN
value.void
gotCode(String name, String code)
Called when reading a field with aBsonType.JAVASCRIPT
value.void
gotCodeWScope(String name, String code, Object scope)
Called when reading a field with aBsonType.JAVASCRIPT_WITH_SCOPE
value.void
gotDate(String name, long millis)
Called when reading a field with aBsonType.DATE_TIME
value.void
gotDBRef(String name, String namespace, ObjectId id)
Invoked whenBSONDecoder
encountered aBsonType.DB_POINTER
type field in a byte sequence.void
gotDecimal128(String name, Decimal128 value)
Called when reading a field with aBsonType.DECIMAL128
value.void
gotDouble(String name, double value)
Called when reading a field with aBsonType.DOUBLE
value.void
gotInt(String name, int value)
Called when reading a field with aBsonType.INT32
value.void
gotLong(String name, long value)
Called when reading a field with aBsonType.INT64
value.void
gotMaxKey(String name)
Called when reading a field with aBsonType.MAX_KEY
value.void
gotMinKey(String name)
Called when reading a field with aBsonType.MIN_KEY
value.void
gotNull(String name)
Called when reading a BSON field that exists but has a null value.void
gotObjectId(String name, ObjectId id)
Called when reading a field with aBsonType.OBJECT_ID
value.void
gotRegex(String name, String pattern, String flags)
Called when reading a field with aBsonType.REGULAR_EXPRESSION
value.void
gotString(String name, String value)
Called when reading a field with aBsonType.STRING
value.void
gotSymbol(String name, String value)
Called when reading a field with aBsonType.SYMBOL
value.void
gotTimestamp(String name, int time, int increment)
Called when reading a field with aBsonType.TIMESTAMP
value.void
gotUndefined(String name)
Called when reading a field with aBsonType.UNDEFINED
value.void
gotUUID(String name, long part1, long part2)
Called when reading a field with aUUID
value.protected boolean
isStackEmpty()
Returns whether this is the top level or notObject
objectDone()
Called at the end of the document/array, and returns this object.void
objectStart()
Signals the start of a BSON document, which usually maps onto some Java object.void
objectStart(String name)
Signals the start of a BSON document, which usually maps onto some Java object.void
reset()
Resets the callback, clearing all state.protected void
setRoot(Object root)
Sets the root document for this position
-
-
-
Method Detail
-
get
public Object get()
Description copied from interface:BSONCallback
Returns the finished top-level Document.- Specified by:
get
in interfaceBSONCallback
- Returns:
- the top level document read from the database.
-
create
public BSONObject create()
Factory method for creating a new BSONObject.- Returns:
- a new BasicBSONObject.
-
createList
protected BSONObject createList()
Factory method for creating a new BSON List.- Returns:
- a new BasicBSONList.
-
createBSONCallback
public BSONCallback createBSONCallback()
Description copied from interface:BSONCallback
Factory method for BSONCallbacks.- Specified by:
createBSONCallback
in interfaceBSONCallback
- Returns:
- a new BSONCallback.
-
create
public BSONObject create(boolean array, List<String> path)
Helper method to create either a BSON Object or a BSON List depending upon whether thearray
parameter is true or not.- Parameters:
array
- set to true to create a new BSON List, otherwise will create a new BSONObjectpath
- a list of field names to navigate to this field in the document- Returns:
- the new BSONObject
-
objectStart
public void objectStart()
Description copied from interface:BSONCallback
Signals the start of a BSON document, which usually maps onto some Java object.- Specified by:
objectStart
in interfaceBSONCallback
-
objectStart
public void objectStart(String name)
Description copied from interface:BSONCallback
Signals the start of a BSON document, which usually maps onto some Java object.- Specified by:
objectStart
in interfaceBSONCallback
- Parameters:
name
- the field name of the document.
-
objectDone
public Object objectDone()
Description copied from interface:BSONCallback
Called at the end of the document/array, and returns this object.- Specified by:
objectDone
in interfaceBSONCallback
- Returns:
- the Object that has been read from this section of the document.
-
arrayStart
public void arrayStart()
Description copied from interface:BSONCallback
Signals the start of a BSON array.- Specified by:
arrayStart
in interfaceBSONCallback
-
arrayStart
public void arrayStart(String name)
Description copied from interface:BSONCallback
Signals the start of a BSON array, with its field name.- Specified by:
arrayStart
in interfaceBSONCallback
- Parameters:
name
- the name of this array field
-
arrayDone
public Object arrayDone()
Description copied from interface:BSONCallback
Called the end of the array, and returns the completed array.- Specified by:
arrayDone
in interfaceBSONCallback
- Returns:
- an Object representing the array that has been read from this section of the document.
-
gotNull
public void gotNull(String name)
Description copied from interface:BSONCallback
Called when reading a BSON field that exists but has a null value.- Specified by:
gotNull
in interfaceBSONCallback
- Parameters:
name
- the name of the field- See Also:
BsonType.NULL
-
gotUndefined
public void gotUndefined(String name)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.UNDEFINED
value.- Specified by:
gotUndefined
in interfaceBSONCallback
- Parameters:
name
- the name of the field- See Also:
BsonType.UNDEFINED
-
gotMinKey
public void gotMinKey(String name)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.MIN_KEY
value.- Specified by:
gotMinKey
in interfaceBSONCallback
- Parameters:
name
- the name of the field
-
gotMaxKey
public void gotMaxKey(String name)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.MAX_KEY
value.- Specified by:
gotMaxKey
in interfaceBSONCallback
- Parameters:
name
- the name of the field
-
gotBoolean
public void gotBoolean(String name, boolean value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.BOOLEAN
value.- Specified by:
gotBoolean
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotDouble
public void gotDouble(String name, double value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.DOUBLE
value.- Specified by:
gotDouble
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotInt
public void gotInt(String name, int value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.INT32
value.- Specified by:
gotInt
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotLong
public void gotLong(String name, long value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.INT64
value.- Specified by:
gotLong
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotDecimal128
public void gotDecimal128(String name, Decimal128 value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.DECIMAL128
value.- Specified by:
gotDecimal128
in interfaceBSONCallback
- Parameters:
name
- the field namevalue
- the Decimal128 field value
-
gotDate
public void gotDate(String name, long millis)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.DATE_TIME
value.- Specified by:
gotDate
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldmillis
- the date and time in milliseconds
-
gotRegex
public void gotRegex(String name, String pattern, String flags)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.REGULAR_EXPRESSION
value.- Specified by:
gotRegex
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldpattern
- the regex patternflags
- the optional flags for the regular expression
-
gotString
public void gotString(String name, String value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.STRING
value.- Specified by:
gotString
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotSymbol
public void gotSymbol(String name, String value)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.SYMBOL
value.- Specified by:
gotSymbol
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldvalue
- the field's value
-
gotTimestamp
public void gotTimestamp(String name, int time, int increment)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.TIMESTAMP
value.- Specified by:
gotTimestamp
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldtime
- the time in seconds since epochincrement
- an incrementing ordinal for operations within a given second
-
gotObjectId
public void gotObjectId(String name, ObjectId id)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.OBJECT_ID
value.- Specified by:
gotObjectId
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldid
- the object ID
-
gotDBRef
public void gotDBRef(String name, String namespace, ObjectId id)
Description copied from interface:BSONCallback
Invoked whenBSONDecoder
encountered aBsonType.DB_POINTER
type field in a byte sequence.- Specified by:
gotDBRef
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldnamespace
- the namespace to which reference is pointing toid
- the if of the object to which reference is pointing to
-
gotBinaryArray
@Deprecated public void gotBinaryArray(String name, byte[] data)
Deprecated.Description copied from interface:BSONCallback
This method is not used.- Specified by:
gotBinaryArray
in interfaceBSONCallback
- Parameters:
name
- the name of the fielddata
- the field's value
-
gotBinary
public void gotBinary(String name, byte type, byte[] data)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.BINARY
value. Note that binary values have a subtype, which may determine how the value is processed.- Specified by:
gotBinary
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldtype
- one of the binary subtypes:BsonBinarySubType
data
- the field's value
-
gotUUID
public void gotUUID(String name, long part1, long part2)
Description copied from interface:BSONCallback
Called when reading a field with aUUID
value. This is a binary value of subtypeBsonBinarySubType.UUID_LEGACY
- Specified by:
gotUUID
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldpart1
- the first part of the UUIDpart2
- the second part of the UUID
-
gotCode
public void gotCode(String name, String code)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.JAVASCRIPT
value.- Specified by:
gotCode
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldcode
- the JavaScript code
-
gotCodeWScope
public void gotCodeWScope(String name, String code, Object scope)
Description copied from interface:BSONCallback
Called when reading a field with aBsonType.JAVASCRIPT_WITH_SCOPE
value.- Specified by:
gotCodeWScope
in interfaceBSONCallback
- Parameters:
name
- the name of the fieldcode
- the JavaScript codescope
- a document representing the scope for the code
-
_put
protected void _put(String name, Object value)
Puts a new value into the document.- Parameters:
name
- the name of the fieldvalue
- the value
-
cur
protected BSONObject cur()
Gets the current value- Returns:
- the current value
-
curName
protected String curName()
Gets the name of the current field- Returns:
- the name of the current field.
-
setRoot
protected void setRoot(Object root)
Sets the root document for this position- Parameters:
root
- the new root document
-
isStackEmpty
protected boolean isStackEmpty()
Returns whether this is the top level or not- Returns:
- true if there's nothing on the stack, and this is the top level of the document.
-
reset
public void reset()
Description copied from interface:BSONCallback
Resets the callback, clearing all state.- Specified by:
reset
in interfaceBSONCallback
-
-