- Timestamp:
- 03/06/09 14:57:19 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/PersistenceManager.cs
r1274 r1276 221 221 } 222 222 223 public class DeSerializer { 224 225 class AccessibleObject { 223 public class DeSerializer { 224 225 interface IAccessibleObject { 226 object Obj { get; } 227 } 228 229 class CustomObject : IAccessibleObject { 230 public object Obj { get { return this.obj; } } 231 private object obj; 232 public List<object> customValues; 233 public CustomObject(object obj) { 234 this.obj = obj; 235 this.customValues = new List<object>(); 236 } 237 public void AddValue(object value) { 238 customValues.Add(value); 239 } 240 } 241 242 class CompositeObject : IAccessibleObject{ 243 public object Obj { get { return this.obj; } } 226 244 public object obj; 227 245 public Dictionary<string, DataMemberAccessor> accessorDict; 228 public List<object> customValues; 229 public AccessibleObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) { 246 public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) { 230 247 this.obj = obj; 231 this.accessorDict = new Dictionary<string, DataMemberAccessor>(); 232 this.customValues = new List<object>(); 248 this.accessorDict = new Dictionary<string, DataMemberAccessor>(); 233 249 foreach (KeyValuePair<string, DataMemberAccessor> pair in accessorDict) { 234 250 this.accessorDict.Add( … … 238 254 } 239 255 public void SetValue(string name, object value) { 240 if (name == "") { 241 customValues.Add(value); 242 } else { 243 accessorDict[name].Set(value); 244 } 256 accessorDict[name].Set(value); 245 257 } 246 258 public void SetAllDefaultValues() { 259 throw new NotImplementedException(); 247 260 } 248 261 } … … 252 265 private Dictionary<int, object> id2obj; 253 266 private Dictionary<Type, Handler> handlers; 254 private Stack< AccessibleObject> compositeStack;267 private Stack<IAccessibleObject> compositeStack; 255 268 256 269 private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers; … … 259 272 public DeSerializer() { 260 273 id2obj = new Dictionary<int, object>(); 261 compositeStack = new Stack< AccessibleObject>();274 compositeStack = new Stack<IAccessibleObject>(); 262 275 handlers = new Dictionary<Type, Handler>(); 263 276 handlers.Add(typeof(CompositeStart), new Handler(CompositeStartHandler)); … … 278 291 handlers[token.GetType()].Invoke(token); 279 292 } 280 return compositeStack.Pop(). obj;293 return compositeStack.Pop().Obj; 281 294 } 282 295 private void CompositeStartHandler(IParseToken token) { … … 284 297 object instance = null; 285 298 if (this.FindCustomSerializer(start.Type) != null) { 286 instance = n ull;287 compositeStack.Push(new AccessibleObject(null, new Dictionary<string, DataMemberAccessor>()));288 id2obj.Add(start.Id, null);299 instance = new object(); 300 compositeStack.Push(new CustomObject(instance)); 301 id2obj.Add(start.Id, instance); 289 302 // TODO: add warning proxy 290 303 } else { … … 292 305 Dictionary<string, DataMemberAccessor> accessorDict = 293 306 StorableAttribute.GetAutostorableAccessors(instance); 294 compositeStack.Push(new AccessibleObject(instance, accessorDict));307 compositeStack.Push(new CompositeObject(instance, accessorDict)); 295 308 id2obj.Add(start.Id, instance); 296 309 } 297 310 } 298 311 private void CompositeEndHandler(IParseToken token) { 299 CompositeEnd end = (CompositeEnd)token; 300 AccessibleObject accessibleObject = compositeStack.Pop(); 312 CompositeEnd end = (CompositeEnd)token; 301 313 ICustomSerializer customSerializer = this.FindCustomSerializer(end.Type); 302 314 if (customSerializer != null) { 315 CustomObject customObject = (CustomObject)compositeStack.Pop(); 303 316 this.SetValue(end.Name, 304 customSerializer.DeSerialize( accessibleObject.customValues, end.Type));317 customSerializer.DeSerialize(customObject.customValues, end.Type)); 305 318 } else { 306 this.SetValue(end.Name, accessibleObject.obj); 319 CompositeObject compositeObject = (CompositeObject)compositeStack.Pop(); 320 this.SetValue(end.Name, compositeObject.obj); 307 321 } 308 322 } … … 329 343 private void SetValue(string name, object value) { 330 344 if (compositeStack.Count == 0) { 331 compositeStack.Push(new AccessibleObject(value, new Dictionary<string,DataMemberAccessor>())); 332 } else { 333 compositeStack.Peek().SetValue(name, value); 345 compositeStack.Push(new CompositeObject(value, new Dictionary<string,DataMemberAccessor>())); 346 } else { 347 object accessibleObject = compositeStack.Peek(); 348 if ( accessibleObject is CompositeObject ) { 349 ((CompositeObject)accessibleObject).SetValue(name, value); 350 } else if (accessibleObject is CustomObject) { 351 ((CustomObject)accessibleObject).AddValue(value); 352 } 334 353 } 335 354 }
Note: See TracChangeset
for help on using the changeset viewer.