使用XML实现多渠道接入网站的构架
互联网 发布时间:2008-10-17 20:15:59 作者:佚名
我要评论
其实写这篇文章的目的最多的想法是把自己在去年在瑞士做项目时应用的一个框架给展现出来让大家共享,但我又有点担心我的表达能力不能将我在里面使用的思想很好的表现出来,所以迟迟 不敢下笔,最后还是下了决心,写吧, 不行就在好好改改,当然也希望大家多提些意见。
其余XML则可按这样的规则来定制
五.技术实现
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可以实现同步和异步的功能.
*/
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));
/*系统回收*/
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的接收函数,
* routeaccept为被动交易对象的主要处理函数
* @param env
* @throws RouterException
*/
public abstract void routeaccept(Env env) throws RouterException;
/**
* routing方法,是Service对外的接口函数
* @throws RouterException
*/
public abstract void routing() throws RouterException;
接下来则需要实现所有的Services的类了,这里就不做介绍了.
六.说明
这个Router到目前为止只能实现同步的交易, 暂时不支持异步的交易,但是由于对Router使用了Composite的模式设计的,实现异步交易也是可以扩展的,这里不做详细分析.
这篇文章是我工作的一个总结,希望能对大家有所帮助.不足之处希望多多指教.
相关文章
MIME类型中application/xml与text/xml的区别介绍
这篇文章介绍了MIME类型中application/xml与text/xml的区别,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧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


最新评论