OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /** |
| 6 * A collection of [Extension] objects, organized by the message type they |
| 7 * extend. |
| 8 */ |
| 9 class ExtensionRegistry { |
| 10 |
| 11 Map<String, Map<int, Extension>> _extensions; |
| 12 |
| 13 ExtensionRegistry() : _extensions = |
| 14 new Map<String, Map<int, Extension>>(); |
| 15 |
| 16 static ExtensionRegistry _EMPTY_REGISTRY; |
| 17 |
| 18 static ExtensionRegistry get EMPTY_REGISTRY() { |
| 19 if (_EMPTY_REGISTRY == null) { |
| 20 _EMPTY_REGISTRY = new _EmptyExtensionRegistry(); |
| 21 } |
| 22 return _EMPTY_REGISTRY; |
| 23 } |
| 24 |
| 25 /** |
| 26 * Store an extension in the registry. |
| 27 */ |
| 28 void add(Extension extension) { |
| 29 Map<int, Extension> map = _extensions[extension.extendee]; |
| 30 if (map == null) { |
| 31 map = new Map<int, Extension>(); |
| 32 _extensions[extension.extendee] = map; |
| 33 } |
| 34 map[extension.tagNumber] = extension; |
| 35 } |
| 36 |
| 37 /** |
| 38 * Retrieve an extension from the registry that adds the given tag |
| 39 * number to the given message type. |
| 40 */ |
| 41 Extension getExtension(String messageName, int tagNumber) { |
| 42 Map<int, Extension> map = _extensions[messageName]; |
| 43 if (map != null) { |
| 44 return map[tagNumber]; |
| 45 } |
| 46 return null; |
| 47 } |
| 48 } |
| 49 |
| 50 class _EmptyExtensionRegistry extends ExtensionRegistry { |
| 51 void add(Extension extension) { |
| 52 throw new UnsupportedOperationException("Immutable ExtensionRegistry"); |
| 53 } |
| 54 |
| 55 Extension getExtension(String messageName, int tagNumber) => null; |
| 56 } |
OLD | NEW |