Added missing "context" classes for uri and starts_with mapping+handler (and helper classes).

So that it is address more needs.
Factorized code between "context" and non context classes.
This commit is contained in:
Jocelyn Fiat
2012-12-13 10:58:08 +01:00
parent 025457747b
commit cb034fc94e
27 changed files with 778 additions and 215 deletions

View File

@@ -0,0 +1,45 @@
note
description: "Summary description for {WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_STARTS_WITH_CONTEXT_HANDLER [C]
create
make
feature -- Change
make (a_action: like action)
do
action := a_action
end
feature -- Access
action: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; context: C; request: WSF_REQUEST; response: WSF_RESPONSE]]
feature -- Execution
execute (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
action.call ([a_start_path, ctx, req, res])
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {WSF_STARTS_WITH_CONTEXT_ROUTED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STARTS_WITH_CONTEXT_ROUTED_SERVICE [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_ROUTED_SERVICE
feature -- Mapping helper: starts_with
map_starts_with (a_uri: READABLE_STRING_8; h: WSF_STARTS_WITH_CONTEXT_HANDLER [C])
do
map_starts_with_request_methods (a_uri, h, Void)
end
map_starts_with_request_methods (a_uri: READABLE_STRING_8; h: WSF_STARTS_WITH_CONTEXT_HANDLER [C]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_with_request_methods (create {WSF_STARTS_WITH_CONTEXT_MAPPING [C]}.make (a_uri, h), rqst_methods)
end
feature -- Mapping helper: starts_with agent
map_starts_with_agent (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]])
do
map_starts_with_agent_with_request_methods (a_uri, proc, Void)
end
map_starts_with_agent_with_request_methods (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
map_starts_with_request_methods (a_uri, create {WSF_STARTS_WITH_AGENT_CONTEXT_HANDLER [C] }.make (proc), rqst_methods)
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,39 @@
note
description: "Summary description for {WSF_STARTS_WITH_ROUTING_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_STARTS_WITH_ROUTING_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_ROUTING_HANDLER
WSF_STARTS_WITH_CONTEXT_HANDLER [C]
rename
execute as execute_with_context
end
create
make,
make_with_router
feature -- Execution
execute_with_context (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
execute (req, res)
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,38 @@
note
description: "Summary description for {WSF_STARTS_WITH_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STARTS_WITH_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_HANDLER
WSF_ROUTER_MAPPING_FACTORY
feature -- Execution
execute (a_start_path: READABLE_STRING_8; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create {WSF_STARTS_WITH_CONTEXT_MAPPING [C]} Result.make (a_uri, Current)
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,64 @@
note
description: "Summary description for WSF_STARTS_WITH_CONTEXT_MAPPING."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_STARTS_WITH_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_STARTS_WITH_MAPPING_I
undefine
debug_output
end
WSF_ROUTER_MAPPING
redefine
debug_output
end
create
make
feature -- Access
handler: WSF_STARTS_WITH_CONTEXT_HANDLER [C]
feature -- change
set_handler (h: like handler)
do
handler := h
end
feature {NONE} -- Execution
execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping
local
ctx: C
do
create ctx.make (req, Current)
h.execute (a_start_path, ctx, req, res)
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := Precursor + " {" + ({C}).name + "}"
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -1,5 +1,5 @@
note
description: "Summary description for EWF_STARTS_WITH_PATH."
description: "Summary description for WSF_STARTS_WITH_MAPPING."
author: ""
date: "$Date$"
revision: "$Revision$"
@@ -8,69 +8,28 @@ class
WSF_STARTS_WITH_MAPPING
inherit
WSF_ROUTER_MAPPING
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
WSF_STARTS_WITH_MAPPING_I
create
make
feature {NONE} -- Initialization
make (a_uri: READABLE_STRING_8; h: like handler)
do
handler := h
uri := a_uri
end
feature -- Access
associated_resource: READABLE_STRING_8
-- Associated resource
do
Result := uri
end
handler: WSF_STARTS_WITH_HANDLER
uri: READABLE_STRING_8
feature -- change
feature -- Documentation
description: STRING_32 = "Starts-With-URI"
feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
-- Return the handler if Current matches the request `req'.
local
p: READABLE_STRING_8
s: like based_uri
set_handler (h: like handler)
do
p := path_from_request (req)
s := based_uri (uri, a_router)
if p.starts_with (s) then
Result := handler
a_router.execute_before (Current)
handler.execute (s, req, res)
a_router.execute_after (Current)
end
handler := h
end
feature {NONE} -- Implementation
feature {NONE} -- Execution
based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri
-- `uri' prefixed by the `WSF_ROUTER.base_url' if any
local
s: STRING_8
execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping
do
if attached a_router.base_url as l_base_url then
create s.make_from_string (l_base_url)
s.append_string (a_uri)
Result := s
else
Result := a_uri
end
h.execute (a_start_path, req, res)
end
note

View File

@@ -0,0 +1,105 @@
note
description: "Summary description for WSF_STARTS_WITH_MAPPING_I."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STARTS_WITH_MAPPING_I
inherit
WSF_ROUTER_MAPPING
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
feature {NONE} -- Initialization
make (a_uri: READABLE_STRING_8; h: like handler)
do
set_handler (h)
uri := a_uri
end
feature -- Access
associated_resource: READABLE_STRING_8
-- Associated resource
do
Result := uri
end
uri: READABLE_STRING_8
feature -- Change
set_handler (h: like handler)
deferred
end
feature -- Documentation
description: STRING_32 = "Starts-With-URI"
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
local
p: READABLE_STRING_8
s: like based_uri
do
p := path_from_request (req)
s := based_uri (uri, a_router)
Result := p.starts_with (s)
end
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
-- Return the handler if Current matches the request `req'.
local
p: READABLE_STRING_8
s: like based_uri
do
p := path_from_request (req)
s := based_uri (uri, a_router)
if p.starts_with (s) then
Result := handler
a_router.execute_before (Current)
execute_handler (handler, s, req, res)
a_router.execute_after (Current)
end
end
feature {NONE} -- Execution
execute_handler (h: like handler; a_start_path: like uri; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping
deferred
end
feature {NONE} -- Implementation
based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri
-- `uri' prefixed by the `WSF_ROUTER.base_url' if any
local
s: STRING_8
do
if attached a_router.base_url as l_base_url then
create s.make_from_string (l_base_url)
s.append_string (a_uri)
Result := s
else
Result := a_uri
end
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end