Asktalk

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

          2007年12月22日

           

          這是一個目前最好的一個開源分頁標(biāo)簽的實現(xiàn)---extremeTable標(biāo)簽。今天談?wù)勊?/span>Limit的設(shè)計架構(gòu)思想。

          這個設(shè)計很通用,經(jīng)過作者的多次重構(gòu),現(xiàn)在extremeTable的架構(gòu)非常漂亮。這個標(biāo)簽現(xiàn)在缺點是有些參數(shù)對mvc控制器屏蔽了,應(yīng)提供一致的對外接口。不過整體上設(shè)計還是很精致的,面向?qū)ο髞硖幚?html元素,與spring非常的默契,非常便于開發(fā)和測試。

          類圖關(guān)系

          1, 工廠LimitFactory

          TableLimitFactoryAbstractLimitFactoryLimitFactory

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

          TableLimitFactory主要是用來實例化,通過構(gòu)造函數(shù)傳入?yún)?shù)。同時創(chuàng)建Registry來完成jsp頁面參數(shù)傳入Registry。當(dāng)然還有一個功能就是從web.xml的配置文件讀取一些全局參數(shù)。首先讀取配置文件參數(shù),然后根據(jù)參數(shù)創(chuàng)建LimitRegistry對象。

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

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

          2, Limit

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

          3, Preferences

          TablePropertiesProperties 主要是來實現(xiàn)從web.xml配置的文件中讀取配置的一些全局參數(shù)。

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

          if (input != null) {

          properties.load(input);

          }

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

          這個設(shè)計也是大多數(shù)需要配置文件的系統(tǒng)常用的方法。

          4, Registry

          LimitRegistryAbstractRegistryRegistry

          這個體系結(jié)構(gòu)和上面的工廠模式一樣,就是LimitRegistry主要是用來實例化,通過構(gòu)造函數(shù)傳入?yún)?shù)。AbstractRegistry是實際實現(xiàn)類,獲取jsp表單提交的參數(shù),并提供getter方法供Limit來使用。Registry是一個接口。

          所以這設(shè)計模式,我們可以來學(xué)習(xí),

          經(jīng)典表述:抽象類接口

          類:初始化,定義構(gòu)造函數(shù),傳入?yún)?shù)。

          抽象類:定義業(yè)務(wù)方法在此。

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

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

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

           

          下面是從struts的角度來談?wù)?/span>spring自帶的web框架的使用。
          當(dāng)然,我們在配置
          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框架根據(jù)分工,把每一種功能都定義為一種組件,所以在開發(fā)過程中需要配置的東西就非常多;Spring中分為幾個角色:

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

          業(yè)務(wù)控制器,也就是struts中的action對象;

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

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

          模型,就是struts MVC結(jié)構(gòu)中的model

          Command對象,類似于struts中的formBean

          2.1 Spring web框架與struts框架的區(qū)別

          下面列出了一些。例如,

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

          action最后要導(dǎo)向到不同的頁面,在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不外乎繼承一些現(xiàn)成的類,來實現(xiàn)我們view部分的業(yè)務(wù)。
          作者:http://www.aygfsteel.com/asktalk

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

           

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

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

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

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

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

          二、Eclipse啟動過程

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

          1exe部分的引導(dǎo)

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

          2java代碼部分的執(zhí)行入口

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

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

          我們從main函數(shù)往后跟蹤,找到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();     //設(shè)置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); //設(shè)置執(zhí)行權(quán)限

                  // 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內(nèi)核

              }

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

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

          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的數(shù)據(jù)庫管理工具相近。

          3,GmailClipse 一個Eclipse RCP 
               http://sourceforge.net/projects/gmclipse/
               源代碼::pserver:anonymous@gmclipse.cvs.sourceforge.net:/cvsroot/gmclipse    源代碼為空,沒有共享
               像hotmail一樣的郵件客戶端收發(fā)系統(tǒng)。其源代碼對于學(xué)習(xí)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
                官方網(wǎng)址:http://htmlparser.sourceforge.net/
               

               
               

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

          主站蜘蛛池模板: 涪陵区| 敦煌市| 通化县| 平阴县| 乐山市| 南投市| 泗洪县| 萨迦县| 禹城市| 斗六市| 长丰县| 临颍县| 景东| 宽城| 金湖县| 织金县| 金川县| 渝北区| 盘锦市| 华容县| 沈丘县| 夹江县| 莆田市| 玉环县| 肃北| 远安县| 濉溪县| 师宗县| 佳木斯市| 和硕县| 六枝特区| 永吉县| 大新县| 苗栗市| 章丘市| 南乐县| 古蔺县| 措勤县| 海兴县| 麻城市| 万宁市|