哪位老大能够解释下这段代码

04-08-12 gelu

package org.ofbiz.core.event;

import java.util.*;

import java.lang.reflect.*;

import javax.servlet.http.*;

import org.ofbiz.core.util.*;

/**

* JavaEventHandler - Static Method Java Event Handler

*

* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>

* @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>

* @version $Revision: 1.17 $

* @since 2.0

*/

public class JavaEventHandler implements EventHandler {

public static final String module = JavaEventHandler.class.getName();

private Map eventClassMap = new HashMap();

/**

* Invoke the web event

* @param eventPath The path or location of this event

* @param eventMethod The method to invoke

* @param request The servlet request object

* @param response The servlet response object

* @return String Result code

* @throws EventHandlerException

*/

public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {

Class eventClass = (Class) this.eventClassMap.get(eventPath);

if (eventClass == null) {

synchronized (this) {

eventClass = (Class) this.eventClassMap.get(eventPath);

if (eventClass == null) {

try {

ClassLoader loader = Thread.currentThread().getContextClassLoader();

eventClass = loader.loadClass(eventPath);

} catch (ClassNotFoundException e) {

Debug.logError(e, "Error loading class with name: " + eventPath + ", will not be able to run event...");

}

if (eventClass != null) {

eventClassMap.put(eventPath, eventClass);

}

}

}

}

if (Debug.verboseOn()) Debug.logVerbose("[Set path/method]: " + eventPath + " / " + eventMethod, module);

Class[] paramTypes = new Class[] {HttpServletRequest.class, HttpServletResponse.class};

Debug.logVerbose("*[[Event invocation]]*", module);

Object[] params = new Object[] {request, response};

return invoke(eventPath, eventMethod, eventClass, paramTypes, params);

}

private String invoke(String eventPath, String eventMethod, Class eventClass, Class[] paramTypes, Object[] params) throws EventHandlerException {

if (eventClass == null) {

throw new EventHandlerException("Error invoking event, the class " + eventPath + " was not found");

}

if (eventPath == null || eventMethod == null) {

throw new EventHandlerException("Invalid event method or path; call initialize()");

}

Debug.logVerbose("[Processing]: JAVA Event", module);

try {

Method m = eventClass.getMethod(eventMethod, paramTypes);

String eventReturn = (String) m.invoke(null, params);

if (Debug.verboseOn()) Debug.logVerbose("[Event Return]: " + eventReturn, module);

return eventReturn;

} catch (java.lang.reflect.InvocationTargetException e) {

Throwable t = e.getTargetException();

if (t != null) {

Debug.logError(t, "Problems Processing Event", module);

throw new EventHandlerException("Problems processing event: " + t.toString(), t);

} else {

Debug.logError(e, "Problems Processing Event", module);

throw new EventHandlerException("Problems processing event: " + e.toString(), e);

}

} catch (Exception e) {

Debug.logError(e, "Problems Processing Event", module);

throw new EventHandlerException("Problems processing event: " + e.toString(), e);

}

}

}

-------

我是新手,能不能有高手帮忙解释下,好多API我都不熟啊