精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程

如何使用XML实现多渠道接入网站的构架

来源:天极网 时间:07-12-10 点击: 点击这里收藏本文
 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的模式设计的,实现异步交易也是可以扩展的,这里不做详细分析.

9 7 3 1 2 3 4 8 :

用户评论

广而告之