Example usage for com.mongodb Bytes getType

List of usage examples for com.mongodb Bytes getType

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static byte getType(final Object object) 

Source Link

Document

Gets the type byte for a given object.

Usage

From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.ResultDataHandler.java

License:Open Source License

static DBObject fetchFieldDocument(Object fieldValue, byte fieldNativeDataType) {
    if (fieldNativeDataType == BSON.UNDEFINED)
        fieldNativeDataType = Bytes.getType(fieldValue);

    if (fieldNativeDataType == BSON.ARRAY) {
        if (!(fieldValue instanceof List))
            return null;

        // fetch nested document, if exists, for each element in array
        BasicDBList dbObjsList = new BasicDBList();
        for (Object valueInList : (List<?>) fieldValue) {
            DBObject listElementObj = fetchFieldDocument(valueInList);
            if (listElementObj == null) // at least one element in array is not a nested doc
                return null;
            if (listElementObj instanceof List)
                dbObjsList.addAll((List<?>) listElementObj); // collapse into the same list
            else/*from www .  j  a v  a  2 s  . c o  m*/
                dbObjsList.add(listElementObj);
        }
        return dbObjsList; // return nested documents in an array
    }

    DBObject fieldObjValue = null;
    if (fieldNativeDataType == BSON.OBJECT) {
        if (fieldValue instanceof DBObject)
            fieldObjValue = (DBObject) fieldValue;
        else if (fieldValue instanceof DBRefBase) {
            try {
                fieldObjValue = ((DBRefBase) fieldValue).fetch();
            } catch (Exception ex) {
                // log and ignore
                getLogger().log(Level.INFO, "Ignoring error in fetching a DBRefBase object."); //$NON-NLS-1$
            }
        }
    }
    return fieldObjValue;
}