Example usage for com.mongodb DBObjectCodec DBObjectCodec

List of usage examples for com.mongodb DBObjectCodec DBObjectCodec

Introduction

In this page you can find the example usage for com.mongodb DBObjectCodec DBObjectCodec.

Prototype

public DBObjectCodec(final CodecRegistry codecRegistry, final BsonTypeClassMap bsonTypeClassMap) 

Source Link

Document

Construct an instance.

Usage

From source file:org.bson.jvm.nashorn.NashornCodecProvider.java

License:Apache License

@SuppressWarnings("unchecked")
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
    if (clazz == Document.class)
        return (Codec<T>) new DocumentCodec(registry, bsonTypeClassMap);
    else if (clazz == DBObject.class)
        return (Codec<T>) new DBObjectCodec(registry, bsonTypeClassMap);
    else if (clazz == NativeArray.class)
        return (Codec<T>) new NativeArrayCodec(registry, bsonTypeClassMap);
    // Nashorn uses subclasses of ScriptObject, such as JO4
    else if (ScriptObject.class.isAssignableFrom(clazz))
        return (Codec<T>) new ScriptObjectCodec(registry, bsonTypeClassMap);
    else if (clazz == ScriptObjectMirror.class)
        return (Codec<T>) new ScriptObjectMirrorCodec(registry);
    return null;/*from w  w w  .  j  a va  2 s  . co m*/
}

From source file:org.bson.jvm.rhino.RhinoCodecProvider.java

License:Apache License

@SuppressWarnings("unchecked")
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
    if (clazz == Document.class)
        return (Codec<T>) new DocumentCodec(registry, bsonTypeClassMap);
    else if (clazz == DBObject.class)
        return (Codec<T>) new DBObjectCodec(registry, bsonTypeClassMap);
    else if (clazz == NativeArray.class)
        return (Codec<T>) new NativeArrayCodec(registry, bsonTypeClassMap);
    else if (Wrapper.class.isAssignableFrom(clazz))
        return (Codec<T>) new WrapperCodec(registry);
    // Handle private classes
    String name = clazz.getCanonicalName();
    if (name.equals("org.mozilla.javascript.NativeBoolean"))
        return new NativeBooleanCodec();
    else if (name.equals("org.mozilla.javascript.NativeDate"))
        return new NativeDateCodec();
    else if (name.equals("org.mozilla.javascript.NativeNumber"))
        return new NativeNumberCodec();
    else if (name.equals("org.mozilla.javascript.regexp.NativeRegExp"))
        return new NativeRegExpCodec();
    else if (name.equals("org.mozilla.javascript.NativeString"))
        return new NativeStringCodec();
    // Make sure Scriptable is last
    else if (Scriptable.class.isAssignableFrom(clazz))
        return (Codec<T>) new ScriptableCodec(registry, bsonTypeClassMap);
    return null;/*from  w  w  w  .  j a v  a 2 s  . c o m*/
}