ModeShape Distribution 3.0.0.Beta4

org.infinispan.schematic.internal.document
Class DocumentEditor

java.lang.Object
  extended by org.infinispan.schematic.internal.document.DocumentEditor
All Implemented Interfaces:
Serializable, Document, EditableDocument
Direct Known Subclasses:
ObservableDocumentEditor

public class DocumentEditor
extends Object
implements EditableDocument

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.infinispan.schematic.document.Document
Document.Field, Document.ValueTransformer
 
Field Summary
protected  DocumentValueFactory factory
           
 
Constructor Summary
DocumentEditor(MutableDocument document)
          Return the document that was edited.
DocumentEditor(MutableDocument document, DocumentValueFactory factory)
          Return the document that was edited.
 
Method Summary
 MutableDocument asMutableDocument()
           
 DocumentEditor clone()
          Obtain a clone of this document.
 boolean containsAll(Document document)
          Checks if this object contains all of the fields in the supplied document.
 boolean containsField(String name)
          Checks if this object contains a field with the given name.
protected  EditableArray createEditableArray(MutableArray array, String fieldName, DocumentValueFactory factory)
           
protected  EditableDocument createEditableDocument(MutableDocument document, String fieldName, DocumentValueFactory factory)
           
protected  Object doSetValue(String name, Object value)
          The method that does the actual setting for all of the set...
protected  Object doSetValueIfAbsent(String name, Object value)
          The method that does the actual setting for all of the set...
protected  EditableDocument editable(Document doc, String fieldName)
           
