哪位老大能夠解釋下這段程式碼
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我都不熟啊
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我都不熟啊
相關文章
- 解釋一下這段程式碼 npm i --no-save --legacy-peer-deps react@17NPMReact
- 遇到了java smtp 郵件問題,哪位高手能夠相助啊?Java
- 這段程式碼如何理解?
- 雖然不相干,但也問一下,哪位高人能夠指點一下偶MYSQL的索引問題??MySql索引
- jpetstore的一段程式碼,請高手解釋一下什麼意思啊
- 【有趣】這段java程式碼太古怪Java
- jive中這段程式碼什麼意思?
- javascript能夠回溯的打字機效果程式碼例項JavaScript
- 編寫讓別人能夠讀懂的程式碼
- 少壯不努力 老大寫程式碼
- 馬哥分享的25段shell指令碼程式碼,日常工作基本夠用指令碼
- 能夠提取郵政編碼的正規表示式程式碼例項
- 一、char *const *(*next)();請對這行程式碼進行一下解釋?行程
- 請教:版上哪位仁兄能介紹一下Embedded Value模式模式
- js能夠四捨五入且能夠保留指定小數位數和千分位的程式碼JS
- 拿好這段程式碼,願你求職路上不再迷茫求職
- 使用 github 做程式碼管理,知道這些就夠了Github
- 側欄能夠定位的導航選單程式碼例項
- 能夠匹配整數的正規表示式程式碼例項
- 請高手給看一下這段程式碼有何作用? (5千字)
- 委託初步瞭解(程式碼段展示)
- 理解線段樹這一篇文章就夠啦!
- 這段程式如何解讀?
- 請立刻修改這段程式
- 請修改這段程式,立刻!
- tomcat + axis,webservice釋出失敗,哪位碰到過這樣的問題!TomcatWeb
- 【趣圖】這段程式碼看起來沒用,刪了吧....
- 這 6 段程式碼,成就瞭如今的深度學習深度學習
- 大家看我這段程式碼有什麼問題麼?
- 寫這段程式碼的人該不該被開除?
- 哪位大師能用匿名遞迴下這個無限極分類?遞迴
- 能夠感知滑鼠移動方位的遮罩層效果程式碼例項遮罩
- Google新作:注意力機制是否真的能夠提供模型的可解釋性?Go模型
- 有些事,不是技術能夠解決的
- 學習SVM,這篇文章就夠了!(附詳細程式碼)
- 要炸了!剛寫完這段程式碼,就被開除了
- 這段程式碼到底怎麼走?終於搞定Event loopOOP
- js能夠自動變動的時間日期效果程式碼例項JS