| Index: runtime/bin/service_object_patch.dart
|
| diff --git a/runtime/bin/service_object_patch.dart b/runtime/bin/service_object_patch.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f23dd71b472627838b9014dd27fcc7c7e45375a8
|
| --- /dev/null
|
| +++ b/runtime/bin/service_object_patch.dart
|
| @@ -0,0 +1,52 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +
|
| +final Map _servicePathMap = {
|
| + 'http' : {
|
| + 'servers' : _httpServersServiceObject
|
| + }
|
| +};
|
| +
|
| +String _serviceObjectHandler(List<String> paths,
|
| + List<String> keys,
|
| + List<String> values) {
|
| + assert(keys.length == values.length);
|
| + badPath() {
|
| + throw "Invalid path '${paths.join("/")}'";
|
| + }
|
| + if (paths.isEmpty) {
|
| + badPath();
|
| + }
|
| + int i = 0;
|
| + var current = _servicePathMap;
|
| + do {
|
| + current = current[paths[i]];
|
| + i++;
|
| + } while (i < paths.length && current is Map);
|
| + if (current is! Function) {
|
| + badPath();
|
| + }
|
| + var query = new Map();
|
| + for (int i = 0; i < keys.length; i++) {
|
| + query[keys[i]] = values[i];
|
| + }
|
| + return JSON.encode(current(paths.sublist(i)));
|
| +}
|
| +
|
| +Map _httpServersServiceObject(args) {
|
| + if (args.length == 1) {
|
| + var server = _HttpServer._servers[int.parse(args.first)];
|
| + if (server == null) {
|
| + return {};
|
| + }
|
| + return server._toJSON(false);
|
| + }
|
| + return {
|
| + 'id': 'io/http/servers',
|
| + 'type': 'HttpServerList',
|
| + 'members': _HttpServer._servers.values
|
| + .map((server) => server._toJSON(true)).toList(),
|
| + };
|
| +}
|
|
|