bson/src/main/org/bson/Document.java
@SuppressWarnings("unchecked")
    private <T> T getEmbeddedValue(final List<?> keys, final Class<T> clazz, final T defaultValue) {
        Object value = this;
        Iterator<?> keyIterator = keys.iterator();
        while (keyIterator.hasNext()) {
            Object key = keyIterator.next();
            value = ((Document) value).get(key);
            if (!(value instanceof Document)) {
                if (value == null) {
                    return defaultValue;
                } else if (keyIterator.hasNext()) {
                    throw new ClassCastException(format("At key %s, the value is not a Document (%s)",
                            key, value.getClass().getName()));
                }
            }
        }
        return clazz != null ? clazz.cast(value) : (T) value;
    }
@SuppressWarnings("unchecked")
    private <T> T getEmbeddedValue(final List<?> keys, final Class<T> clazz, final T defaultValue) {
        Object value = this;
        Iterator<?> keyIterator = keys.iterator();
        while (keyIterator.hasNext()) {
            Object key = keyIterator.next();
            value = ((Document) value).get(key);
            if (!(value instanceof Document)) {
                if (value == null) {
                    return defaultValue;
                } else if (keyIterator.hasNext()) {
                    throw new ClassCastException(format("At key %s, the value is not a Document (%s)",
                            key, value.getClass().getName()));
                }
            }
        }
        return clazz != null ? clazz.cast(value) : (T) value;
    }
@ SuppressWarnings ( "unchecked" ) private < T > T getEmbeddedValue ( final List < ? > keys , final Class < T > clazz , final T defaultValue ) { Object value = this ; Iterator < ? > keyIterator = keys . iterator ( ) ; while ( keyIterator . hasNext ( ) ) { Object key = keyIterator . next ( ) ; value = ( ( Document ) value ) . get ( key ) ; if ( ! ( value instanceof Document ) ) { if ( value == null ) { return defaultValue ; } else if ( keyIterator . hasNext ( ) ) { throw new ClassCastException ( format ( "At key %s, the value is not a Document (%s)" , key , value . getClass ( ) . getName ( ) ) ) ; } } } return clazz != null ? clazz . cast ( value ) : ( T ) value ; }
Throws ClassCastException if any of the intermediate embedded values is not a Document.
Throws ClassCastException if any of the intermediate embedded values is not a Document .