使用XML實現(xiàn)多渠道接入網(wǎng)站的構架
互聯(lián)網(wǎng) 發(fā)布時間:2008-10-17 20:15:59 作者:佚名
我要評論
其實寫這篇文章的目的最多的想法是把自己在去年在瑞士做項目時應用的一個框架給展現(xiàn)出來讓大家共享,但我又有點擔心我的表達能力不能將我在里面使用的思想很好的表現(xiàn)出來,所以遲遲 不敢下筆,最后還是下了決心,寫吧, 不行就在好好改改,當然也希望大家多提些意見。
其余XML則可按這樣的規(guī)則來定制
五.技術實現(xiàn)
RouterFactory
package com.web.router;
import com.web.platform.Exception.RouterException;
import java.util.java/util/Hashtable.java.html" target="_blank">Hashtable;
/**
* Router產生和清除的類
*/
public class RouterFactory
{
/**
* Router存儲的樹front
*/
private static java/util/Hashtable.java.html" target="_blank">Hashtable QueuePairFront = null;
/**
* Router存儲的樹back
*/
private static java/util/Hashtable.java.html" target="_blank">Hashtable QueuePairBack = null;
/**
* Router存儲的樹
*/
private static java/util/Hashtable.java.html" target="_blank">Hashtable QueueRouter = null;
/**
* 返回的XMLRouter
*/
public static XMLRouter instance = null;
/**
* Router的定義
*/
public static RouterDefine routerdefine = null;
/**
* Router的ID號
*/
public static long routeIndex = 0;
/**
* @roseuid 3F169C21027C
*/
public RouterFactory()
{
}
/**
* 初始化Hashtable和Vector
*/
public static void initFactory() throws java/lang/Exception.java.html" target="_blank">Exception
{
QueuePairFront = new java/util/Hashtable.java.html" target="_blank">Hashtable();
QueuePairBack = new java/util/Hashtable.java.html" target="_blank">Hashtable();
QueueRouter = new java/util/Hashtable.java.html" target="_blank">Hashtable();
initRouteDefine();
}
/**
* 初始化Route的設置
*
*/
private static void initRouteDefine() throws java/lang/Exception.java.html" target="_blank">Exception
{
if( routerdefine == null )
routerdefine = new RouterDefine();
routerdefine.loadRouterDef();
}
/**
* 返回實例
* @return com.web.router.XMLRouter
*/
public static XMLRouter getInstance(long index) throws RouterException
{
return (XMLRouter)QueueRouter.get(new java/lang/Long.java.html" target="_blank">Long(index));
}
/**
* 產生一個XMLRouter的實例
* @return com.web.router.XMLRouter
* @roseuid 3F1618A103BC
*/
public static XMLRouter popInstance() throws RouterException
{
routeIndex ;
instance = new XMLRouter(routeIndex);
setDefine( instance );
QueueRouter.put(new java/lang/Long.java.html" target="_blank">Long(routeIndex), instance);
return instance;
}
/**
* 清空Hashtable,Vector等
* @roseuid 3F1618B203C1
*/
private static void freeResource() throws java/lang/Exception.java.html" target="_blank">Exception
{
QueuePairFront.clear();
QueuePairBack.clear();
QueueRouter.clear();
QueuePairFront = QueuePairBack = QueueRouter = null;
}
/**
* 清除實例
* @param instanceID
* @throws Exception
*/
public static void removeInstance(XMLRouter instance) throws java/lang/Exception.java.html" target="_blank">Exception
{
instance.clear();
QueueRouter.remove( new java/lang/Long.java.html" target="_blank">Long(instance.getIndex() ) ) ;
}
/**
* Method isNull.
* @return boolean
*/
public static boolean isNull()
{
……
return false;
}
}
XMLRouter
package com.web.router;
import com.web.platform.Exception.RouterException;
import com.web.common.*;
import java.util.*;
import java.lang.reflect.java/lang/reflect/Method.java.html" target="_blank">Method;
import java.lang.reflect.java/lang/reflect/Constructor.java.html" target="_blank">Constructor;
/**
* @author keli
* @version 0.0.1
* 平臺的關鍵,路由的類,每個Router將從RouterFactory里讀取
* Router存儲的樹front,和back,routeIndex,目的是為了能在路由
* 之后可以清除申請的對象。
* Router可以實現(xiàn)同步和異步的功能.
*/
public class XMLRouter
{
/**
* Router存儲的樹front
*/
private static java/util/Hashtable.java.html" target="_blank">Hashtable QueuePairFront = null;
/**
* Router存儲的樹back
*/
private static java/util/Hashtable.java.html" target="_blank">Hashtable QueuePairBack = null;
/**
* 本router的index號碼
*/
private long routeIndex = 0;
/**
* router的設置
*/
private RouterDefine define = null;
/**
* 用于判斷是路由的起回點
*/
private java/lang/String.java.html" target="_blank">String action = "";
/**
*此變量只是用于在routeto方法中申請新的class
*/
private java/lang/String.java.html" target="_blank">String classname = "";
/**
*/
public XMLRouter(long index)
{
routeIndex = index;
}
/**
* 路由
* @throws Exception
* @roseuid 3F1616BD0186
*/
public void routing(Env env) throws RouterException, java/lang/Exception.java.html" target="_blank">Exception
{
/*如果為起點*/
if( action.equalsIgnoreCase( RouterConstant.CFG_FUNC_ROUTETO ) )
{
……
}
/*如果為返回點*/
else if( action.equalsIgnoreCase( RouterConstant.CFG_FUNC_ROUTEBACK ) )
{
……
}
/*否則為錯誤*/
else
throw new RouterException("Set Router action error.");
}
/**
* 讀取本Router的id號.
* @return long
*/
public long getIndex()
{
return routeIndex;
}
/**
* 清除所有對象.
* @throws RouterException
*/
public void clear() throws RouterException
{
QueuePairFront.remove(new java/lang/Long.java.html" target="_blank">Long(routeIndex));
QueuePairBack.remove(new java/lang/Long.java.html" target="_blank">Long(routeIndex));
/*系統(tǒng)回收*/
java/lang/System.java.html" target="_blank">System.runFinalization();
}
/**
* 設置本Router的設置.
* @param def
* @throws RouterException
*/
public void setDefine(RouterDefine def) throws RouterException
{
define = def;
}
/**
* 設置action的值
* @param actionName
* @throws RouterException
*/
public void setAction( java/lang/String.java.html" target="_blank">String actionName )
{
action = actionName;
}
}
Service類
package com.web.common;
import com.web.platform.Exception.RouterException;
/**
* Service的父類,abstract
*/
public abstract class RouteService
{
/**
*/
public RouteService()
{
}
/**
* routeTo方法,是交易的起點。
* @param env
* @throws RouterException
*/
public abstract void routeto(Env env) throws RouterException;
/**
* routeBack,交易的結束點,
* @param env
* @throws RouterException
*/
public abstract void routeback(Env env) throws RouterException;
/**
* routeaccept方法,是交易的接收點,也是routeto的接收函數(shù),
* routeaccept為被動交易對象的主要處理函數(shù)
* @param env
* @throws RouterException
*/
public abstract void routeaccept(Env env) throws RouterException;
/**
* routing方法,是Service對外的接口函數(shù)
* @throws RouterException
*/
public abstract void routing() throws RouterException;
接下來則需要實現(xiàn)所有的Services的類了,這里就不做介紹了.
六.說明
這個Router到目前為止只能實現(xiàn)同步的交易, 暫時不支持異步的交易,但是由于對Router使用了Composite的模式設計的,實現(xiàn)異步交易也是可以擴展的,這里不做詳細分析.
這篇文章是我工作的一個總結,希望能對大家有所幫助.不足之處希望多多指教.
相關文章
MIME類型中application/xml與text/xml的區(qū)別介紹
這篇文章介紹了MIME類型中application/xml與text/xml的區(qū)別,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-12-28- XML中擁有Schema特性,能夠比DTD更加強大地引入元素結構,下面我們就來詳解XML中的模式Schema的概念及作用和用法,需要的朋友可以參考下2021-11-30
- 這篇文章主要介紹了XML基本概念入門學習指南,包括其與HTML的關系以及元素和特殊標簽等,需要的朋友可以參考下2016-06-24
- XML標簽的自定義功能非常強大,比如本文將要講解的DTD(Document Type Definition)就帶給人們一種面向對象般的感覺,well,下面就來看一下XML中的DTD文件類型定義完全解析2016-06-24
- 這篇文章主要介紹了XML文件的閱讀與編輯,最常用的工具當然還是瀏覽器中的控制臺與源代碼查看,需要的朋友可以參考下2016-02-16
- 這篇文章主要介紹了XML的命名空間,包括命名空間的聲明等XML入門學習中的基礎知識,需要的朋友可以參考下2016-02-16
- 這篇文章主要介紹了XML中的樹形結構與DOM文檔對象模型,文中舉了JavaScript解析DOM對象的例子,需要的朋友可以參考下2016-02-15
- 這篇文章主要介紹了詳解XML編程中的模式定義XSD,講解了如何在XML文檔中聲明模式及定義類型等內容,需要的朋友可以參考下2016-02-15
- 這篇文章主要介紹了XML中的DTD文檔類型定義,是XML入門學習中的基礎知識,需要的朋友可以參考下2016-02-15
- 這篇文章主要介紹了XML代碼編寫的編碼與驗證問題,與HTML類似,XML文件的編碼也能在序言部分被指定,需要的朋友可以參考下2016-02-15

