一、前言
通过JAVA实现AJAX技术,主要包含AJAX主线程逻辑控制处理类(AJAXDispatcherServlet/AJAXDelegate)、AJAX请求响应模型(AJAXRequest/AJAXResponse)、AJAX的请求资源关联文档映射(URLMapping/URLMappings/URLMappingsXmlDAO)三部分,详情参见代码示例说明。
二、代码示例
1. AJAX请求响应模型(AJAXRequest/AJAXResponse)
package ajax;@b@@b@import java.security.Principal;@b@import java.sql.Date;@b@import java.sql.Time;@b@import java.sql.Timestamp;@b@import java.util.ArrayList;@b@import java.util.Enumeration;@b@import java.util.HashMap;@b@import java.util.List;@b@import java.util.Map;@b@import java.util.Set;@b@@b@import javax.servlet.http.Cookie;@b@import javax.servlet.http.HttpServletRequest;@b@import javax.servlet.http.HttpServletResponse;@b@import javax.servlet.http.HttpSession;@b@@b@public class AJAXRequest {@b@ private Map map;@b@ private HttpServletRequest request;@b@ private HttpServletResponse response;@b@@b@ public AJAXRequest(HttpServletRequest request, HttpServletResponse response) {@b@ Map paramMap = new HashMap();@b@ Enumeration paramNames = request.getParameterNames();@b@ while (paramNames.hasMoreElements()) {@b@ String paramName = (String) paramNames.nextElement();@b@ if ((request.getParameterValues(paramName) != null)@b@ && (request.getParameterValues(paramName).length > 1)) {@b@ String[] ps = request.getParameterValues(paramName);@b@ paramMap.put(paramName, ps);@b@ } else {@b@ paramMap.put(paramName, request.getParameter(paramName));@b@ }@b@ }@b@@b@ this.map = paramMap;@b@ this.request = request;@b@ this.response = response;@b@ }@b@@b@ public String getParameter(String parameterName) {@b@ Object o = this.map.get(parameterName);@b@ if (o == null)@b@ return null;@b@@b@ return o.toString();@b@ }@b@@b@ public float getParameterAsFlt(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return 0.0F;@b@ if (r.trim().equals(""))@b@ return 0.0F;@b@@b@ return Float.parseFloat(r.trim());@b@ }@b@@b@ public Float getParameterAsFloat(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@@b@ return Float.valueOf(r.trim());@b@ }@b@@b@ public Integer getParameterAsInteger(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@@b@ return Integer.valueOf(r.trim());@b@ }@b@@b@ public int getParameterAsInt(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return 0;@b@ if (r.trim().equals(""))@b@ return 0;@b@@b@ return Integer.parseInt(r.trim());@b@ }@b@@b@ public Boolean getParameterAsBoolean(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@@b@ return Boolean.valueOf(r);@b@ }@b@@b@ public String getRemoteUser() {@b@ return this.request.getRemoteHost();@b@ }@b@@b@ public String getAuthType() {@b@ return this.request.getAuthType();@b@ }@b@@b@ public Double getParameterAsDouble(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@@b@ return Double.valueOf(r.trim());@b@ }@b@@b@ public double getParameterAsDbl(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return 0.0D;@b@ if (r.trim().equals(""))@b@ return 0.0D;@b@@b@ return Double.parseDouble(r.trim());@b@ }@b@@b@ public Long getParameterAsLong(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@@b@ return Long.valueOf(r.trim());@b@ }@b@@b@ public long getParameterAsLng(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return 0L;@b@ if (r.trim().equals(""))@b@ return 0L;@b@@b@ return Long.parseLong(r.trim());@b@ }@b@@b@ public Timestamp getParameterAsTimestamp(String name) {@b@ long time;@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@ try {@b@ return Timestamp.valueOf(r.trim());@b@ } catch (IllegalArgumentException iae) {@b@ time = getParameterAsLng(name);@b@ }@b@ return new Timestamp(time);@b@ }@b@@b@ public Time getParameterAsTime(String name) {@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@@b@ return Time.valueOf(r.trim());@b@ }@b@@b@ public Date getParameterAsDate(String name) {@b@ long l;@b@ String r = getParameter(name);@b@ if (r == null)@b@ return null;@b@ if (r.trim().equals(""))@b@ return null;@b@ try {@b@ return Date.valueOf(r.trim());@b@ } catch (IllegalArgumentException e) {@b@ l = getParameterAsLng(name);@b@ }@b@ return new Date(l);@b@ }@b@@b@ public Set getParameterNames() {@b@ return this.map.keySet();@b@ }@b@@b@ public Map getParameterMap() {@b@ return this.map;@b@ }@b@@b@ public List getParameterAsList(String name) {@b@ String[] ss;@b@ int i;@b@ List rt = new ArrayList();@b@ if ((this.map.get(name) != null)@b@ && (this.map.get(name) instanceof String[])) {@b@ ss = (String[]) (String[]) this.map.get(name);@b@ for (i = 0; i < ss.length; ++i)@b@ rt.add(ss[i]);@b@ } else {@b@ rt.add(this.map.get(name));@b@ }@b@ return rt;@b@ }@b@@b@ public String[] getParameterAsArray(String name) {@b@ if ((this.map.get(name) != null)@b@ && (this.map.get(name) instanceof String[]))@b@ return ((String[]) (String[]) this.map.get(name));@b@@b@ String[] oa = new String[1];@b@ oa[0] = ((String) this.map.get(name));@b@ return oa;@b@ }@b@@b@ public Principal getUserPrincipal() {@b@ return this.request.getUserPrincipal();@b@ }@b@@b@ public boolean isUserInRole(String role) {@b@ return this.request.isUserInRole(role);@b@ }@b@@b@ public String getRemoteAddr() {@b@ return this.request.getRemoteAddr();@b@ }@b@@b@ public String getRemoteHost() {@b@ return this.request.getRemoteHost();@b@ }@b@@b@ public boolean isSecure() {@b@ return this.request.isSecure();@b@ }@b@@b@ public String getCharacterEncoding() {@b@ return this.request.getCharacterEncoding();@b@ }@b@@b@ public String getSessionId() {@b@ HttpSession ss = getSession();@b@ if (ss == null)@b@ return null;@b@@b@ return ss.getId();@b@ }@b@@b@ public void addCookie(Cookie cookie) {@b@ this.response.addCookie(cookie);@b@ }@b@@b@ public Cookie[] getCookies() {@b@ return this.request.getCookies();@b@ }@b@@b@ public Cookie getCookie(String cookieName) {@b@ Cookie[] cks = getCookies();@b@ if (cks == null)@b@ return null;@b@ for (int i = 0; i < cks.length; ++i) {@b@ Cookie ck = cks[i];@b@ String name = ck.getName();@b@ if (name.equals(cookieName))@b@ return ck;@b@ }@b@@b@ return null;@b@ }@b@@b@ public String getVerifyCode() {@b@ Cookie ck = getCookie("VerifyCodeDraw");@b@ if (ck != null)@b@ return ck.getValue();@b@@b@ return null;@b@ }@b@@b@ public String getHeader(String name) {@b@ return this.request.getHeader(name);@b@ }@b@@b@ public HttpSession getSession() {@b@ return this.request.getSession();@b@ }@b@@b@ public HttpSession getSession(boolean create) {@b@ return this.request.getSession(create);@b@ }@b@@b@ public Object getDataFromSession(String valueName) {@b@ HttpSession session = this.request.getSession(false);@b@ if (session == null)@b@ return null;@b@@b@ return session.getAttribute(valueName);@b@ }@b@@b@ protected void finalize() throws Throwable {@b@ if (!(this.map.isEmpty()))@b@ this.map.clear();@b@ super.finalize();@b@ }@b@}
package ajax;@b@@b@import java.util.HashMap;@b@@b@public class AJAXResponse extends HashMap {@b@ private int returnFlag;@b@ private String returnMsg;@b@@b@ public AJAXResponse() {@b@ this.returnFlag = 0;@b@ this.returnMsg = "ok";@b@ }@b@@b@ public int getReturnFlag() {@b@ return this.returnFlag;@b@ }@b@@b@ public String getReturnMsg() {@b@ return this.returnMsg;@b@ }@b@@b@ public void setReturnFlag(int returnFlag) {@b@ this.returnFlag = returnFlag;@b@ }@b@@b@ public void setReturnMsg(String returnMsg) {@b@ this.returnMsg = returnMsg;@b@ }@b@}
2. AJAX的请求资源关联文档映射(URLMapping/URLMappings/URLMappingsXmlDAO)
package ajax;@b@@b@import java.io.Serializable;@b@@b@public class URLMapping implements Serializable {@b@ private String url;@b@ private String delegateActionClass = null;@b@ private String delegateMethod = null;@b@@b@ public URLMapping(String url) {@b@ this.url = url;@b@ }@b@@b@ public URLMapping(String url, String delegateActionClass,@b@ String delegateMethod) {@b@ this.url = url;@b@ this.delegateActionClass = delegateActionClass;@b@ this.delegateMethod = delegateMethod;@b@ }@b@@b@ public String getDelegateAction() {@b@ return this.delegateActionClass;@b@ }@b@@b@ public String getDelegateMethod() {@b@ return this.delegateMethod;@b@ }@b@@b@ public String toString() {@b@ return "[URLMapping: url=" + this.url + ", delegateActionClass="@b@ + this.delegateActionClass + ", delegateMethod="@b@ + this.delegateMethod + "]";@b@ }@b@}
package ajax;@b@@b@import java.util.HashMap;@b@@b@class URLMappings {@b@ private HashMap urlMappingMap;@b@@b@ URLMappings() {@b@ this.urlMappingMap = new HashMap();@b@ }@b@@b@ public void addURLMapping(String urlMappingName, URLMapping urlmapping) {@b@ if (this.urlMappingMap.containsKey(urlMappingName))@b@ this.urlMappingMap.remove(urlMappingName);@b@@b@ this.urlMappingMap.put(urlMappingName, urlmapping);@b@ }@b@@b@ public URLMapping getURLMapping(String urlMappingName) {@b@ if (this.urlMappingMap.containsKey(urlMappingName))@b@ return ((URLMapping) this.urlMappingMap.get(urlMappingName));@b@@b@ return null;@b@ }@b@@b@ public boolean containsURLMapping(String urlMappingName) {@b@ return this.urlMappingMap.containsKey(urlMappingName);@b@ }@b@@b@ public void reset() {@b@ this.urlMappingMap.clear();@b@ }@b@@b@ public String toString() {@b@ return "[Screens: urlMappingMap=" + this.urlMappingMap + "]";@b@ }@b@}
package ajax;@b@@b@import java.io.IOException;@b@import java.net.MalformedURLException;@b@import java.net.URL;@b@import javax.xml.parsers.DocumentBuilder;@b@import javax.xml.parsers.DocumentBuilderFactory;@b@import org.w3c.dom.Document;@b@import org.w3c.dom.Element;@b@import org.w3c.dom.Node;@b@import org.w3c.dom.NodeList;@b@import org.xml.sax.InputSource;@b@import org.xml.sax.SAXException;@b@import org.xml.sax.SAXParseException;@b@@b@class URLMappingsXmlDAO {@b@ public static final String URL_MAPPING = "url-mapping";@b@ public static final String URL = "url";@b@ public static final String DELEGATE_ACTION_CLASS = "delegate-action-class";@b@ public static final String DELEGATE_METHOD = "delegate-method";@b@ static final boolean VERBOSE = true;@b@@b@ private static Element loadDocument(String location) throws Exception {@b@ Document doc = null;@b@ try {@b@ URL url = new URL(location);@b@ InputSource xmlInp = new InputSource(url.openStream());@b@@b@ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory@b@ .newInstance();@b@ DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();@b@ doc = parser.parse(xmlInp);@b@ Element root = doc.getDocumentElement();@b@ root.normalize();@b@ return root;@b@ } catch (SAXParseException err) {@b@ String message = "URLMappingsXmlDAO ** Parsing error, line "@b@ + err.getLineNumber() + ", uri " + err.getSystemId() + "\n"@b@ + "URLMappingsXmlDAO error: " + err.getMessage();@b@@b@ throw new Exception(message);@b@ } catch (SAXException e) {@b@ throw new Exception("URLMappingsXmlDAO error: " + e);@b@ } catch (MalformedURLException mfx) {@b@ throw new Exception("URLMappingsXmlDAO error: " + mfx);@b@ } catch (IOException e) {@b@ throw new Exception("URLMappingsXmlDAO error: " + e);@b@ } catch (Exception pce) {@b@ throw new Exception("URLMappingsXmlDAO error: " + pce);@b@ }@b@ }@b@@b@ public static URLMappings loadRequestMappings(String location)@b@ throws Exception {@b@ Element root = loadDocument(location);@b@ return getURLMappings(root);@b@ }@b@@b@ private static URLMappings getURLMappings(Element root) throws Exception {@b@ URLMappings urlMappings = new URLMappings();@b@ NodeList list = root.getElementsByTagName("url-mapping");@b@ for (int loop = 0; loop < list.getLength(); ++loop) {@b@ Node node = list.item(loop);@b@ if (node != null) {@b@ String url = "";@b@ String next = null;@b@ String delegateActionString = null;@b@ String delegateMethodString = null;@b@@b@ if (node instanceof Element) {@b@ Element element = (Element) node;@b@ url = element.getAttribute("url");@b@ delegateActionString = element@b@ .getAttribute("delegate-action-class");@b@ delegateMethodString = element@b@ .getAttribute("delegate-method");@b@ }@b@ URLMapping mapping = new URLMapping(url, delegateActionString,@b@ delegateMethodString);@b@@b@ if (!(urlMappings.containsURLMapping(url)))@b@ urlMappings.addURLMapping(url, mapping);@b@ else@b@ throw new Exception(@b@ "*** Non Fatal errror: Screen "@b@ + url@b@ + " defined more than once in screen definitions file");@b@ }@b@@b@ }@b@@b@ return urlMappings;@b@ }@b@}
<
3. AJAX主线程逻辑控制处理类(AJAXDispatcherServlet/AJAXDelegate)
package ajax;@b@@b@import java.io.IOException;@b@import java.io.PrintStream;@b@import java.net.MalformedURLException;@b@import java.net.URL;@b@import java.util.Date;@b@import javax.servlet.ServletConfig;@b@import javax.servlet.ServletContext;@b@import javax.servlet.ServletException;@b@import javax.servlet.http.HttpServlet;@b@import javax.servlet.http.HttpServletRequest;@b@import javax.servlet.http.HttpServletResponse;@b@@b@public class AJAXDispatcherServlet extends HttpServlet {@b@@b@ private static final boolean debug = true;@b@ protected ServletContext context;@b@ protected String encoding;@b@ protected String requestMappingUrl;@b@ protected AJAXDelegate urlmappingprocessor;@b@@b@ public AJAXDispatcherServlet() {@b@ this.encoding = "GBK";@b@ this.requestMappingUrl = "ajax-mappings.xml";@b@ }@b@@b@ protected AJAXDelegate getRequestProcessor() {@b@ return this.urlmappingprocessor;@b@ }@b@@b@ public void doGet(HttpServletRequest request, HttpServletResponse response)@b@ throws ServletException, IOException {@b@ doService(request, response);@b@ }@b@@b@ public void doPost(HttpServletRequest request, HttpServletResponse response)@b@ throws ServletException, IOException {@b@ doService(request, response);@b@ }@b@@b@ public void doService(HttpServletRequest request,@b@ HttpServletResponse response) throws ServletException, IOException {@b@ String fullURL = request.getRequestURI();@b@@b@ String selectedURL = null;@b@ int lastPathSeparator = fullURL.lastIndexOf("/") + 1;@b@ if (lastPathSeparator != -1) {@b@ selectedURL = fullURL@b@ .substring(lastPathSeparator, fullURL.length());@b@ }@b@@b@ int lastDot = selectedURL.lastIndexOf(".") + 1;@b@@b@ if ((lastDot != -1)@b@ && (selectedURL.substring(lastDot, selectedURL.length())@b@ .equals("ajax"))) {@b@ getRequestProcessor().processRequest(request, response);@b@ }@b@ }@b@@b@ public void init(ServletConfig config) throws ServletException {@b@ logAudit("开始初始化AJAXDispatcherServlet...", "init");@b@ this.context = config.getServletContext();@b@@b@ String encoding = config.getInitParameter("encoding");@b@ if (encoding != null)@b@ this.encoding = encoding;@b@@b@ String requestMappingsURL = null;@b@ String customRequestMapping = config@b@ .getInitParameter("requestmappingfile");@b@@b@ if (customRequestMapping == null)@b@ customRequestMapping = this.requestMappingUrl;@b@ try {@b@ URL url = this.context.getResource("/WEB-INF/"@b@ + customRequestMapping);@b@ requestMappingsURL = url.toString();@b@ } catch (MalformedURLException me) {@b@ throw new ServletException("Request mapping file exception: "@b@ + requestMappingsURL);@b@ }@b@@b@ if (requestMappingsURL != null) {@b@ URLMappings urlmappings;@b@ try {@b@ urlmappings = URLMappingsXmlDAO@b@ .loadRequestMappings(requestMappingsURL);@b@ } catch (Exception e) {@b@ throw new ServletException(e);@b@ }@b@ this.urlmappingprocessor = new AJAXDelegate(this.context,@b@ urlmappings);@b@ } else {@b@ throw new ServletException("Request mapping file exception: "@b@ + requestMappingsURL);@b@ }@b@@b@ logAudit("初始化AJAXDispatcherServlet完成!", "init");@b@ }@b@@b@ public void destroy() {@b@ this.context = null;@b@ logAudit("destroy AJAXDispatcherServlet", "destroy");@b@ }@b@@b@ private void logAudit(String message, String method) {@b@ System.out.println("<" + new Date() + "> <Audit> In "@b@ + "AJAXDispatcherServlet." + method + ":" + message);@b@ }@b@}
package ajax;@b@@b@import java.io.IOException;@b@import java.io.PrintStream;@b@import java.io.PrintWriter;@b@import java.io.Serializable;@b@import java.lang.reflect.Method;@b@import java.util.Date;@b@import java.util.Hashtable;@b@import java.util.Iterator;@b@import java.util.Set;@b@import javax.servlet.ServletContext;@b@import javax.servlet.http.HttpServletRequest;@b@import javax.servlet.http.HttpServletResponse;@b@import org.jdom.output.XMLOutputter;@b@@b@public class AJAXDelegate implements Serializable {@b@ @b@ private URLMappings urlMappings;@b@ private Hashtable delegateCache;@b@ private ServletContext servletContext;@b@ private static final boolean VERBOSE = true;@b@ private static final boolean debug = false;@b@@b@ public void init(ServletContext context) {@b@ this.servletContext = context;@b@ }@b@@b@ public ServletContext getContext() {@b@ return this.servletContext;@b@ }@b@@b@ public AJAXDelegate() {@b@ }@b@@b@ AJAXDelegate(ServletContext context, URLMappings urlmappings) {@b@ this.servletContext = context;@b@ this.urlMappings = urlmappings;@b@ this.delegateCache = new Hashtable();@b@ }@b@@b@ private URLMapping getURLMapping(String urlPattern) {@b@ if ((this.urlMappings != null)@b@ && (this.urlMappings.containsURLMapping(urlPattern)))@b@ return this.urlMappings.getURLMapping(urlPattern);@b@@b@ return null;@b@ }@b@@b@ public void processRequest(HttpServletRequest request,@b@ HttpServletResponse response) {@b@ String domain = "";@b@ try {@b@ Iterator it;@b@ logAudit("enter", "processRequest");@b@ if (request.getMethod().equals("GET"))@b@ request.setCharacterEncoding("UTF-8");@b@@b@ domain = request.getParameter("domain");@b@ AJAXResponse result = new AJAXResponse();@b@ String fullURL = request.getRequestURI();@b@@b@ String selectedURL = null;@b@ int lastPathSeparator = fullURL.lastIndexOf("/") + 1;@b@ if (lastPathSeparator != -1) {@b@ selectedURL = fullURL.substring(lastPathSeparator,@b@ fullURL.length());@b@ }@b@@b@ URLMapping urlMapping = getURLMapping(selectedURL);@b@@b@ AJAXDelegate delegate = getDelegateClass(urlMapping);@b@ if (delegate != null) {@b@ delegate.init(this.servletContext);@b@ String method = getDelegateMethod(urlMapping).trim();@b@ logAudit("method = " + method, "processRequest");@b@@b@ Class[] args = new Class[1];@b@@b@ AJAXRequest arequest = new AJAXRequest(request, response);@b@ Object[] params = { arequest };@b@@b@ args[0] = AJAXRequest.class;@b@@b@ Method m = delegate.getClass().getMethod(method, args);@b@ if (m != null)@b@ result = (AJAXResponse) m.invoke(delegate, params);@b@ } else {@b@ result.setReturnFlag(-1);@b@ result.setReturnMsg("系统内部错误:未找到对应的处理程序");@b@ }@b@ if ((domain != null) && (domain.length() > 0))@b@ response.setContentType("text/html; charset=GBK");@b@ else@b@ response.setContentType("text/xml; charset=GBK");@b@@b@ response.setDateHeader("Expires", 0L);@b@ PrintWriter out = response.getWriter();@b@ XMLOutputter outputter = new XMLOutputter();@b@ AJAXXMLDocument icssdoc = new AJAXXMLDocument();@b@@b@ if (result != null) {@b@ icssdoc.setReturnFlag(String.valueOf(result.getReturnFlag()));@b@ icssdoc.setReturnMessage(result.getReturnMsg());@b@ for (it = result.keySet().iterator(); it.hasNext();) {@b@ String key = (String) it.next();@b@ icssdoc.addObject(key, result.get(key));@b@ }@b@ } else {@b@ icssdoc.setReturnFlag("-1");@b@ icssdoc.setReturnMessage("返回结果为空");@b@ }@b@@b@ outputter.setEncoding("GBK");@b@ if ((domain != null) && (domain.length() > 0))@b@ out.write("<html><head><script>document.domain='"@b@ + request.getParameter("domain")@b@ + "';</script></head><body>");@b@@b@ outputter.output(icssdoc.getAJAXXMLDocument(), out);@b@ if ((domain != null) && (domain.length() > 0))@b@ out.write("</body></html>");@b@@b@ out.flush();@b@ out.close();@b@ } catch (Exception e) {@b@ e.printStackTrace();@b@ response.setContentType("text/html; charset=GBK");@b@ response.setDateHeader("Expires", 0L);@b@ XMLOutputter outputter = new XMLOutputter();@b@ AJAXXMLDocument icssdoc = new AJAXXMLDocument();@b@ icssdoc.setReturnFlag("-1");@b@ icssdoc.setReturnMessage("系统内部错误:" + e.getMessage());@b@ try {@b@ PrintWriter out = response.getWriter();@b@ outputter.setEncoding("GBK");@b@ if ((domain != null) && (domain.length() > 0))@b@ out.write("<html><head><script>document.domain='"@b@ + request.getParameter("domain")@b@ + "';</script></head><body>");@b@@b@ outputter.output(icssdoc.getAJAXXMLDocument(), out);@b@ if ((domain != null) && (domain.length() > 0))@b@ out.write("</body></html>");@b@@b@ out.flush();@b@ out.close();@b@ } catch (IOException e1) {@b@ e1.printStackTrace();@b@ }@b@ }@b@ }@b@@b@ private AJAXDelegate getDelegateClass(URLMapping urlMapping) {@b@ AJAXDelegate handler = null;@b@ String delegateClassString = null;@b@ if (urlMapping != null) {@b@ delegateClassString = urlMapping.getDelegateAction();@b@ handler = (AJAXDelegate) this.delegateCache@b@ .get(delegateClassString);@b@@b@ if (handler == null) {@b@ delegateClassString = urlMapping.getDelegateAction();@b@ logAudit(" delegateClassString " + delegateClassString,@b@ "getDelegateClass");@b@ try {@b@ ClassLoader classLoader = Thread.currentThread()@b@ .getContextClassLoader();@b@@b@ if (classLoader == null) {@b@ logAudit(" classLoader is null", "getDelegateClass");@b@ classLoader = AJAXDelegate.class.getClassLoader();@b@ }@b@ if (classLoader == null) {@b@ logAudit("The last classLoader is null",@b@ "getDelegateClass");@b@ }@b@@b@ handler = (AJAXDelegate) (AJAXDelegate) classLoader@b@ .loadClass(delegateClassString).newInstance();@b@@b@ this.delegateCache.put(delegateClassString, handler);@b@ } catch (Exception ex) {@b@ logError("handler is null", "getDelegateClass", ex);@b@ }@b@ }@b@ }@b@ return handler;@b@ }@b@@b@ private String getDelegateMethod(URLMapping urlMapping) {@b@ if (urlMapping != null)@b@ return urlMapping.getDelegateMethod();@b@@b@ return null;@b@ }@b@@b@ private void logAudit(String message, String method) {@b@ }@b@@b@ private void logError(String errorMessage, String method, Throwable e) {@b@ System.out.println("<" + new Date()@b@ + "> <Error> Error in AJAXDelegate." + method + ":"@b@ + errorMessage + e.toString());@b@ }@b@}