DustDataEntity resolveRef(DustSystem system, DustDataStore store, String key)
        {
            if (isLocal(key))
            {
                return(store[key]);
            }
            else
            {
                var keyModName = (String)((JObject)data[key])[header.EntityUnit];
                var keyId      = (String)((JObject)data[key])[header.EntityId];

                return(system.modules[keyModName][keyId]);
            }
        }
        public void populate(Dictionary <string, JsonUnitWrapper> js, DustSystem system, String name)
        {
            DustDataStore store = system.modules[name];

            foreach (var c in data.Children())
            {
                var p = (JProperty)c;

                var id = p.Name;

                if (isLocal(id))
                {
                    var eTarget = store[id];

                    var o = (JObject)p.Value;

                    foreach (var cc in o.Children())
                    {
                        var pp = (JProperty)cc;

                        var            key  = pp.Name;
                        DustDataEntity eKey = resolveRef(system, store, key);
                        eKey.optValType = getValType(key);
                        Object val = null;

                        switch (eKey.optValType)
                        {
                        case DustValType.AttDefBool:
                        case DustValType.AttDefIdentifier:
                        case DustValType.AttDefDouble:
                        case DustValType.AttDefLong:
                        case DustValType.AttDefRaw:
                            val = ((JValue)pp.Value).Value;
                            break;

                        case DustValType.LinkDefSingle:
                            val = ((JValue)pp.Value).Value;
                            val = resolveRef(system, store, (String)val);
                            break;

                        case DustValType.LinkDefSet:
                        case DustValType.LinkDefArray:
                            var a   = (JArray)pp.Value;
                            int idx = 0;

                            foreach (var r in a.Children())
                            {
                                eTarget.setValue(eKey, resolveRef(system, store, (String)r), idx++);
                            }

                            break;

                        case DustValType.LinkDefMap:
                            var m = (JObject)pp.Value;

                            foreach (var mc in m.Children())
                            {
                                var mp = (JProperty)mc;

                                var            mk  = mp.Name;
                                DustDataEntity eMK = resolveRef(system, store, mk);

                                var mv = ((JValue)mp.Value).Value;
                                mv = resolveRef(system, store, (String)mv);

                                eTarget.setValue(eKey, mv, eMK);
                            }

                            break;
                        }

                        if (null != val)
                        {
                            eTarget.setValue(eKey, val, null);
                        }
                    }
                }
            }
        }