Asktalk

          天行健,君子以自強不息!
          posts - 21, comments - 79, trackbacks - 0, articles - 2
            BlogJava :: 首頁 ::  :: 聯系 :: 聚合  :: 管理

          2007年12月22日

           

          這是一個目前最好的一個開源分頁標簽的實現---extremeTable標簽。今天談談它的Limit的設計架構思想。

          這個設計很通用,經過作者的多次重構,現在extremeTable的架構非常漂亮。這個標簽現在缺點是有些參數對mvc控制器屏蔽了,應提供一致的對外接口。不過整體上設計還是很精致的,面向對象來處理 html元素,與spring非常的默契,非常便于開發和測試。

          類圖關系

          1, 工廠LimitFactory

          TableLimitFactoryAbstractLimitFactoryLimitFactory

          TableLimitFactory是最終實現的工廠,它extendsAbstractLimitFactory抽象類,AbstractLimitFactory implementsLimitFactory接口。

          TableLimitFactory主要是用來實例化,通過構造函數傳入參數。同時創建Registry來完成jsp頁面參數傳入Registry。當然還有一個功能就是從web.xml的配置文件讀取一些全局參數。首先讀取配置文件參數,然后根據參數創建LimitRegistry對象。

          this.registry = new LimitRegistry(context, tableId, prefixWithTableId, state, stateAttr);

          AbstractLimitFactory主要是用來獲取jsp頁面上設置的參數,比如分頁的信息(第幾頁,起始行,結束行,每頁顯示行數,查詢條件,排序條件等),當然他是通過工具類Registry來實現。

          2, Limit

          TableLimitLimit。其主要作用是一個參數參數器,就是把Registry對象的參數傳入TableLimit,考慮到分層吧,TableLimit是該標簽和action通信的橋梁。就像我們的j2ee項目vodaostrutsview等數據傳輸工具。

          3, Preferences

          TablePropertiesProperties 主要是來實現從web.xml配置的文件中讀取配置的一些全局參數。

          InputStream input = this.getClass().getResourceAsStream(preferencesLocation);

          if (input != null) {

          properties.load(input);

          }

          其中preferencesLocation是路徑,在TableLimitFactory初始化時候,通過工具類TableModelUtils.getPreferencesLocation(context)獲取。

          這個設計也是大多數需要配置文件的系統常用的方法。

          4, Registry

          LimitRegistryAbstractRegistryRegistry

          這個體系結構和上面的工廠模式一樣,就是LimitRegistry主要是用來實例化,通過構造函數傳入參數。AbstractRegistry是實際實現類,獲取jsp表單提交的參數,并提供getter方法供Limit來使用。Registry是一個接口。

          所以這設計模式,我們可以來學習,

          經典表述:抽象類接口

          類:初始化,定義構造函數,傳入參數。

          抽象類:定義業務方法在此。

          接口:定義接口方法,這個不用多說。

          (作者:asktalk   來自 http://www.aygfsteel.com/askltak 原創文章,轉載請注明出處)

          posted @ 2007-12-26 16:17 Asktalk 閱讀(4611) | 評論 (5)編輯 收藏

           

          下面是從struts的角度來談談spring自帶的web框架的使用。
          當然,我們在配置
          web框架前,需要把spring配置好,這里就不多說了。

          1.web框架核心servletweb.xml中的配置。


           

           1<servlet>  
           2<servlet-name>Dispatcher</servlet-name>  
           3<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  <init-param>   
           4<param-name>contextConfigLocation</param-name>   <param-value>/WEB-INF/Config.xml</param-value>
           5  </init-param> 
           6</servlet>  
           7
           8<servlet-mapping>  
           9<servlet-name>Dispatcher</servlet-name>  
          10<url-pattern>*.do</url-pattern>
          11 </servlet-mapping>
          12

           

          如果沒有配置config.xml文件,那么其默認的配置文件為[ servlet-name ]-servlet.xml 。也就是我們這個配置的默認配置文件是Dispatcher-servlet.xml

          2.web框架的xml配置

          spring web框架與struts最大的不同就是spring web框架根據分工,把每一種功能都定義為一種組件,所以在開發過程中需要配置的東西就非常多;Spring中分為幾個角色:

          核心控制器,就是web框架的主 servlet

          業務控制器,也就是struts中的action對象;

          映射處理器,定義了訪問路徑如何與webxml中的bean相匹配,就是定義了一種策略;

          視圖和視圖解析器,視圖就是jstl,velocity,xslt等,視圖解析器定義了action最終導航頁面的策略;

          模型,就是struts MVC結構中的model

          Command對象,類似于struts中的formBean

          2.1 Spring web框架與struts框架的區別

          下面列出了一些。例如,

          Web框架要攔截*.do路徑,那么*.do如何與我們下面的bean匹配,就需要一個映射控制器。在struts中就是名字相同的匹配,不需要配置。

          action最后要導向到不同的頁面,在struts中我們用的是默認的不需要在xml文件中配置,在spring中就需要配置視圖解析器。

          下面代碼中,ActioncommandClass配置的就是類似于struts中的formBean對象。

           1<?xml version="1.0" encoding="UTF-8"?>
           2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
           3 "http://www.springframework.org/dtd/spring-beans.dtd">
           4<beans>
           5 <!--Definition of View Resolver -->
           6 <bean id="viewResolver"
           7  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
           8  <property name="viewClass"> 
           9   <value>org.springframework.web.servlet.view.JstlView</value>
          10  </property>
          11  <property name="prefix">
          12   <value>/WEB-INF/view/</value>
          13  </property>
          14  <property name="suffix">
          15   <value>.jsp</value>
          16  </property>
          17 </bean>
          18  
          19<!—就是我們上面說的映射控制器 -->
          20 <!--Request Mapping -->
          21 <bean id="urlMapping"
          22  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          23  <property name="mappings">
          24   <props>
          25    <prop key="/login.do">LoginAction</prop>
          26   </props>
          27  </property>
          28 </bean>
          29 
          30<!---類似于struts的action配置-->
          31 <!---Action Definition-->
          32 <bean id="LoginAction"
          33  class="com.maxway.action.LoginAction">
          34  <property name="commandClass">
          35   <value>com.maxway.action.LoginInfo</value>
          36  </property>
          37  <property name="fail_view">
          38   <value>loginfail</value>
          39  </property>
          40  <property name="success_view">
          41   <value>main</value>
          42  </property>
          43 </bean>
          44</beans>
          45


           

          3.代碼的編寫

          Action不外乎繼承一些現成的類,來實現我們view部分的業務。
          作者:http://www.aygfsteel.com/asktalk

          posted @ 2007-12-25 02:23 Asktalk 閱讀(4322) | 評論 (0)編輯 收藏

           

          最近我一直在研究Eclipse的架構體系,下面我們就來看看Eclipse的啟動機制吧

          1Eclipse源代碼       
          eclipse-sourceBuild-srcIncluded-3.3.1.1.zip   
          版本:3.3.1.1        大小:95.058MB
          下載地址:http://download.eclipse.org/eclipse/downloads

          解壓后的目錄結構如下圖,通過執行build.bat可以編譯出完整的Eclipse-sdk-3.3.1.1運行包,和我們網上下載的一樣。但是這個過程可能需要一個小時左右的時間,要有耐性哦。所有的插件工程目錄在plugins中,我們只需要導入現有工程即可把plugins下所有工程導入。

          下面我們就先來研究一下Eclipse最核心的部分,就是RCP部分必須的插件。下面我列出了Eclipse RCP需要的插件。

          將這些代碼解壓縮到一個空目錄里,然后導入到Source InsightProject里。     

          二、Eclipse啟動過程

          首先我們從Eclipse的啟動過程開始分析。

          1exe部分的引導

          eclipse.exeEclipse的啟動文件,是與平臺相關的可執行文件。它的功能比較簡單,主要是加載startup.jar文件,代碼在Eclipse源代碼的eclipse-sourceBuild-srcIncluded-3.3.1.1"plugins"org.eclipse.platform"launchersrc.zip,對應多個平臺。對于win32平臺,你可以直接運行win32目錄下的build.bat文件來編譯得到它(需要安裝C編譯器)。

          2java代碼部分的執行入口

          對于Eclipse 3.3.1.1版本來說,如果在eclipse目錄下沒有找到startup.jar,則直接執行org.eclipse.equinox.launcher.Main.main方法。

          當然我們可以在eclipse目錄下定制我們自己的啟動引導包startup.jar,現在Eclipse 3.3.1.1好像已經不建議這樣做了。如果有這個包,那么這個包將是java代碼的執行入口,你可以在命令行下運行java -jar startup.jar命令來啟動Eclipse。它的入口是org.eclipse.core.launcher.Main類,這個類最終執行的還是org.eclipse.equinox.launcher.Main.main方法。它對應的源代碼在org.eclipse.equinox.launcher目錄下的Main.java。關于此文件的定制詳細信息請查看eclipse-sourceBuild-srcIncluded-3.3.1.1"plugins"org.eclipse.platform"launchersrc.zip中的eclipse.c的注解部分。

          我們從main函數往后跟蹤,找到basicRun方法,這個是啟動的主要部分。

              protectedvoid basicRun(String[] args) throws Exception {

                  System.getProperties().put("eclipse.startTime", Long.toString(System.currentTimeMillis())); //$NON-NLS-1$

                  commands = args;

                  String[] passThruArgs = processCommandLine(args);

                 

                  if (!debug)

                     // debug can be specified as system property as well

                     debug = System.getProperty(PROP_DEBUG) != null;

                  setupVMProperties();     //設置VM屬性

                  processConfiguration();   //讀取configuration/config.ini配置文件

                 

                  // need to ensure that getInstallLocation is called at least once to initialize the value.

                  // Do this AFTER processing the configuration to allow the configuration to set

                  // the install location. 

                  getInstallLocation();

                  // locate boot plugin (may return -dev mode variations)

                  URL[] bootPath = getBootPath(bootLocation);

                  

                  //Set up the JNI bridge. We need to know the install location to find the shared library

                  setupJNI(bootPath);

                 

                  //ensure minimum Java version, do this after JNI is set up so that we can write an error message

                  //with exitdata if we fail.

                  if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$

                      return;

                 

                  setSecurityPolicy(bootPath); //設置執行權限

                  // splash handling is done here, because the default case needs to know

                  // the location of the boot plugin we are going to use

                  handleSplash(bootPath);

                  beforeFwkInvocation();

                  invokeFramework(passThruArgs, bootPath);    //啟動Eclipse內核

              }

          posted @ 2007-12-22 16:33 Asktalk 閱讀(4904) | 評論 (3)編輯 收藏

          先列出這些開源項目,隨后對其實現過程深入分析。

          1,Hibernate Synchronizer Eclipse Plugin   最近更新在2006.04.26
                http://hibernatesynch.sourceforge.net/   
                源代碼::pserver:anonymous@hibernatesynch.cvs.sourceforge.net:/cvsroot/hibernatesynch   
                HibernateSynchronizer3   為新項目,支持Eclipse3
                HibernateSynchronizer     為舊項目,支持Eclipse2 

                本插件使用方法:http://dev2dev.bea.com.cn/bbsdoc/20060124187.html
               可以生成hibernate的所有配置文件和dao。基本流程是 hibernate.cfg.xml->xxx.hbm.xml->po and dao

          2,  SqlExplorer    最近更新 2007.09.08
               http://www.sqlexplorer.org/index.php
               http://sourceforge.net/projects/eclipsesql
               源代碼::pserver:anonymous@eclipsesql.cvs.sourceforge.net:/cvsroot/eclipsesql
               與myEclipse的數據庫管理工具相近。

          3,GmailClipse 一個Eclipse RCP 
               http://sourceforge.net/projects/gmclipse/
               源代碼::pserver:anonymous@gmclipse.cvs.sourceforge.net:/cvsroot/gmclipse    源代碼為空,沒有共享
               像hotmail一樣的郵件客戶端收發系統。其源代碼對于學習RCP有很大的幫助。

          4,  SpringIde    spring官方的IDE工具。
                源代碼:http://springide.org/project/browser/trunk

          5, Hibernate tools   hibernate官方IDE工具。
                 官方介紹:http://www.hibernate.org/268.html 
                 源代碼svn: http://anonhibernate.labs.jboss.com/branches/Branch_3_2/HibernateExt 

          6,   Html解析工具 HTML Parser
                官方網址:http://htmlparser.sourceforge.net/
               

               
               

          posted @ 2007-12-22 00:43 Asktalk 閱讀(1172) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 彰化市| 高邮市| 佛冈县| 西昌市| 太和县| 肥城市| 九寨沟县| 图木舒克市| 陇南市| 鄂伦春自治旗| 陆川县| 固始县| 肥西县| 农安县| 临潭县| 平原县| 巴里| 探索| 荣昌县| 太原市| 仪陇县| 河西区| 景洪市| 齐齐哈尔市| 侯马市| 汝南县| 朔州市| 大丰市| 京山县| 吉木乃县| 勃利县| 莱州市| 宜城市| 平乐县| 莎车县| 萨嘎县| 广南县| 乐山市| 灌阳县| 富锦市| 威宁|