Merge pull request #42 from colin-adams/master

Contracts for non-Void-safe users (take 3)
This commit is contained in:
Jocelyn Fiat
2013-03-15 06:39:47 -07:00
5 changed files with 54 additions and 3 deletions

View File

@@ -13,11 +13,19 @@ inherit
feature -- Mapping helper: uri feature -- Mapping helper: uri
map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER) map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER)
-- Map `h' as handler for `a_tpl'
require
a_tpl_attached: a_tpl /= Void
h_attached: h /= Void
do do
map_uri_template_with_request_methods (a_tpl, h, Void) map_uri_template_with_request_methods (a_tpl, h, Void)
end end
map_uri_template_with_request_methods (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS) map_uri_template_with_request_methods (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS)
-- Map `h' as handler for `a_tpl' for request methods `rqst_methods'.
require
a_tpl_attached: a_tpl /= Void
h_attached: h /= Void
do do
router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods)
end end
@@ -25,17 +33,25 @@ feature -- Mapping helper: uri
feature -- Mapping helper: uri agent feature -- Mapping helper: uri agent
map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]) map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]])
-- Map `proc' as handler for `a_tpl'
require
a_tpl_attached: a_tpl /= Void
proc_attached: proc /= Void
do do
map_uri_template_agent_with_request_methods (a_tpl, proc, Void) map_uri_template_agent_with_request_methods (a_tpl, proc, Void)
end end
map_uri_template_agent_with_request_methods (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS) map_uri_template_agent_with_request_methods (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS)
-- Map `proc' as handler for `a_tpl' for request methods `rqst_methods'.
require
a_tpl_attached: a_tpl /= Void
proc_attached: proc /= Void
do do
map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods)
end end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -15,6 +15,10 @@ inherit
feature -- Execution feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE) execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute `req' responding in `res'.
require
req_attached: req /= Void
res_attached: res /= Void
deferred deferred
end end

View File

@@ -21,17 +21,25 @@ feature -- Access
feature -- Change feature -- Change
set_handler (h: like handler) set_handler (h: like handler)
-- <Precursor>
do do
handler := h handler := h
ensure then
h_aliased: handler = h
end end
feature {NONE} -- Execution feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE) execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do do
h.execute (req, res) h.execute (req, res)
end end
invariant
handler_attached: handler /= Void
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -15,20 +15,27 @@ inherit
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (s: READABLE_STRING_8; h: like handler) make (s: READABLE_STRING_8; h: like handler)
-- <Precursor>
do do
make_from_template (create {URI_TEMPLATE}.make (s), h) make_from_template (create {URI_TEMPLATE}.make (s), h)
end end
make_from_template (tpl: URI_TEMPLATE; h: like handler) make_from_template (tpl: URI_TEMPLATE; h: like handler)
-- Create with `h' as the handler for resources matching `tpl'
require
tpl_attached: tpl /= Void
h_attached: h /= Void
do do
template := tpl template := tpl
set_handler (h) set_handler (h)
ensure
tpl_aliased: template = tpl
end end
feature -- Access feature -- Access
associated_resource: READABLE_STRING_8 associated_resource: READABLE_STRING_8
-- Associated resource -- URI template text of handled resource
do do
Result := template.template Result := template.template
end end
@@ -38,6 +45,9 @@ feature -- Access
feature -- Change feature -- Change
set_handler (h: like handler) set_handler (h: like handler)
-- Set `handler' to `h'.
require
h_attached: h /= Void
deferred deferred
end end
@@ -59,6 +69,7 @@ feature -- Status
end end
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
-- <Precursor>
local local
tpl: URI_TEMPLATE tpl: URI_TEMPLATE
p: READABLE_STRING_32 p: READABLE_STRING_32
@@ -88,13 +99,21 @@ feature -- Status
feature {NONE} -- Execution feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE) execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping -- Run `h' to execute `req' responding in `res'.
require
h_attached: h /= Void
req_attached: req /= Void
res_attached: res /= Void
deferred deferred
end end
feature {NONE} -- Implementation feature {NONE} -- Implementation
based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template
-- Version of `a_tpl' using bas URI of `a_router'
require
a_tpl_attached: a_tpl /= Void
a_router_attached: a_router /= Void
do do
if attached a_router.base_url as l_base_url then if attached a_router.base_url as l_base_url then
Result := a_tpl.duplicate Result := a_tpl.duplicate
@@ -102,6 +121,8 @@ feature {NONE} -- Implementation
else else
Result := a_tpl Result := a_tpl
end end
ensure
based_uri_template_attached: Result /= Void
end end
note note

View File

@@ -14,6 +14,8 @@ feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
-- New mapping object -- New mapping object
require
a_uri_attached: a_uri /= Void
deferred deferred
ensure ensure
Result_attached: Result /= Void Result_attached: Result /= Void