滿店香的家

          學習+實踐=進步

          第四部分 DWRServlet類分析

              org.directwebremoting.servlet.DwrServlet主要分為三部分,也就是三個主要方法:init;doGet;doPost;
              1,init,初始化。    
              DWR對于Servelet容器內(nèi)部設(shè)一個配置容器,該容器裝載dwr映射相關(guān)信息。

          public void init(ServletConfig servletConfig) throws ServletException
              
          {
                  
          super.init(servletConfig);
                  ServletContext servletContext 
          = servletConfig.getServletContext();

                  
          try
                  
          {
                      
          // setupLogging() only needed for servlet logging if commons-logging is unavailable
                      
          // logStartup() just outputs some version numbers
                      日志初始化開始
                      StartupUtil.logStartup(servletConfig);

                      
          // create and setup a DefaultContainer
                       DWR對于Servelet容器內(nèi)部設(shè)一個配置容器,該容器裝載dwr隱射相關(guān)信息。
                      container 
          = ContainerUtil.createAndSetupDefaultContainer(servletConfig);

                      StartupUtil.initContainerBeans(servletConfig, servletContext, container);
                      webContextBuilder 
          = container.getBean(WebContextBuilder.class);

                      ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, 
          this);
                      ContainerUtil.publishContainer(container, servletConfig);
                      ContainerUtil.configureContainerFully(container, servletConfig);
                  }

                  
          catch (ExceptionInInitializerError ex)
                  
          {
                      log.fatal(
          "ExceptionInInitializerError. Nested exception:", ex.getException());
                      
          throw new ServletException(ex);
                  }

                  
          catch (Exception ex)
                  
          {
                      log.fatal(
          "DwrServlet.init() failed", ex);
                      
          throw new ServletException(ex);
                  }

                  
          finally
                  
          {
                      
          if (webContextBuilder != null)
                      
          {
                          webContextBuilder.unset();
                      }

                  }

              }



          比較細致的環(huán)節(jié):
           init()調(diào)用
               createAndSetupDefaultContainer()
                  調(diào)用
                   setupDefaultContainer(defaultContainer, servletConfig)
                       調(diào)用如下步驟
                             1)setupDefaults(container);
                             包括:
                             容器相關(guān)管理工具配置集,也就是要實現(xiàn)的一些接口。這種方式蠻好,當容器需要具備很多接口功能時,把這些接口全部做成隱射,并設(shè)置成可配置的實現(xiàn)
                              container.addImplementation(AccessControl.class, DefaultAccessControl.class);
                              // Mapping handlers to URLs,路徑配置
                              createUrlMapping(container, "/index.html", IndexHandler.class, "indexHandlerUrl");
                              //讀取servlet配置屬性
                             2)setupFromServletConfig(container, servletConfig);
                               額外處理1)中多選類型
                             3)resolveMultipleImplementations(container, servletConfig);

                              里面使用了通用yui型壓縮器 
                             【使用 YUI Compressor 壓縮 Javascript 和 CSS 
                  
                              工具下載: http://www.julienlecomte.net/yuicompressor/ 
                              英文介紹: http://com3.devnet.re3.yahoo.com/yui/compressor/

                              YUI Compressor是使用Java編寫的工具,需要Java版本大于等于1.4。

                              工作原理簡介: 
                              主要是去掉冗余的空白,主要包括空格,換行符、制表符。 
                              對于 Javascript,還采用縮短變量名的方法壓縮文件,就是在保證代碼正確性的情況下將變量名用只有1個字符的字符串代替,或者2個、3個字符,總之盡量短。 
                              對于 CSS,還有采用優(yōu)化0值屬性值的表示,優(yōu)化顏色值的方法壓縮文件。 
                               CSS的優(yōu)化比 CSSTidy 功能弱。CSSTidy還能支持一些相關(guān)屬性的合并。】
                               //工具配置集 加載,顯現(xiàn),檢查
                             4)container.setupFinished();
                               容器內(nèi)容bean初始化 ,包括系統(tǒng)默認???
                               initContainerBeans

              2,doGet
            實際調(diào)用doPost,看到這里最好溫習下servlet的doGet方法和doPost的區(qū)別
          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
              
          {
                  doPost(req, resp);
              }

              3,doPost
             在工程中,有個樣例Dynamically Text,地址是http://localhost:5050/dwr/simpletext/index.html,當點擊按鈕時,實際上就是觸發(fā)了org.directwebremoting.servlet.DwrServlet的下面的方法。
          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
              
          {
                  
          try
                  
          {
                      webContextBuilder.set(request, response, getServletConfig(), getServletContext(), container);

                      UrlProcessor processor 
          = container.getBean(UrlProcessor.class);
                      processor.handle(request, response);
                  }

                  
          finally
                  
          {
                      webContextBuilder.unset();
                  }

              }

          posted on 2008-03-28 01:41 滿店香 閱讀(1611) 評論(0)  編輯  收藏 所屬分類: dwr源碼分析

          主站蜘蛛池模板: 翼城县| 沐川县| 龙井市| 衡山县| 衡阳县| 娱乐| 宣化县| 怀化市| 岳普湖县| 宜章县| 安达市| 常德市| 佛山市| 简阳市| 特克斯县| 牡丹江市| 青海省| 尉氏县| 郸城县| 荆门市| 剑河县| 平舆县| 监利县| 大丰市| 天津市| 临武县| 秦安县| 涞源县| 平武县| 攀枝花市| 新乡市| 南京市| 开阳县| 五峰| 上思县| 丰镇市| 桐柏县| 夏河县| 四子王旗| 黔西县| 乌鲁木齐县|