>>>>> "Berend" == Berend de Boer <berend@...> writes:
Berend> Also, I think we need an additional require for `resolve'
Berend> that the given URI is valid for the scheme.
Colin> I think that this is too much to ask, as such a pre-condition
Colin> cannot, in general be written, as it would need knowledge of
Colin> all possible URI schemes, which is impossible.
Berend> I'm afraid this isn't good enough. DbC promises that if
Berend> you meet the preconditions, the postcondition will be
Berend> met. In this case the caller doesn't meet the
Berend> postconditions.
Berend> At the minimum I suggest there should be a feature per
Berend> XM_URI_RESOLVER with scheme specific checks.
I'm replying on gobo-eiffel-develop, as this is where this discussion
needs to take place.
{XM_URI_RESOLVER}.resolve is called from
{XM_SIMPLE_URI_EXTERNAL_RESOLVER}.resolve and resolve_uri
via resolve_absolute_uri
Both of these are passed a STRING (not a UT_URI), whose only
pre-requisite is that it is non-Void, as these STRINGs are coming
straight out of XML source files.
resolve_absolute_uri receives a UT_URI which has already been made
absolute (if possible).
It then checks the scheme to find a suitable XM_URI_RESOLVER, and if
it doesn't find one, reports an unkown scheme error.
When it does find one, it simply calls resolve on that resolver,
expecting the resolver to provide a suitable diagnostic message if it
cannot resolve the URI.
The alternative you are suggesting would be to have a routine
is_valid_uri (a_uri: UT_URI): BOOLEAN
on XM_URI_RESOLVER.
If this were the case, and resolve_absolute_uri calls it
and gets a False result, then it could issue a catch-all message
"URI is invalid for scheme " + scheme,
or it could query the XM_URI_RESOLVER's last_error routine to get a
more helpful (perhaps) diagnostic.
The latter seems better to me, but this is what in effect already
happens, but without the call to is_valid_uri.
I think the present behaviour is better, but the
post-conditions of {XM_URI_RESOLVER}.resolve are at present the empty
set.
So I think it would be better to add post-conditions to
{XM_URI_RESOLVER}.resolve such as:
resolve (a_uri: UT_URI) is
-- Resolve URI to stream.
require
a_uri_not_void: a_uri /= Void
a_uri_absolute: a_uri.is_absolute
a_uri_scheme: STRING_.same_string (scheme, a_uri.scheme)
deferred
ensure
stream_open_on_sucess: not has_error implies
last_stream /= Void and then last_stream.is_open_read
end
Now I also note that the pre-condition:
a_uri_absolute: a_uri.is_absolute
does not appear to be 100% guarenteed by resolve_absolute_uri. I think
it need amending to check this, and set an appropriate error.
--
Colin Paul Adams
Preston Lancashire
|