# HG changeset patch # User paulb # Date 1076197080 0 # Node ID 94e00d0253461d5625ae4402c8b739db97b934d6 # Parent dd3406d710fb72f0cb75fb145c007d833acd4ecb [project @ 2004-02-07 23:38:00 by paulb] Added support for URLParser usage with Webware beyond 0.8.1. Added a call to Servlet.__init__ within WebStackServlet (required for later Webware releases). diff -r dd3406d710fb -r 94e00d025346 WebStack/Adapters/Webware.py --- a/WebStack/Adapters/Webware.py Sat Feb 07 23:37:17 2004 +0000 +++ b/WebStack/Adapters/Webware.py Sat Feb 07 23:38:00 2004 +0000 @@ -6,8 +6,53 @@ import WebStack.Webware -# NOTE: Webware Experimental seems to employ special URLParsers in contexts -# NOTE: which are much more compatible with the WebStack approach. +# For Webware releases later than 0.8.1, employ special URLParsers in contexts +# for each application in the application server; such parsers create servlets +# instead of having servlet factories do that work. + +try: + from WebKit.URLParser import URLParser + +except ImportError: + + # NOTE: Using Webware 0.8.1 or earlier. Assume that this really is the case. + + pass + +else: + class WebStackURLParser(URLParser): + + """ + A custom URL parser which provides access to application-specific resources. + Override the 'parse' method for more precise control of servlet + instantiation. + """ + + def __init__(self, resource): + + """ + Initialise the parser object with the given root application-specific + 'resource'. + """ + + self.webstack_resource = resource + + def parse(self, trans, requestPath): + + """ + For the given Webware transaction, 'trans', override the usual servlet + factory mechanism and 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. + The provided 'requestPath' object is not used, since this information + should be available elsewhere. + """ + + return WebStackServlet(self.webstack_resource) + +# For Webware 0.8.1 and earlier, employ servlet factories and servlets. from WebKit.ServletFactory import ServletFactory from WebKit.Servlet import Servlet @@ -58,6 +103,8 @@ return WebStackServlet(self.webstack_resource) +# Servlets are common to both solutions. + class WebStackServlet(Servlet): "A servlet which dispatches transactions to application-specific resources." @@ -66,6 +113,7 @@ "Initialise the servlet with an application-specific 'resource'." + Servlet.__init__(self) self.webstack_resource = resource def respond(self, trans):