# HG changeset patch # User paulb # Date 1075661134 0 # Node ID 284e9a383ddc33586a42b7ff9ce30b7cf71f1506 # Parent 67b5c2debf54892e72a019a6baf73774d897a74c [project @ 2004-02-01 18:45:34 by paulb] Added a servlet factory and servlet mechanism for resource dispatching. diff -r 67b5c2debf54 -r 284e9a383ddc WebStack/Adapters/Webware.py --- a/WebStack/Adapters/Webware.py Sun Feb 01 18:45:09 2004 +0000 +++ b/WebStack/Adapters/Webware.py Sun Feb 01 18:45:34 2004 +0000 @@ -6,6 +6,76 @@ import WebStack.Webware -# NOTE: Implement a servlet factory or other appropriate Webware component. +# NOTE: Webware Experimental seems to employ special URLParsers in contexts +# NOTE: which are much more compatible with the WebStack approach. + +from WebKit.ServletFactory import ServletFactory +from WebKit.Servlet import Servlet + +class WebStackServletFactory(ServletFactory): + + """ + A servlet factory object producing servlets which provide access to + application-specific resources. + """ + + def __init__(self, application, resource, file_extensions): + + """ + Initialise the servlet factory with the Webware 'application' and the + WebStack root application-specific 'resource'. The 'file_extensions' + specified indicate for which files this factory is invoked. + """ + + ServletFactory.__init__(self, application) + self.webstack_resource = resource + self.file_extensions = file_extensions + + def uniqueness(self): + + """ + Return "file" uniqueness - probably the most appropriate response. + """ + + return "file" + + def extensions(self): + + """ + Return the file extensions supported by this factory. + """ + + return self.file_extensions + + def servletForTransaction(self, trans): + + """ + Return a servlet which will provide access to the application-specific + resources. The 'trans' object - a Webware transaction - is not given to + the servlet since such information is available when the 'respond' + method is invoked on the servlet. + """ + + return WebStackServlet(self.webstack_resource) + +class WebStackServlet(Servlet): + + "A servlet which dispatches transactions to application-specific resources." + + def __init__(self, resource): + + "Initialise the servlet with an application-specific 'resource'." + + self.webstack_resource = resource + + def respond(self, trans): + + """ + Respond to the incoming transaction, 'trans', by dispatching to the + application-specific resource. + """ + + new_trans = WebStack.Webware.Transaction(trans) + self.webstack_resource.respond(new_trans) # vim: tabstop=4 expandtab shiftwidth=4