From c6d022bf18573e3b70c6e817928f6af43dba55c3 Mon Sep 17 00:00:00 2001 From: Colin Adams Date: Fri, 15 Mar 2013 10:16:32 +0000 Subject: [PATCH 1/2] Third iteration of contracts for non-Void-safe users --- .../uri_template/wsf_uri_template_handler.e | 4 +++ .../uri_template/wsf_uri_template_mapping.e | 8 ++++++ .../uri_template/wsf_uri_template_mapping_i.e | 25 +++++++++++++++++-- .../wsf/router/wsf_router_mapping_factory.e | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e index e049154d..0e14102c 100644 --- a/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_handler.e @@ -15,6 +15,10 @@ inherit feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute `req' responding in `res'. + require + req_attached: req /= Void + res_attached: res /= Void deferred end diff --git a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e index 5fc830fa..31d6285d 100644 --- a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping.e @@ -21,17 +21,25 @@ feature -- Access feature -- Change set_handler (h: like handler) + -- do handler := h + ensure then + h_aliased: handler = h end feature {NONE} -- Execution execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE) + -- do h.execute (req, res) end +invariant + + handler_attached: handler /= Void + note 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)" diff --git a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e index 3abf5f66..0a047949 100644 --- a/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e +++ b/library/server/wsf/router/support/uri_template/wsf_uri_template_mapping_i.e @@ -15,20 +15,27 @@ inherit feature {NONE} -- Initialization make (s: READABLE_STRING_8; h: like handler) + -- do make_from_template (create {URI_TEMPLATE}.make (s), h) end 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 template := tpl set_handler (h) + ensure + tpl_aliased: template = tpl end feature -- Access associated_resource: READABLE_STRING_8 - -- Associated resource + -- URI template text of handled resource do Result := template.template end @@ -38,6 +45,9 @@ feature -- Access feature -- Change set_handler (h: like handler) + -- Set `handler' to `h'. + require + h_attached: h /= Void deferred end @@ -59,6 +69,7 @@ feature -- Status end routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER + -- local tpl: URI_TEMPLATE p: READABLE_STRING_32 @@ -88,13 +99,21 @@ feature -- Status feature {NONE} -- Execution 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 end feature {NONE} -- Implementation 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 if attached a_router.base_url as l_base_url then Result := a_tpl.duplicate @@ -102,6 +121,8 @@ feature {NONE} -- Implementation else Result := a_tpl end + ensure + based_uri_template_attached: Result /= Void end note diff --git a/library/server/wsf/router/wsf_router_mapping_factory.e b/library/server/wsf/router/wsf_router_mapping_factory.e index 5d4e3d4e..88eac0dd 100644 --- a/library/server/wsf/router/wsf_router_mapping_factory.e +++ b/library/server/wsf/router/wsf_router_mapping_factory.e @@ -14,6 +14,8 @@ feature {WSF_ROUTER} -- Mapping new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING -- New mapping object + require + a_uri_attached: a_uri /= Void deferred ensure Result_attached: Result /= Void From bb56166f959df9367a208abdef68c34e4f6dc2ee Mon Sep 17 00:00:00 2001 From: Colin Adams Date: Fri, 15 Mar 2013 12:01:54 +0000 Subject: [PATCH 2/2] Fourth round of contracts for non-Void-safe users --- .../helpers/wsf_uri_template_routed_service.e | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e index 018f3c86..7dc8b5a6 100644 --- a/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e +++ b/library/server/wsf/router/support/uri_template/helpers/wsf_uri_template_routed_service.e @@ -13,11 +13,19 @@ inherit feature -- Mapping helper: uri 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 map_uri_template_with_request_methods (a_tpl, h, Void) end 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 router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) end @@ -25,17 +33,25 @@ feature -- Mapping helper: uri 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 `proc' as handler for `a_tpl' + require + a_tpl_attached: a_tpl /= Void + proc_attached: proc /= Void do map_uri_template_agent_with_request_methods (a_tpl, proc, Void) 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 `proc' as handler for `a_tpl' for request methods `rqst_methods'. + require + a_tpl_attached: a_tpl /= Void + proc_attached: proc /= Void do map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) end 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)" source: "[ Eiffel Software