Package muntjac :: Package terminal :: Package gwt :: Package server :: Module application_servlet
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.gwt.server.application_servlet

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  """Defines a servlet that connects a Muntjac Application to Web.""" 
 17   
 18  from muntjac.terminal.gwt.server.exceptions import ServletException 
 19   
 20  from muntjac.terminal.gwt.server.abstract_application_servlet import \ 
 21      AbstractApplicationServlet 
 22   
 23   
24 -class ApplicationServlet(AbstractApplicationServlet):
25 """This servlet connects a Muntjac Application to Web. 26 27 @author: Vaadin Ltd. 28 @author: Richard Lincoln 29 @version: 1.1.2 30 """ 31
32 - def __init__(self, applicationClass, *args, **kw_args):
33 super(ApplicationServlet, self).__init__(*args, **kw_args) 34 35 self._applicationClass = applicationClass
36 37 38 # def awake(self, transaction): 39 # """Called by the servlet container to indicate to a servlet that 40 # the servlet is being placed into service. 41 # 42 # @param servletConfig 43 # the object containing the servlet's configuration and 44 # initialization parameters 45 # @raise javax.servlet.ServletException 46 # if an exception has occurred that interferes with the 47 # servlet's normal operation. 48 # """ 49 # super(ApplicationServlet, self).awake(transaction) 50 # 51 # 52 # # Loads the application class using the same class loader 53 # # as the servlet itself 54 # 55 # # Gets the application class name 56 # applicationClassName = CONFIG.get('application') 57 # if applicationClassName is None: 58 # raise ServletException, ('Application not specified ' 59 # 'in servlet parameters') 60 # 61 # try: 62 # self._applicationClass = loadClass(applicationClassName) 63 # except ImportError: 64 # raise ServletException, ('Failed to import module: ' 65 # + applicationClassName) 66 # except AttributeError: 67 # raise ServletException, ('Failed to load application class: ' 68 # + applicationClassName) 69 70
71 - def getNewApplication(self, request):
72 # Creates a new application instance 73 try: 74 applicationClass = self.getApplicationClass() 75 application = applicationClass() 76 except TypeError: 77 raise ServletException, "getNewApplication failed" 78 79 return application
80 81
82 - def getApplicationClass(self):
83 return self._applicationClass
84 85
86 -class SingletonApplicationServlet(AbstractApplicationServlet):
87
88 - def __init__(self, applicationObject, *args, **kw_args):
89 super(SingletonApplicationServlet, self).__init__(*args, **kw_args) 90 self._applicationObject = applicationObject
91 92
93 - def getNewApplication(self, request):
94 if self._applicationObject is not None: 95 return self._applicationObject 96 else: 97 raise ServletException, "getNewApplication failed"
98 99
100 - def getApplicationClass(self):
101 return self._applicationObject.__class__
102