parse method
Parse T
by given propertyMap
.
This method is not designed for inhertance since it defines all
standardized properties in Map and convert to all builtin Dart object
to createProperty
.
If the property is incompleted, InvalidPropertyMapException
will be thrown.
If the parser does not support url scheme, StateError will be thrown.
Implementation
@protected
@mustCallSuper
T parse(Map<String, dynamic> propertyMap) {
late final Uri url;
late final bool accessible;
try {
url = Uri.parse(propertyMap["url"]);
accessible = propertyMap["accessible"];
} on TypeError {
throw InvalidPropertyMapException._(propertyMap);
}
final Duration timeout = Duration(seconds: propertyMap["timeout"] ?? 10);
final int? tryCount = propertyMap["try_count"];
if (!supportedSchemes
.any((element) => element.toLowerCase() == url.scheme)) {
throw StateError(
"URL scheme '${url.scheme}' is not handled by this processor.");
} else if ((tryCount != null) && !accessible) {
throw InvalidPropertyMapException._(propertyMap);
}
return createProperty(
url,
timeout,
accessible,
tryCount,
UnmodifiableMapView(Map.fromEntries(propertyMap.entries.where(
(element) => !{"url", "timeout", "accessible", "try_count"}
.contains(element)))));
}