| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This provides a general-purpose serialization facility for Dart objects. A | 6 * This provides a general-purpose serialization facility for Dart objects. A |
| 7 * [Serialization] is defined in terms of [SerializationRule]s and supports | 7 * [Serialization] is defined in terms of [SerializationRule]s and supports |
| 8 * reading and writing to different formats. | 8 * reading and writing to different formats. |
| 9 * | 9 * |
| 10 * Setup | 10 * Setup |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 * minimum necessary information in [create] and do more of the work in | 80 * minimum necessary information in [create] and do more of the work in |
| 81 * [setState]. | 81 * [setState]. |
| 82 * | 82 * |
| 83 * The other way to do this is not creating a subclass, but by using a | 83 * The other way to do this is not creating a subclass, but by using a |
| 84 * [ClosureRule] and giving it functions for how to create | 84 * [ClosureRule] and giving it functions for how to create |
| 85 * the address. | 85 * the address. |
| 86 * | 86 * |
| 87 * addressToMap(a) => {"number" : a.number, "street" : a.street, | 87 * addressToMap(a) => {"number" : a.number, "street" : a.street, |
| 88 * "city" : a.city}; | 88 * "city" : a.city}; |
| 89 * createAddress(Map m) => new Address.create(m["number"], m["street"]); | 89 * createAddress(Map m) => new Address.create(m["number"], m["street"]); |
| 90 * fillInAddress(Map m, Address a) => a.city = m["city"]; | 90 * fillInAddress(Address a, Map m) => a.city = m["city"]; |
| 91 * var serialization = new Serialization() | 91 * var serialization = new Serialization() |
| 92 * ..addRule( | 92 * ..addRule( |
| 93 * new ClosureRule(anAddress.runtimeType, | 93 * new ClosureRule(anAddress.runtimeType, |
| 94 * addressToMap, createAddress, fillInAddress); | 94 * addressToMap, createAddress, fillInAddress); |
| 95 * | 95 * |
| 96 * In this case we have created standalone functions rather than | 96 * In this case we have created standalone functions rather than |
| 97 * methods in a subclass and we pass them to the constructor of | 97 * methods in a subclass and we pass them to the constructor of |
| 98 * [ClosureRule]. In this case we've also had them use maps rather than | 98 * [ClosureRule]. In this case we've also had them use maps rather than |
| 99 * lists for the state, but either would work as long as the rule is | 99 * lists for the state, but either would work as long as the rule is |
| 100 * consistent with the representation it uses. We pass it the runtimeType | 100 * consistent with the representation it uses. We pass it the runtimeType |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 /** | 459 /** |
| 460 * An exception class for errors during serialization. | 460 * An exception class for errors during serialization. |
| 461 */ | 461 */ |
| 462 class SerializationException implements Exception { | 462 class SerializationException implements Exception { |
| 463 final String message; | 463 final String message; |
| 464 const SerializationException([this.message]); | 464 const SerializationException([this.message]); |
| 465 } | 465 } |
| OLD | NEW |