/// class ProspectDirector.Web.ObjectProxy

/**
A list class that wraps a JavaScript array.
@class ObjectProxy
@namespace Web
@constructor
@param {Object}
**/
ProspectDirector.Web.ObjectProxy = Class.extend({

    //===================================
    // FIELDS
    //===================================

    _innerObject: null,

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function (obj) {
        this._innerObject = obj;
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    update: function (obj) {
        
        var that = this,
            keys = this._keys(obj);

        keys.each(function (index, key) {
            if (that._innerObject.hasOwnProperty(key)) {
                that._innerObject[key] = obj[key];
            }
        });

    },

    getValue: function (path) {

        var that = this,
            keys = new ProspectDirector.Web.List(path.split(".")),
            result = this._innerObject;

        keys.each(function (index, key) {
            if (result.hasOwnProperty(key)) {
                result = result[key];
            }
            else {
                result = undefined;
                return false;
            }
        });

        return result;

    },

    setValue: function (path, value) {

        var that = this,
            keys = new ProspectDirector.Web.List(path.split(".")),
            result = this._innerObject;

        keys.each(function (index, key) {
            if (result.hasOwnProperty(key)) {
                result = result[key];
            }
        });

        return result;

    },

    toObject: function () {
        return this._innerObject;
    },

    toPartial: function (exclude) {
        
        var that = this,
            result = {},
            excludeList = new ProspectDirector.Web.List(exclude);

        this._keys.each(function (index, key) {
            if (!excludeList.contains(key)) {
                result[key] = that._innerObject[key];
            }
        });

        return result;

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _keys: function (target) {
        
        var source = target || this._innerObject,
            result = new ProspectDirector.Web.List();

        for (var key in source) {
            result.add(key);
        }

        return result;

    }

});