| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library protocol; | 5 library protocol; |
| 6 | 6 |
| 7 import 'dart:convert' show JsonDecoder; | 7 import 'dart:convert' show JsonDecoder; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Instances of the class [Request] represent a request that was received. | 10 * Instances of the class [Request] represent a request that was received. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 "be a map")); | 178 "be a map")); |
| 179 } | 179 } |
| 180 if (!datum.containsKey(key)) { | 180 if (!datum.containsKey(key)) { |
| 181 throw new RequestFailure(new Response.invalidParameter(request, path, | 181 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 182 "contain key '$key'")); | 182 "contain key '$key'")); |
| 183 } | 183 } |
| 184 return new RequestDatum(request, "$path.$key", datum[key]); | 184 return new RequestDatum(request, "$path.$key", datum[key]); |
| 185 } | 185 } |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * Return `true` if the datum is a Map containing the given [key]. |
| 189 */ |
| 190 bool hasKey(String key) { |
| 191 if (datum is! Map<String, dynamic>) { |
| 192 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 193 "be a map")); |
| 194 } |
| 195 return datum.containsKey(key); |
| 196 } |
| 197 |
| 198 /** |
| 188 * Validate that the datum is a Map whose keys are strings, and call [f] on | 199 * Validate that the datum is a Map whose keys are strings, and call [f] on |
| 189 * each key/value pair in the map. | 200 * each key/value pair in the map. |
| 190 */ | 201 */ |
| 191 void forEachMap(void f(String key, RequestDatum value)) { | 202 void forEachMap(void f(String key, RequestDatum value)) { |
| 192 if (datum is! Map<String, dynamic>) { | 203 if (datum is! Map<String, dynamic>) { |
| 193 throw new RequestFailure(new Response.invalidParameter(request, path, | 204 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 194 "be a map")); | 205 "be a map")); |
| 195 } | 206 } |
| 196 datum.forEach((String key, dynamic value) { | 207 datum.forEach((String key, dynamic value) { |
| 197 f(key, new RequestDatum(request, "$path.$key", value)); | 208 f(key, new RequestDatum(request, "$path.$key", value)); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 /** | 704 /** |
| 694 * The response to be returned as a result of the failure. | 705 * The response to be returned as a result of the failure. |
| 695 */ | 706 */ |
| 696 final Response response; | 707 final Response response; |
| 697 | 708 |
| 698 /** | 709 /** |
| 699 * Initialize a newly created exception to return the given reponse. | 710 * Initialize a newly created exception to return the given reponse. |
| 700 */ | 711 */ |
| 701 RequestFailure(this.response); | 712 RequestFailure(this.response); |
| 702 } | 713 } |
| OLD | NEW |