How to use XML to construct a multi-channel website access architecture

Source: Internet
Author: User
In today's websites, there are more and more access channels and more advanced technologies, such as WAP, SMS, EMAIL, traditional Web, and Socket, if the database and LDAP are connected, the space to be extended in the design should be very good, to ensure that you do not need to modify or even change the code when adding a new channel. I. Background

In today's websites, there are more and more access channels and more advanced technologies, such as WAP, SMS, EMAIL, traditional Web, and Socket, if the database and LDAP are connected, the space to be extended in the design should be very good, to ensure that you do not need to modify or even change the code when adding a new channel. But is it possible? I don't think so, but how can we better solve the perfection of this multi-channel access framework?

II. Architecture

  
 
      
      
  
       
       
      
      
  
         
       
   …… 
 


This is the configuration file of the Router. The service node represents the channel to be accessed. The service node contains the connector subnode. the configuration of the subnode is differentiated by type. if it is a database, the url, user, passwd, driver, and other attributes. if it is socket, it contains attributes such as port and maxthread. the attribute values can be configured according to your own definitions.

Another XML file is an XML transaction data file used to transmit data in all services. each service contains an XML file. for example, the format of webtrans. xml is as follows:

The following is a reference clip:

  
 
      
  
         
         
         
         
             
       
 


The corresponding dbtrans. xml format is as follows:


The following is a reference clip:

 
        
            
  
           
           
           
           
               
      
 



Other XML files can be customized according to such rules.

V. Technical implementation

RouterFactory

The following is a reference clip:

package com.web.router; import com.web.platform.Exception.RouterException; import java.util.java/util/Hashtable.java.html" target="_blank">Hashtable;




The following is a reference clip:

/*** Router-generated and cleared classes */public class RouterFactory {/*** Router-stored tree front */private static java/util/Hashtable.java.html "target =" _ blank "> Hashtable QueuePairFront = null; /*** Router stored tree back */private static java/util/Hashtable.java.html "target =" _ blank "> Hashtable QueuePairBack = null; /*** Router stored tree */private static java/util/Hashtable.java.html "target =" _ blank "> Hashtable QueueRouter = null; /*** Returned XMLRouter */public static XMLRouter instance = null;/*** Router Definition */public static RouterDefine routerdefine = null; /*** ID of the Router */public static long routeIndex = 0;/*** @ roseuid 3F169C21027C */public RouterFactory () {}/*** initialize Hashtable and Vector */public static void initFactory () throws java/lang/Exception.java.html "target =" _ blank "> Exception {QueuePairFront = new java/ut Il/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 ();} /*** initialize Route settings **/private static void initRouteDefine () throws java/lang/Exception.java.html "target =" _ blank "> Exception {if (routerdefine = null) routerdefine = New RouterDefine (); routerdefine. loadRouterDef ();}/*** return instance * @ 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);}/*** generate an XMLRouter instance * @ 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;}/*** clear Hashtable, vector, etc. * @ roseuid 3F1618B203C1 */private static void freeResource () throws java/lang/Exception.java.html "target =" _ blank "> Exception {QueuePairFront. clear (); QueuePairBack. cle Ar (); QueueRouter. clear (); QueuePairFront = QueuePairBack = QueueRouter = null;}/*** clear instance * @ 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. * @ ret Urn boolean */public static boolean isNull (){...... Return false ;}}



XMLRouter

The following is a reference clip:

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 * the key of the platform, the routing class, each Router will read * rofront storage tree front, back, r from RouterFactory OuteIndex is used to clear the applied objects after routing. * The Router can implement synchronous and asynchronous functions. */public class XMLRouter {/*** rofront storage tree front */private static java/util/Hashtable.java.html "target =" _ blank "> Hashtable QueuePairFront = null; /*** Router stored tree back */private static java/util/Hashtable.java.html "target =" _ blank "> Hashtable QueuePairBack = null; /*** index number of the current router */private long routeIndex = 0;/*** router setting */private RouterDefine define = null ;/** * Used to determine the starting point of the route */private java/lang/String.java.html "target =" _ blank "> String action = ""; /*** this variable is only used to apply for a new class in the routeto method */private java/lang/String.java.html "target =" _ blank "> String classname = ""; /***/public XMLRouter (long index) {routeIndex = index;}/*** route ** @ throws Exception * @ roseuid 3F1616BD0186 */public void routing (Env env) throws RouterException, java/lang/Exception.java.html" Target = "_ blank"> Exception {/* if it is the starting point */if (action. role signorecase (RouterConstant. assist_func_routeto )){...... }/* If it is the return vertex */else if (action. fig (RouterConstant. fig _func_routeback )){...... }/* Otherwise error */else throw new RouterException ("Set Router action error. ");}/*** READ the ID of the current Router. * @ return long */public long getIndex () {return routeIndex;}/*** clear all objects. * @ 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 )); /* recycle the System */java/lang/System.java.html "target =" _ blank "> System. runFinalization ();}/*** sets the Router settings. * @ param def * @ throws RouterException */public void setDefine (RouterDefine def) throws RouterException {define = def ;} /*** set the action value * @ param actionName * @ throws RouterException */public void setAction (java/lang/String.java.html "target =" _ blank "> String actionName) {action = actionName ;}}



Service

The following is a reference clip:

Package com. web. common; import com. web. platform. exception. routerException;/*** Service parent class, abstract */public abstract class RouteService {/***/public RouteService () {}/ *** routeTo method, is the starting point of the transaction. * @ Param env * @ throws RouterException */public abstract void routeto (Env env) throws RouterException;/*** routeBack, transaction end point, * @ param env * @ throws RouterException */public abstract void routeback (Env env) throws RouterException;/*** the routeaccept method is the receiving point of the transaction and the receiving function of routeto, * routeaccept is the main processing function of a passive transaction object * @ param env * @ throws RouterException */public abstract void routeaccept (Env env) throws RouterException;/*** routing method, is the external interface function of the Service * @ throws RouterException */public abstract void routing () throws RouterException;


Next, we need to implement all Services classes. we will not introduce them here.

VI. description

This Router can only implement synchronous transactions so far and does not support asynchronous transactions for the time being. However, due to the use of the Composite pattern design for Router, asynchronous transactions can also be extended, no detailed analysis is provided here.

The preceding figure shows how to use XML to implement the multi-channel website access architecture. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.