public class DocumentBuilderImpl extends AbstractBuilder implements DocumentBuilder
AbstractBuilder.BuilderElement
ASSERTIONS_ENABLED, BUILDER_ELEMENT_CLASS, myElements
Constructor and Description |
---|
DocumentBuilderImpl()
Creates a new builder.
|
DocumentBuilderImpl(AbstractBuilder outerScope)
Creates a new builder.
|
Modifier and Type | Method and Description |
---|---|
DocumentBuilder |
add(ElementAssignable elementRef)
Adds a pre-built element to the document.
|
DocumentBuilder |
add(String name,
boolean value)
Adds a boolean element.
|
DocumentBuilder |
add(String name,
byte[] data)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
add(String name,
byte subType,
byte[] data)
Adds a binary element.
|
DocumentBuilder |
add(String name,
Date timestamp)
Adds a timestamp element.
|
DocumentBuilder |
add(String name,
DocumentAssignable document)
Adds a pre-constructed document to the array.
|
DocumentBuilder |
add(String name,
double value)
Adds a double element.
|
DocumentBuilder |
add(String name,
int value)
Adds a integer (32-bit signed) element.
|
DocumentBuilder |
add(String name,
long value)
Adds a long (64-bit signed) element.
|
DocumentBuilder |
add(String name,
ObjectId id)
Adds an ObjectId element.
|
DocumentBuilder |
add(String name,
Pattern pattern)
Adds an ObjectId element.
|
DocumentBuilder |
add(String name,
String value)
Adds a string element.
|
DocumentBuilder |
add(String name,
String databaseName,
String collectionName,
ObjectId id)
Deprecated.
|
DocumentBuilder |
addBinary(String name,
byte[] value)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
addBinary(String name,
byte subType,
byte[] value)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
addBoolean(String name,
boolean value)
Adds a boolean element.
|
DocumentBuilder |
addDBPointer(String name,
String databaseName,
String collectionName,
ObjectId id)
Deprecated.
|
DocumentBuilder |
addDocument(String name,
DocumentAssignable value)
Adds a pre-built document element.
|
DocumentBuilder |
addDouble(String name,
double value)
Adds a double element.
|
DocumentBuilder |
addInteger(String name,
int value)
Adds a integer (32-bit signed) element.
|
DocumentBuilder |
addJavaScript(String name,
String code)
Adds a JavaScript element.
|
DocumentBuilder |
addJavaScript(String name,
String code,
DocumentAssignable scope)
Adds a JavaScript with Scope element.
|
DocumentBuilder |
addLong(String name,
long value)
Adds a long (64-bit signed) element.
|
DocumentBuilder |
addMaxKey(String name)
Adds a minimum key value element.
|
DocumentBuilder |
addMinKey(String name)
Adds a minimum key value element.
|
DocumentBuilder |
addMongoTimestamp(String name,
long value)
Adds a MongoDB Timestamp element.
|
DocumentBuilder |
addNull(String name)
Adds a
null valued element. |
DocumentBuilder |
addObjectId(String name,
ObjectId id)
Adds an ObjectId element.
|
DocumentBuilder |
addRegularExpression(String name,
Pattern pattern)
Adds a regular expression element.
|
DocumentBuilder |
addRegularExpression(String name,
String pattern,
String options)
Adds a regular expression element.
|
DocumentBuilder |
addString(String name,
String value)
Adds a string element.
|
DocumentBuilder |
addSymbol(String name,
String symbol)
Adds a symbol element.
|
DocumentBuilder |
addTimestamp(String name,
long timestamp)
Adds a timestamp element.
|
Document |
asDocument()
Converts the object into a document.
|
Document |
build()
Returns the
Document being constructed. |
protected Element |
build(String name)
Constructs the final form of the element being constructed.
|
DocumentBuilder |
push(String name)
Pushes a context for constructing a sub-document.
|
ArrayBuilder |
pushArray(String name)
Pushes a context for constructing a sub-array.
|
DocumentBuilder |
reset()
Resets the builder back to an empty state.
|
doPush, doPushArray, pop, subElements
public DocumentBuilderImpl()
public DocumentBuilderImpl(AbstractBuilder outerScope)
outerScope
- The outer document scope.public DocumentBuilder add(ElementAssignable elementRef)
add
in interface DocumentBuilder
elementRef
- The element to add.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, boolean value)
This is a equivalent to DocumentBuilder.addBoolean(String,boolean)
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.value
- The boolean value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, byte subType, byte[] data)
This is a equivalent to DocumentBuilder.addBinary(String,byte, byte[])
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.subType
- The sub-type for the binary data.data
- The binary value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, byte[] data)
This is a equivalent to DocumentBuilder.addBinary(String,byte[])
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.data
- The binary value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, Date timestamp)
This is a equivalent to addTimeStamp(timestamp.getTime())
but less verbose.
add
in interface DocumentBuilder
name
- The name of the element.timestamp
- The number of milliseconds since the Unix epoch.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, DocumentAssignable document)
This is a equivalent to DocumentBuilder.addDocument(String,DocumentAssignable)
but less verbose.
add
in interface DocumentBuilder
name
- The name of the element.document
- The document to add to the array.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, double value)
This is a equivalent to DocumentBuilder.addDouble(String,double)
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.value
- The double value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, int value)
This is a equivalent to DocumentBuilder.addInteger(String,int)
but less verbose.
add
in interface DocumentBuilder
name
- The name of the element.value
- The integer value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, long value)
This is a equivalent to DocumentBuilder.addLong(String,long)
but less verbose.
add
in interface DocumentBuilder
name
- The name of the element.value
- The long value.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, ObjectId id)
This is a equivalent to DocumentBuilder.addObjectId(String,ObjectId)
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.id
- The ObjectId to add.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, Pattern pattern)
This is a equivalent to DocumentBuilder.addRegularExpression(String,Pattern)
but
less verbose.
add
in interface DocumentBuilder
name
- The name of the element.pattern
- The pattern for the regular expression.DocumentBuilder
for method chaining.public DocumentBuilder add(String name, String value)
This is a equivalent to DocumentBuilder.addString(String,String)
but less
verbose.
add
in interface DocumentBuilder
name
- The name of the element.value
- The string value.DocumentBuilder
for method chaining.@Deprecated public DocumentBuilder add(String name, String databaseName, String collectionName, ObjectId id)
This is a equivalent to
DocumentBuilder.addDBPointer(String,String, String, ObjectId)
but less verbose.
add
in interface DocumentBuilder
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.DocumentBuilder
for method chaining.public DocumentBuilder addBinary(String name, byte subType, byte[] value)
addBinary
in interface DocumentBuilder
name
- The name of the element.subType
- The sub-type for the binary data.value
- The binary value.DocumentBuilder
for method chaining.public DocumentBuilder addBinary(String name, byte[] value)
addBinary
in interface DocumentBuilder
name
- The name of the element.value
- The binary value.DocumentBuilder
for method chaining.public DocumentBuilder addBoolean(String name, boolean value)
addBoolean
in interface DocumentBuilder
name
- The name of the element.value
- The boolean value.DocumentBuilder
for method chaining.@Deprecated public DocumentBuilder addDBPointer(String name, String databaseName, String collectionName, ObjectId id)
addDBPointer
in interface DocumentBuilder
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.DocumentBuilder
for method chaining.public DocumentBuilder addDocument(String name, DocumentAssignable value)
DocumentBuilder.push(String)
a sub
document.addDocument
in interface DocumentBuilder
name
- The name of the element.value
- The document value.DocumentBuilder
for method chaining.public DocumentBuilder addDouble(String name, double value)
addDouble
in interface DocumentBuilder
name
- The name of the element.value
- The double value.DocumentBuilder
for method chaining.public DocumentBuilder addInteger(String name, int value)
addInteger
in interface DocumentBuilder
name
- The name of the element.value
- The integer value.DocumentBuilder
for method chaining.public DocumentBuilder addJavaScript(String name, String code)
addJavaScript
in interface DocumentBuilder
name
- The name of the element.code
- The java script code.DocumentBuilder
for method chaining.public DocumentBuilder addJavaScript(String name, String code, DocumentAssignable scope)
addJavaScript
in interface DocumentBuilder
name
- The name of the element.code
- The java script code.scope
- The scope for the JacaScript code.DocumentBuilder
for method chaining.public DocumentBuilder addLong(String name, long value)
addLong
in interface DocumentBuilder
name
- The name of the element.value
- The long value.DocumentBuilder
for method chaining.public DocumentBuilder addMaxKey(String name)
addMaxKey
in interface DocumentBuilder
name
- The name of the element.DocumentBuilder
for method chaining.public DocumentBuilder addMinKey(String name)
addMinKey
in interface DocumentBuilder
name
- The name of the element.DocumentBuilder
for method chaining.public DocumentBuilder addMongoTimestamp(String name, long value)
addMongoTimestamp
in interface DocumentBuilder
name
- The name of the element.value
- The mongoDB timstamp value.DocumentBuilder
for method chaining.public DocumentBuilder addNull(String name)
null
valued element.addNull
in interface DocumentBuilder
name
- The name of the element.DocumentBuilder
for method chaining.public DocumentBuilder addObjectId(String name, ObjectId id)
addObjectId
in interface DocumentBuilder
name
- The name of the element.id
- The ObjectId to add.DocumentBuilder
for method chaining.public DocumentBuilder addRegularExpression(String name, Pattern pattern)
addRegularExpression
in interface DocumentBuilder
name
- The name of the element.pattern
- The pattern for the regular expression.DocumentBuilder
for method chaining.public DocumentBuilder addRegularExpression(String name, String pattern, String options)
addRegularExpression
in interface DocumentBuilder
name
- The name of the element.pattern
- The pattern for the regular expression.options
- The regular expression options. See the BSON specification for
details.DocumentBuilder
for method chaining.public DocumentBuilder addString(String name, String value)
addString
in interface DocumentBuilder
name
- The name of the element.value
- The string value.DocumentBuilder
for method chaining.public DocumentBuilder addSymbol(String name, String symbol)
addSymbol
in interface DocumentBuilder
name
- The name of the element.symbol
- The symbol value.DocumentBuilder
for method chaining.public DocumentBuilder addTimestamp(String name, long timestamp)
addTimestamp
in interface DocumentBuilder
name
- The name of the element.timestamp
- The number of milliseconds since the Unix epoch.DocumentBuilder
for method chaining.public Document asDocument()
Returns the result of build()
.
asDocument
in interface DocumentAssignable
build()
public Document build()
Document
being constructed.build
in interface DocumentBuilder
Document
.public DocumentBuilder push(String name)
push
in interface DocumentBuilder
name
- The name of the sub-document.DocumentBuilder
for constructing the sub-document.public ArrayBuilder pushArray(String name)
pushArray
in interface DocumentBuilder
name
- The name of the sub-array.ArrayBuilder
for constructing the sub-array.public DocumentBuilder reset()
reset
in interface Builder
reset
in interface DocumentBuilder
reset
in class AbstractBuilder
protected Element build(String name)
Overridden to return an DocumentElement
.
build
in class AbstractBuilder
name
- The name of the element.Copyright © 2011-2012 Allanbank Consulting, Inc.. All Rights Reserved.