protected  EditableArray editable(List<?> array, String fieldName)
           
 Iterable<Document.Field> fields()
          Obtain an iterator over the Document.Fields in this object.
 Object get(String name)
          Gets the value in this document for the given field name.
 EditableArray getArray(String name)
          Get the existing array value in this document for the given field name.
 Binary getBinary(String name)
          Get the Binary value in this document for the given field name.
 Boolean getBoolean(String name)
          Get the boolean value in this document for the given field name.
 boolean getBoolean(String name, boolean defaultValue)
          Get the boolean value in this document for the given field name.
 Code getCode(String name)
          Get the Code value in this document for the given field name.
 CodeWithScope getCodeWithScope(String name)
          Get the CodeWithScope value in this document for the given field name.
 EditableDocument getDocument(String name)
          Get the existing document value in this document for the given field name.
 Double getDouble(String name)
          Get the double value in this document for the given field name.
 double getDouble(String name, double defaultValue)
          Get the double value in this document for the given field name.
 Integer getInteger(String name)
          Get the integer value in this document for the given field name.
 int getInteger(String name, int defaultValue)
          Get the integer value in this document for the given field name.
 Long getLong(String name)
          Get the integer value in this document for the given field name.
 long getLong(String name, long defaultValue)
          Get the long value in this document for the given field name.
 MaxKey getMaxKey(String name)
          Get the MaxKey value in this document for the given field name.
 MinKey getMinKey(String name)
          Get the MinKey value in this document for the given field name.
 Number getNumber(String name)
          Get the number value in this document for the given field name.
 Number getNumber(String name, Number defaultValue)
          Get the number value in this document for the given field name.
 ObjectId getObjectId(String name)
          Get the ObjectId value in this document for the given field name.
 EditableArray getOrCreateArray(String name)
          Get the existing array value in this document for the given field name, or create a new array if there is no existing array at this field.
 EditableDocument getOrCreateDocument(String name)
          Get the existing document value in this document for the given field name, or create a new document if there is no existing document at this field.
 Pattern getPattern(String name)
          Get the Pattern value in this document for the given field name.
 String getString(String name)
          Get the string value in this document for the given field name.
 String getString(String name, String defaultValue)
          Get the string value in this document for the given field name.
 Symbol getSymbol(String name)
          Get the Symbol value in this document for the given field name.
 int getType(String name)
          Get the Bson.Type constant that describes the type of value for the given field name.
 UUID getUuid(String name)
          Get the UUID value in this document for the given field name.
 UUID getUuid(String name, UUID defaultValue)
          Get the UUID value in this document for the given field name.
 boolean isEmpty()
          Return whether this document contains no fields and is therefore empty.
 boolean isNull(String name)
          Determine whether this object has a pair with the given the name and the value is null.
 boolean isNullOrMissing(String name)
          Determine whether this object has a pair with the given the name and the value is null, or if this object has no field with the given name.
 Set<String> keySet()
          Returns this object's fields' names
 Object put(String name, Object value)
           
 void putAll(Document object)
          Sets on this object all name/value pairs from the supplied object.
 void putAll(Map<? extends String,? extends Object> map)
          Sets on this object all key/value pairs from the supplied map.
 Object remove(String name)
          Remove the field with the supplied name, and return the value.
 void removeAll()
          Remove all fields from this document.
 EditableDocument set(String name, Object value)
          Set the value for the field with the given name to the supplied value.
 EditableArray setArray(String name)
          Set the value for the field with the given name to be a new, empty array.
 EditableArray setArray(String name, Array array)
          Set the value for the field with the given name to be the supplied array.
 EditableArray setArray(String name, Object... values)
          Set the value for the field with the given name to be the supplied array.
 EditableDocument setBinary(String name, byte type, byte[] data)
          Set the value for the field with the given name to be a binary value.
 EditableDocument setBoolean(String name, boolean value)
          Set the value for the field with the given name to the supplied boolean value.
 EditableDocument setCode(String name, String code, boolean includeScope)
          Set the value for the field with the given name to be a Code or CodeWithScope.
 EditableDocument setCode(String name, String code, Document scope)
          Set the value for the field with the given name to be a Code or CodeWithScope.
 EditableDocument setDate(String name, Date value)
          Set the value for the field with the given name to the supplied date value.
 EditableDocument setDate(String name, String isoDate)
          Set the value for the field with the given name to the date value parsed from the ISO-8601 date representation.
 EditableDocument setDocument(String name)
          Set the value for the field with the given name to be a new, empty Document.
 EditableDocument setDocument(String name, Document document)
          Set the value for the field with the given name to be the supplied Document.
 EditableDocument setNull(String name)
          Set the value for the field with the given name to be a null value.
 EditableDocument setNumber(String name, double value)
          Set the value for the field with the given name to the supplied double value.
 EditableDocument setNumber(String name, float value)
          Set the value for the field with the given name to the supplied float value.
 EditableDocument setNumber(String name, int value)
          Set the value for the field with the given name to the supplied integer value.
 EditableDocument setNumber(String name, long value)
          Set the value for the field with the given name to the supplied long value.
 EditableDocument setObjectId(String name, byte[] bytes)
          Set the value for the field with the given name to an ObjectId created from the supplied 12-byte binary value.
 EditableDocument setObjectId(String name, int time, int machine, int process, int inc)
          Set the value for the field with the given name to an ObjectId created from the supplied hexadecimal binary value.
 EditableDocument setObjectId(String name, String hex)
          Set the value for the field with the given name to an ObjectId created from the supplied hexadecimal binary value.
 EditableDocument setRegularExpression(String name, String pattern)
          Set the value for the field with the given name to the supplied regular expression.
 EditableDocument setRegularExpression(String name, String pattern, int flags)
          Set the value for the field with the given name to the supplied regular expression.
 EditableDocument setString(String name, String value)
          Set the value for the field with the given name to the supplied string value.
 EditableDocument setSymbol(String name, String value)
          Set the value for the field with the given name to a Symbol created from the supplied string value.
 EditableDocument setTimestamp(String name, int timeInSeconds, int increment)
          Set the value for the field with the given name to a Timestamp with the supplied time in seconds and increment.
 EditableDocument setUuid(String name, UUID uuid)
          Set the value for the field with the given name to be a UUID.
 int size()
          Return the number of name-value pairs in this object.
 Map<String,? extends Object> toMap()
          Returns a map representing this BSONObject.
 String toString()
           
 Document unwrap()
          Unwrap this editor to obtain the potentially wrapped document.
static Array unwrap(Array array)
           
static Document unwrap(Document document)
           
static Object unwrap(Object value)
           
 DocumentEditor with(Document.ValueTransformer transformer)
          Obtain a clone of this document, but with the field values transformed using the supplied Document.ValueTransformer.
 DocumentEditor with(Map<String,Object> changedFields)
          Obtain a clone of this document, but with the supplied fields replaced.
 Document withVariablesReplaced(Properties properties)
          Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the supplied properties.
 Document withVariablesReplacedWithSystemProperties()
          Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the System properties.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

factory

protected final DocumentValueFactory factory
Constructor Detail

DocumentEditor

public DocumentEditor(MutableDocument document)
Return the document that was edited.

Parameters:
document - the document to be edited

DocumentEditor

public DocumentEditor(MutableDocument document,
                      DocumentValueFactory factory)
Return the document that was edited.

Parameters:
document - the document to be edited
factory - the factory that should be used to create value objects
Method Detail

