Make ScriptableDocument support JSON.stringify.
Fix style errors.

This patch fixes below style errrors.

error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/database/ScriptableQuery.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=16 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableUUID.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=11 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=30 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=35 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=42 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=49 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=79 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=94 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=105 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=128 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=140 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableFuture.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=155 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableConsole.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=11 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableConsole.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=15 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableConsole.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=19 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableConsole.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=23 column=6
error file=/home/sloan/workspace/beyond/core/app/beyond/engine/javascript/lib/ScriptableConsole.scala message=Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' line=27 column=6
Rename JSStaticFunction to JSStaticFunctionAnnotation.

JSFunction is imported as JSFunctionAnnotation to distinguish it from
JSFunction type alias. Use the same naming convention for JSStaticFunction to
make naming consistent.
Add Future.andThen function.

andThen applies the side-effecting function to the result of this future, and
returns a new future with the result of this future.

This method allows one to enforce that the callbacks are executed in a
specified order.
Make ScriptableDocument.findOne() succeed even when there is no matching data.

Currently, findOne method returns a failed future with
NoSuchElementException if there is no matching data. This behavior is
inconsist with find method - find method returns an empty array.

This patch makes findOne method return a successful future whose value
is null.
Fix a bug in ScriptableFuture.onSuccess method.

Currently, onSuccess callback of ScriptableFuture is not called if the
result is null because null is not matched with AnyRef.
Modify findOne example to check if result is null.

result can be null if there is no matching data.
Make scalastyle warn when code exceeds the maximum cyclomatic complexity.

Currently, scalastyle errors when code exceeds the maximum cyclomatic
complexity (currently 10). It's helpful mostly but it makes code verbose in
some cases.
Adjust relations between Scala, JavaScript and BSON types.

Currentlym Scala, JavaScript and BSON types are not consistently used. This
patch adjusts their relations.

There are three kind of types:
 - JavaScript type: used by Rhino engine
 - Scala type: intermediate type used by Scala code
 - BSON type: used by database

The conversion table is:

 JavaScriptType  | ScalaType            | BSONType
-----------------+----------------------+----------------
 NativeObject    | Map[String, AnyRef]  | BSONDocument
 NativeArray     | Seq[AnyRef]          | BSONArray
 NativeNumber    | Int                  | BSONInteger
                 | Long                 | BSONLong
                 | Double               | BSONDouble
 NativeBoolean   | Boolean              | BSONBoolean
 NativeDate      | Date                 | BSONDateTime
 NativeUndefined | Undefined            | BSONUndefined
 NativeFunction  | String               | BSONJavaScript

JavaScript types can be converted to Scala types with Field and Scala types can
be converted to JavaScript types with Context and Scope.  Scala types are
convertible to BSON types and vice versa.  But JavaScript types and BSON types
cannot be converted to each other directly.

ScriptableDocument contains data as BSON Type, and converts to JavaScript type
when the engine requests it.

Scala types seem to be useless because it's not used by engine nor database,
but code becomes complicated without these types because the Rhino engine
automatically converts primitive types with toSource method of Native*.
Add ObjectID wrapper.

Currently, there is no way to find a document with object id.
This patch adds ObjectID wrapper. A user can use this wrapper with
require('db').ObjectID().

This patch also adds examples of how to use ObjectID.
Implement the reference type for DB field.

The purpose of reference field is to reference a document. This field will
store the object id of the document. The getter of a reference type field
returns the future of the document referenced by this field.

And this patch adds three examples of how to use reference type.
Add embedding field.

Embedding field is used to store an object. This type must be used with a
schema.

See https://github.com/SollmoStudio/beyond/wiki/Beyond-DB-API-Schema for
more information.
Make reference field return ObjectID.

Currently, reference field returns Future of document for convenience.
However, only the object id is needed in some use cases. This patch makes
reference fied return ObjectID instead. When a user needs the corresponding
document, the user must call findOne.
Fix a grammar error.
Remove invalid comments.

bodyAsJson is already implemented.
Do not convert to NativeObject if it is a primitive type.

Currently, each field type of Document is always 'object' instead of the
expected type (e.g., 'string', 'number' and 'boolean') because
ScriptableDocument converts it to NativeObject.

This patch makes ScriptableDocument return the primitve type with no
conversion.  Rhino engine will automatically convert Number, Boolean and String
because BeyondContextFactory set javaPrimitiveWrap to false.
Don't share emptyUpdatedValueTable across multiple ScriptableDocument.

Currently, ScriptableDocument's updateValues field accidentally shares a
single UpdatedValueTable because emptyUpdatedValueTable is a singleton defined
in ScriptableDocument's companion object. Move it to ScriptableDocument class
so that each ScriptableDocument instance has its own UpdatedValueTable.

Also move UpdatedValueTable type to ScriptableDocument class because it is used
only within ScriptableDocument class.
Expose objectID as objectId in JavaScript.

Follow the mongo shell's naming convention.
Make collection.save method return a Future of the saved document on success.

Currently,  save method returns a Future of LastErrorMessage. But the updated
document is needed in most cases.

This patch makes save method return a Future of the saved document on success.
Change the behavior of ScriptableFuture.andThen.

Change andThen to do exactly the same thing as flatMap except it does not pass
the result of this future to the andThen callback. andThen will be used only
for sequencing.