Package mungbean.rhino

Source Code of mungbean.rhino.RhinoBSONMap

package mungbean.rhino;

import java.util.ArrayList;
import java.util.List;

import mungbean.protocol.bson.AbstractBSONMap;
import mungbean.protocol.bson.KeyValuePair;

import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.ScriptableObject;

public class RhinoBSONMap extends AbstractBSONMap<ScriptableObject> {
    public RhinoBSONMap() {
        super(ScriptableObject.class);
    }

    @Override
    protected ScriptableObject newInstance() {
        return new NativeObject();
    }

    @Override
    protected ScriptableObject setValue(ScriptableObject item, String key, Object value) {
        NativeObject.putProperty(item, key, value);
        return item;
    }

    @Override
    protected Iterable<KeyValuePair<String, Object>> entriesOf(ScriptableObject item) {
        List<KeyValuePair<String, Object>> returnValue = new ArrayList<KeyValuePair<String, Object>>();
        for (Object id : item.getIds()) {
            String key = String.valueOf(id);
            Object value = NativeObject.getProperty(item, key);
            returnValue.add(new KeyValuePair<String, Object>(key, value));
        }
        return returnValue;
    }
}
TOP

Related Classes of mungbean.rhino.RhinoBSONMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.