clone

public DocumentEditor clone()
Description copied from interface: Document
Obtain a clone of this document.

Specified by:
clone in interface Document
Overrides:
clone in class Object
Returns:
the clone of this document; never null

with

public DocumentEditor with(Map<String,Object> changedFields)
Description copied from interface: Document
Obtain a clone of this document, but with the supplied fields replaced.

Specified by:
with in interface Document
Parameters:
changedFields - the fields that should be changed; may be null
Returns:
the clone of this document with the change fields, or this document if there are no changes

with

public DocumentEditor with(Document.ValueTransformer transformer)
Description copied from interface: Document
Obtain a clone of this document, but with the field values transformed using the supplied Document.ValueTransformer.

Specified by:
with in interface Document
Parameters:
transformer - the transformer that should be used to transform each field value; may not be null
Returns:
the clone of this document with transformed fields, or this document if the transformer changed none of the values

withVariablesReplaced

public Document withVariablesReplaced(Properties properties)
Description copied from interface: Document
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the supplied properties.

Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:

    variable := '${' variableNames [ ':' defaultValue ] '}'
    
    variableNames := variableName [ ',' variableNames ]
    
    variableName := /* any characters except ',' and ':' and '}'
    
    defaultValue := /* any characters except
 
Note that variableName is the name used to look up the Properties property.

Notice that the syntax supports multiple variables. The logic will process the variables from let to right, until an existing System property is found. And at that point, it will stop and will not attempt to find values for the other variables.

Specified by:
withVariablesReplaced in interface Document
Parameters:
properties - the properties keyed by variable name
Returns:
the clone of this document with variables in fields string values replaced with values from the properties object, or this document if no variables were found
See Also:
Document.withVariablesReplacedWithSystemProperties(), Document.with(ValueTransformer), SchemaLibrary.convertValues(Document, String)

withVariablesReplacedWithSystemProperties

public Document withVariablesReplacedWithSystemProperties()
Description copied from interface: Document
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the System properties.

Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:

    variable := '${' variableNames [ ':' defaultValue ] '}'
    
    variableNames := variableName [ ',' variableNames ]
    
    variableName := /* any characters except ',' and ':' and '}'
    
    defaultValue := /* any characters except
 
Note that variableName is the name used to look up a System property via System.getProperty(String).

Notice that the syntax supports multiple variables. The logic will process the variables from let to right, until an existing System property is found. And at that point, it will stop and will not attempt to find values for the other variables.

Because only string values can contain variables, the resulting values are left as strings. This may not be valid according to the document's JSON Schema, so see SchemaLibrary.convertValues(Document, String) to convert the string values after variable substitution into the expected non-string types.

Specified by:
withVariablesReplacedWithSystemProperties in interface Document
Returns:
the clone of this document with variables in fields string values replaced with values from the System properties, or this document if no variables were found
See Also:
Document.withVariablesReplaced(Properties), Document.with(ValueTransformer), SchemaLibrary.convertValues(Document, String)

unwrap

public Document unwrap()
Description copied from interface: EditableDocument
Unwrap this editor to obtain the potentially wrapped document.

Specified by:
unwrap in interface EditableDocument
Returns:
the wrapped document, or this object; never null

asMutableDocument

public MutableDocument asMutableDocument()

get

public Object get(String name)
Description copied from interface: Document
Gets the value in this document for the given field name.

Specified by:
get in interface Document
Parameters:
name - The name of the pair
Returns:
The field value, if found, or null otherwise

getBoolean

public Boolean getBoolean(String name)
Description copied from interface: Document
Get the boolean value in this document for the given field name.

Specified by:
getBoolean in interface Document
Parameters:
name - The name of the pair
Returns:
The boolean field value, if found, or null if there is no such pair or if the value is not a boolean

getBoolean

public boolean getBoolean(String name,
                          boolean defaultValue)
Description copied from interface: Document
Get the boolean value in this document for the given field name.

Specified by:
getBoolean in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a boolean
Returns:
The boolean field value if found, or defaultValue if there is no such pair or if the value is not a boolean

put

public Object put(String name,
                  Object value)

putAll

public void putAll(Document object)
Description copied from interface: EditableDocument
Sets on this object all name/value pairs from the supplied object. If the supplied object is null, this method does nothing.

Specified by:
putAll in interface EditableDocument
Parameters:
object - the object containing the name/value pairs to be set on this object

putAll

public void putAll(Map<? extends String,? extends Object> map)
Description copied from interface: EditableDocument
Sets on this object all key/value pairs from the supplied map. If the supplied map is null, this method does nothing.

Specified by:
putAll in interface EditableDocument
Parameters:
map - the map containing the name/value pairs to be set on this object

remove

public Object remove(String name)
Description copied from interface: EditableDocument
Remove the field with the supplied name, and return the value.

Specified by:
remove in interface EditableDocument
Parameters:
name - The name of the field
Returns:
the value that was removed, or null if there was no such value

getInteger

public Integer getInteger(String name)
Description copied from interface: Document
Get the integer value in this document for the given field name.

Specified by:
getInteger in interface Document
Parameters:
name - The name of the pair
Returns:
The integer field value, if found, or null if there is no such pair or if the value is not an integer

getInteger

public int getInteger(String name,
                      int defaultValue)
Description copied from interface: Document
Get the integer value in this document for the given field name.

Specified by:
getInteger in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a integer
Returns:
The integer field value if found, or defaultValue if there is no such pair or if the value is not a integer

getLong

public Long getLong(String name)
Description copied from interface: Document
Get the integer value in this document for the given field name.

Specified by:
getLong in interface Document
Parameters:
name - The name of the pair
Returns:
The long field value, if found, or null if there is no such pair or if the value is not a long value

getLong

public long getLong(String name,
                    long defaultValue)
Description copied from interface: Document
Get the long value in this document for the given field name.

Specified by:
getLong in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a long value
Returns:
The long field value if found, or defaultValue if there is no such pair or if the value is not a long value

getDouble

public Double getDouble(String name)
Description copied from interface: Document
Get the double value in this document for the given field name.

Specified by:
getDouble in interface Document
Parameters:
name - The name of the pair
Returns:
The double field value, if found, or null if there is no such pair or if the value is not a double

getDouble

public double getDouble(String name,
                        double defaultValue)
Description copied from interface: Document
Get the double value in this document for the given field name.

Specified by:
getDouble in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a double
Returns:
The double field value if found, or defaultValue if there is no such pair or if the value is not a double

getNumber

public Number getNumber(String name)
Description copied from interface: Document
Get the number value in this document for the given field name.

Specified by:
getNumber in interface Document
Parameters:
name - The name of the pair
Returns:
The double field value, if found, or null if there is no such pair or if the value is not a number

getNumber

public Number getNumber(String name,
                        Number defaultValue)
Description copied from interface: Document
Get the number value in this document for the given field name.

Specified by:
getNumber in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a number
Returns:
The number field value if found, or defaultValue if there is no such pair or if the value is not a number

getString

public String getString(String name)
Description copied from interface: Document
Get the string value in this document for the given field name. This method will return the string even if the actual value is a Symbol.

Specified by:
getString in interface Document
Parameters:
name - The name of the pair
Returns:
The string field value, if found, or null if there is no such pair or if the value is not a string

getString

public String getString(String name,
                        String defaultValue)
Description copied from interface: Document
Get the string value in this document for the given field name. This method will return the string even if the actual value is a Symbol.

Specified by:
getString in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a string
Returns:
The string field value if found, or defaultValue if there is no such pair or if the value is not a string

getArray

public EditableArray getArray(String name)
Description copied from interface: EditableDocument
Get the existing array value in this document for the given field name.

Specified by:
getArray in interface Document
Specified by:
getArray in interface EditableDocument
Parameters:
name - The name of the pair
Returns:
The editable array field value (as a list), if found, or null if there is no such pair or if the value is not an array

getOrCreateArray

public EditableArray getOrCreateArray(String name)
Description copied from interface: EditableDocument
Get the existing array value in this document for the given field name, or create a new array if there is no existing array at this field.

Specified by:
getOrCreateArray in interface EditableDocument
Parameters:
name - The name of the pair
Returns:
The editable array field value; never null

getDocument

public EditableDocument getDocument(String name)
Description copied from interface: EditableDocument
Get the existing document value in this document for the given field name.

Specified by:
getDocument in interface Document
Specified by:
getDocument in interface EditableDocument
Parameters:
name - The name of the pair
Returns:
The editable document field value, if found, or null if there is no such pair or if the value is not a document

getOrCreateDocument

public EditableDocument getOrCreateDocument(String name)
Description copied from interface: EditableDocument
Get the existing document value in this document for the given field name, or create a new document if there is no existing document at this field.

Specified by:
getOrCreateDocument in interface EditableDocument
Parameters:
name - The name of the pair
Returns:
The editable document field value; never null

isNull

public boolean isNull(String name)
Description copied from interface: Document
Determine whether this object has a pair with the given the name and the value is null. This is equivalent to calling:
 this.get(name) instanceof Null;
 

Specified by:
isNull in interface Document
Parameters:
name - The name of the pair
Returns:
true if the field has been set to a Null value, or false otherwise
See Also:
Document.isNullOrMissing(String)

isNullOrMissing

public boolean isNullOrMissing(String name)
Description copied from interface: Document
Determine whether this object has a pair with the given the name and the value is null, or if this object has no field with the given name. This is equivalent to calling:
 Null.matches(this.get(name));
 

Specified by:
isNullOrMissing in interface Document
Parameters:
name - The name of the pair
Returns:
true if the field value for the name is null or if there is no such field.
See Also:
Document.isNull(String)

getMaxKey

public MaxKey getMaxKey(String name)
Description copied from interface: Document
Get the MaxKey value in this document for the given field name.

Specified by:
getMaxKey in interface Document
Parameters:
name - The name of the pair
Returns:
The MaxKey field value, if found, or null if there is no such pair or if the value is not a MaxKey

getMinKey

public MinKey getMinKey(String name)
Description copied from interface: Document
Get the MinKey value in this document for the given field name.

Specified by:
getMinKey in interface Document
Parameters:
name - The name of the pair
Returns:
The MinKey field value, if found, or null if there is no such pair or if the value is not a MinKey

getCode

public Code getCode(String name)
Description copied from interface: Document
Get the Code value in this document for the given field name.

Specified by:
getCode in interface Document
Parameters:
name - The name of the pair
Returns:
The Code field value, if found, or null if there is no such pair or if the value is not a Code

getCodeWithScope

public CodeWithScope getCodeWithScope(String name)
Description copied from interface: Document
Get the CodeWithScope value in this document for the given field name.

Specified by:
getCodeWithScope in interface Document
Parameters:
name - The name of the pair
Returns:
The CodeWithScope field value, if found, or null if there is no such pair or if the value is not a CodeWithScope

getObjectId

public ObjectId getObjectId(String name)
Description copied from interface: Document
Get the ObjectId value in this document for the given field name.

Specified by:
getObjectId in interface Document
Parameters:
name - The name of the pair
Returns:
The ObjectId field value, if found, or null if there is no such pair or if the value is not a ObjectId

getBinary

public Binary getBinary(String name)
Description copied from interface: Document
Get the Binary value in this document for the given field name.

Specified by:
getBinary in interface Document
Parameters:
name - The name of the pair
Returns:
The Binary field value, if found, or null if there is no such pair or if the value is not a Binary

getSymbol

public Symbol getSymbol(String name)
Description copied from interface: Document
Get the Symbol value in this document for the given field name.

Specified by:
getSymbol in interface Document
Parameters:
name - The name of the pair
Returns:
The Symbol field value, if found, or null if there is no such pair or if the value is not a Symbol

getPattern

public Pattern getPattern(String name)
Description copied from interface: Document
Get the Pattern value in this document for the given field name.

Specified by:
getPattern in interface Document
Parameters:
name - The name of the pair
Returns:
The Pattern field value, if found, or null if there is no such pair or if the value is not a Pattern

getUuid

public UUID getUuid(String name)
Description copied from interface: Document
Get the UUID value in this document for the given field name.

Specified by:
getUuid in interface Document
Parameters:
name - The name of the pair
Returns:
The UUID field value, if found, or null if there is no such pair or if the value is not a UUID

getUuid

public UUID getUuid(String name,
                    UUID defaultValue)
Description copied from interface: Document
Get the UUID value in this document for the given field name.

Specified by:
getUuid in interface Document
Parameters:
name - The name of the pair
defaultValue - the default value to return if there is no such pair or if the value is not a string
Returns:
The UUID field value if found, or defaultValue if there is no such pair or if the value is not a UUID (or a string that is convertable from a UUID)

getType

public int getType(String name)
Description copied from interface: Document
Get the Bson.Type constant that describes the type of value for the given field name.

Specified by:
getType in interface Document
Parameters:
name - The name of the pair
Returns:
the Bson.Type constant describing the value, or -1 if there is no field with the supplied name

toMap

public Map<String,? extends Object> toMap()
Description copied from interface: Document
Returns a map representing this BSONObject.

Specified by:
toMap in interface Document
Returns:
the map

fields

public Iterable<Document.Field> fields()
Description copied from interface: Document
Obtain an iterator over the Document.Fields in this object.

Specified by:
fields in interface Document
Returns:
a field iterator; never null

containsField

public boolean containsField(String name)
Description copied from interface: Document
Checks if this object contains a field with the given name.

Specified by:
containsField in interface Document
Parameters:
name - The name of the pair for which to check
Returns:
true if this document contains a field with the supplied name, or false otherwise

containsAll

public boolean containsAll(Document document)
Description copied from interface: Document
Checks if this object contains all of the fields in the supplied document.

Specified by:
containsAll in interface Document
Parameters:
document - The document with the fields that should be in this document
Returns:
true if this document contains all of the fields in the supplied document, or false otherwise

keySet

public Set<String> keySet()
Description copied from interface: Document
Returns this object's fields' names

Specified by:
keySet in interface Document
Returns:
The names of the fields in this object

size

public int size()
Description copied from interface: Document
Return the number of name-value pairs in this object.

Specified by:
size in interface Document
Returns:
the number of name-value pairs; never negative

isEmpty

public boolean isEmpty()
Description copied from interface: Document
Return whether this document contains no fields and is therefore empty.

Specified by:
isEmpty in interface Document
Returns:
true if there are no fields in this document, or false if there is at least one.

removeAll

public void removeAll()
Description copied from interface: EditableDocument
Remove all fields from this document.

Specified by:
removeAll in interface EditableDocument

set

public EditableDocument set(String name,
                            Object value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied value.

Specified by:
set in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setBoolean

public EditableDocument setBoolean(String name,
                                   boolean value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied boolean value.

Specified by:
setBoolean in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setNumber

public EditableDocument setNumber(String name,
                                  int value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied integer value.

Specified by:
setNumber in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setNumber

public EditableDocument setNumber(String name,
                                  long value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied long value.

Specified by:
setNumber in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setNumber

public EditableDocument setNumber(String name,
                                  float value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied float value.

Specified by:
setNumber in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setNumber

public EditableDocument setNumber(String name,
                                  double value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied double value.

Specified by:
setNumber in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setString

public EditableDocument setString(String name,
                                  String value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied string value.

Specified by:
setString in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setSymbol

public EditableDocument setSymbol(String name,
                                  String value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to a Symbol created from the supplied string value. Symbols are defined in the BSON specification as being similar to a string but which exists for those languages that have a specific symbol type. Symbols are serialized to JSON as a normal string.

Specified by:
setSymbol in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setString(String, String)

setDocument

public EditableDocument setDocument(String name)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a new, empty Document.

Specified by:
setDocument in interface EditableDocument
Parameters:
name - The name of the field
Returns:
The editable document that was just created; never null

setDocument

public EditableDocument setDocument(String name,
                                    Document document)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be the supplied Document.

Specified by:
setDocument in interface EditableDocument
Parameters:
name - The name of the field
document - the document
Returns:
The editable document that was just set as the value for the named field; never null and may or may not be the same instance as the supplied document.

setArray

public EditableArray setArray(String name)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a new, empty array.

Specified by:
setArray in interface EditableDocument
Parameters:
name - The name of the field
Returns:
The editable array that was just created; never null

setArray

public EditableArray setArray(String name,
                              Array array)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be the supplied array.

Specified by:
setArray in interface EditableDocument
Parameters:
name - The name of the field
array - the array
Returns:
The editable array that was just set as the value for the named field; never null and may or may not be the same instance as the supplied array.

setArray

public EditableArray setArray(String name,
                              Object... values)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be the supplied array.

Specified by:
setArray in interface EditableDocument
Parameters:
name - The name of the field
values - the (valid) values for the array
Returns:
The editable array that was just set as the value for the named field; never null and may or may not be the same instance as the supplied array.

setDate

public EditableDocument setDate(String name,
                                Date value)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied date value.

Specified by:
setDate in interface EditableDocument
Parameters:
name - The name of the field
value - the new value for the field
Returns:
This document, to allow for chaining methods

setDate

public EditableDocument setDate(String name,
                                String isoDate)
                         throws ParseException
Description copied from interface: EditableDocument
Set the value for the field with the given name to the date value parsed from the ISO-8601 date representation. Specifically, the date string must match one of these patterns:

Specified by:
setDate in interface EditableDocument
Parameters:
name - The name of the field
isoDate - the new value for the field
Returns:
This document, to allow for chaining methods
Throws:
ParseException - if the supplied value could not be parsed into a valid date

setTimestamp

public EditableDocument setTimestamp(String name,
                                     int timeInSeconds,
                                     int increment)
Description copied from interface: EditableDocument
Set the value for the field with the given name to a Timestamp with the supplied time in seconds and increment. Note that Date values are recommended for most purposes, as they are better suited to most applications' representations of time instants.

Specified by:
setTimestamp in interface EditableDocument
Parameters:
name - The name of the field
timeInSeconds - the time in seconds for the new Timestamp
increment - the time increment for the new Timestamp
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setDate(String, Date)

setObjectId

public EditableDocument setObjectId(String name,
                                    String hex)
Description copied from interface: EditableDocument
Set the value for the field with the given name to an ObjectId created from the supplied hexadecimal binary value. Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is serialized in a JSON document as a nested document of the form:
 { "$oid" : "12bytesOfIdInBase16" }
 
When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to an ObjectId value.

For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as

 { "$oid" : "4e2064df0000010002000003" }
 

Specified by:
setObjectId in interface EditableDocument
Parameters:
name - The name of the field
hex - the hexadecimal binary value for the ObjectId
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setObjectId(String, byte[]), EditableDocument.setObjectId(String, int, int, int, int)

setObjectId

public EditableDocument setObjectId(String name,
                                    byte[] bytes)
Description copied from interface: EditableDocument
Set the value for the field with the given name to an ObjectId created from the supplied 12-byte binary value. Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is serialized in a JSON document as a nested document of the form:
 { "$oid" : "12bytesOfIdInBase16" }
 
When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to an ObjectId value.

For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as

 { "$oid" : "4e2064df0000010002000003" }
 

Specified by:
setObjectId in interface EditableDocument
Parameters:
name - The name of the field
bytes - the 12-byte value for the ObjectId
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setObjectId(String, String), EditableDocument.setObjectId(String, int, int, int, int)

setObjectId

public EditableDocument setObjectId(String name,
                                    int time,
                                    int machine,
                                    int process,
                                    int inc)
Description copied from interface: EditableDocument
Set the value for the field with the given name to an ObjectId created from the supplied hexadecimal binary value. Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is serialized in a JSON document as a nested document of the form:
 { "$oid" : "12bytesOfIdInBase16" }
 
When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to an ObjectId value.

For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as

 { "$oid" : "4e2064df0000010002000003" }
 

Specified by:
setObjectId in interface EditableDocument
Parameters:
name - The name of the field
time - the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 1st 1970 (UTC)
machine - the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the virtual machine id
process - the 2 bytes of the process id (or thread id) of the process generating the object id
inc - an ever incrementing value, or a random number if a counter can't be used in the language/runtime
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setObjectId(String, String), EditableDocument.setObjectId(String, byte[])

setRegularExpression

public EditableDocument setRegularExpression(String name,
                                             String pattern)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied regular expression. Regular expression values are represented in memory using Pattern instances, and are stored natively in BSON as regular expressions. However, when serialized to JSON, regular expressions are written as nested documents of the form:
 { "$regex" : "pattern" }
 
where "pattern" is the regular expression pattern.

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to a regular expression value.

Specified by:
setRegularExpression in interface EditableDocument
Parameters:
name - The name of the field
pattern - the regular expression pattern string
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setRegularExpression(String, String, int)

setRegularExpression

public EditableDocument setRegularExpression(String name,
                                             String pattern,
                                             int flags)
Description copied from interface: EditableDocument
Set the value for the field with the given name to the supplied regular expression. Regular expression values are represented in memory using Pattern instances, and are stored natively in BSON as regular expressions. However, when serialized to JSON, regular expressions are written as nested documents of the form:
 { "$regex" : "pattern", "$options" : "flags" }
 
where "pattern" is the regular expression pattern, and "flags" is a string representation of the regular expression options.

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to a regular expression value.

Specified by:
setRegularExpression in interface EditableDocument
Parameters:
name - The name of the field
pattern - the regular expression pattern string
flags - the bitwise-anded Pattern options: Pattern.CANON_EQ, Pattern.CASE_INSENSITIVE, Pattern.CASE_INSENSITIVE, Pattern.COMMENTS, Pattern.DOTALL, Pattern.LITERAL, Pattern.MULTILINE, Pattern.UNICODE_CASE, and Pattern.UNIX_LINES
Returns:
This document, to allow for chaining methods
See Also:
EditableDocument.setRegularExpression(String, String)

setNull

public EditableDocument setNull(String name)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a null value. Both JSON and BSON formats support null values, and Null is used for the value in the in-memory representation. The Document.isNull(String) methods can be used to determine if a field has been set to null, or Document.isNullOrMissing(String) if the field has not be set or if it has been set to null.

Specified by:
setNull in interface EditableDocument
Parameters:
name - The name of the field
Returns:
This document, to allow for chaining methods
See Also:
Document.isNull(String), Document.isNullOrMissing(String)

setBinary

public EditableDocument setBinary(String name,
                                  byte type,
                                  byte[] data)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a binary value. JSON does not formally support binary values, and so such values will be encoded using a nested document of the form:
 { "$type" : typeAsInt, "$base64" : "bytesInBase64" }
 
where "typeAsInt" is the integer representation of the BSON type, and "bytesInBase64" is the Base64 encoding of the actual Binary bytes.

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to Binary value.

Specified by:
setBinary in interface EditableDocument
Parameters:
name - The name of the field
type - one of the BSON type constants denoting the type of the Binary value
data - the bytes for the Binary value
Returns:
This document, to allow for chaining methods

setUuid

public EditableDocument setUuid(String name,
                                UUID uuid)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a UUID. JSON does not formally support binary values, and so such values will be encoded using a nested document of the form:
 { "$uuid" : "string-form-of-uuid" }
 
where "string-form-of-uuid" is the UUID's string representation

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to UUID value.

Specified by:
setUuid in interface EditableDocument
Parameters:
name - The name of the field
uuid - the UUID value
Returns:
This document, to allow for chaining methods

setCode

public EditableDocument setCode(String name,
                                String code,
                                boolean includeScope)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a Code or CodeWithScope. JSON does not formally support such values, and so when written to JSON they will be encoded using a nested document of the form:
 { "$code" : "code" }
 
or, if there is a scope document
 { "$code" : "code", "$scope" : scope document }
 
where "code" is the Code's JavaScript code and scopeDocument is the nested document representing the scope in which the JavaScript code should be evaluated.

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to Code or CodeWithScope value.

Note that when includeScope is true, the returned EditableDocument can be used to populate the scope document.

Specified by:
setCode in interface EditableDocument
Parameters:
name - The name of the field
code - the code
includeScope - true if the code should include a scope (and if this method should return an EditableDocument for this scope document), or false otherwise
Returns:
if includeScope is true, then the EditableDocument for the scope; otherwise, this document to allow for chaining methods
See Also:
EditableDocument.setCode(String, String, Document)

setCode

public EditableDocument setCode(String name,
                                String code,
                                Document scope)
Description copied from interface: EditableDocument
Set the value for the field with the given name to be a Code or CodeWithScope. JSON does not formally support such values, and so when written to JSON they will be encoded using a nested document of the form:
 { "$code" : "code" }
 
or, if there is a scope document
 { "$code" : "code", "$scope" : scope document }
 
where "code" is the Code's JavaScript code and scopeDocument is the nested document representing the scope in which the JavaScript code should be evaluated.

When nested documents of this form are read by this library's JSON reader, nested documents of this form will be converted to Code or CodeWithScope value.

Specified by:
setCode in interface EditableDocument
Parameters:
name - The name of the field
code - the code
scope - the scope in which the JavaScript code should be evaulated, or null if there is no scope
Returns:
the EditableDocument for the scope, or null if the scope reference is null
See Also:
EditableDocument.setCode(String, String, boolean)

doSetValue

protected Object doSetValue(String name,
                            Object value)
The method that does the actual setting for all of the set... methods. This method may be overridden by subclasses when additional work needs to be performed during the set operations.

Parameters:
name - the name of the field being set
value - the new value
Returns:
the old value, or null if there was no existing value

doSetValueIfAbsent

protected Object doSetValueIfAbsent(String name,
                                    Object value)
The method that does the actual setting for all of the set... methods. This method may be overridden by subclasses when additional work needs to be performed during the set operations.

Parameters:
name - the name of the field being set
value - the new value
Returns:
the old value, or null if there was no existing value

editable

protected EditableDocument editable(Document doc,
                                    String fieldName)

editable

protected EditableArray editable(List<?> array,
                                 String fieldName)

createEditableDocument

protected EditableDocument createEditableDocument(MutableDocument document,
                                                  String fieldName,
                                                  DocumentValueFactory factory)

createEditableArray

protected EditableArray createEditableArray(MutableArray array,
                                            String fieldName,
                                            DocumentValueFactory factory)

unwrap

public static Array unwrap(Array array)

unwrap

public static Document unwrap(Document document)

unwrap

public static Object unwrap(Object value)

toString

public String toString()
Overrides:
toString in class Object

ModeShape Distribution 3.0.0.Beta4

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.