📄 eventmanager.java
字号:
String loginGroup)
throws EventPropertyException, EventException {
String name = null;
Object eventObject = null;
Event event = null;
// 巜掕偝傟偨傾僾儕働乕僔儑儞偲僉乕偐傜僀儀儞僩傪惗惉
name = this.eventPropertyHandler.getEventName(application, key);
if (name == null) {
event = new EmptyEvent();
} else {
try {
eventObject = Class.forName(name).newInstance();
} catch (Exception e) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FailedToCreateEvent");
} catch (MissingResourceException ex) {
}
throw new EventException(
message
+ " : event class = "
+ name
+ ", application = "
+ application
+ ", key = "
+ key,
e);
}
if (eventObject instanceof Event) {
event = (Event)eventObject;
} else {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.EventExtended");
} catch (MissingResourceException ex) {
}
throw new EventException(
message
+ " : event class = "
+ name
+ ", application = "
+ application
+ ", key = "
+ key);
}
}
// 傾僾儕働乕僔儑儞柤偲僉乕偺愝掕
event.setApplication(application);
event.setKey(key);
event.setLoginUserID(loginUser);
event.setLoginGroupID(loginGroup);
return event;
}
/**
* 僀儀儞僩偵懳偡傞張棟傪幚峴偟傑偡丅
* 僀儀儞僩傪搉偝傟傞偲丄僀儀儞僩偵娭楢偡傞{@link EventListenerFactory}偐傜
* {@link EventListener}傪惗惉偟丄{@link EventListener}偵張棟傪埶棅偟傑偡丅
* <code>event</code>偵偼昁偢{@link #createEvent(String, String, String, String)}偱庢摼偟偨僀儀儞僩傪愝掕偟偰偔偩偝偄丅
* 偙偺儊僜僢僪偼{@link #dispatch(Event, boolean) dispatch(event, false)}傪屇傃弌偟偨偲偒偲摨偠岠壥偑偁傝傑偡丅
*
* @param event 僀儀儞僩
* @return 僀儀儞僩張棟寢壥
* @throws EventException 晄惓側僀儀儞僩偑搉偝傟偨
* @throws SystemException 僀儀儞僩張棟帪偵僔僗僥儉椺奜偑敪惗
* @throws ApplicationException 僀儀儞僩張棟帪偵傾僾儕働乕僔儑儞椺奜偑敪惗
*/
public EventResult dispatch(Event event)
throws EventException, SystemException, ApplicationException {
return dispatch(event, false);
}
/**
* 僀儀儞僩偵懳偡傞張棟傪幚峴偟傑偡丅
* 僀儀儞僩傪搉偝傟傞偲丄僀儀儞僩偵娭楢偡傞{@link EventListenerFactory}偐傜
* {@link EventListener}傪惗惉偟丄{@link EventListener}偵張棟傪埶棅偟傑偡丅
* <code>event</code>偵偼昁偢{@link #createEvent(String, String, String, String)}偱庢摼偟偨僀儀儞僩傪愝掕偟偰偔偩偝偄丅
* <BR>{@link EventListener}偵張棟傪埶棅偡傞嵺丄{@link EventListener#setInTransaction(boolean)}儊僜僢僪偑屇偽傟傑偡丅
* 偙偺偲偒偵<code>nest</code>偱巜掕偝傟偨抣偑搉偝傟傑偡丅
*
* @param event 僀儀儞僩
* @param transaction 僩儔儞僓僋僔儑儞偺拞偱幚峴偝傟偰偄傞偐偳偆偐傪帵偡僼儔僌乮僩儔儞僓僋僔儑儞撪偺応崌true丄僩儔儞僓僋僔儑儞奜偺応崌false乯
* @return 僀儀儞僩張棟寢壥
* @throws EventException 晄惓側僀儀儞僩偑搉偝傟偨
* @throws SystemException 僀儀儞僩張棟帪偵僔僗僥儉椺奜偑敪惗
* @throws ApplicationException 僀儀儞僩張棟帪偵傾僾儕働乕僔儑儞椺奜偑敪惗
* @since 4.2
*/
public EventResult dispatch(Event event, boolean transaction)
throws EventException, SystemException, ApplicationException {
EventListenerFactory factory;
EventListener listener;
// 僀儀儞僩儕僗僫僼傽僋僩儕偺庢摼
factory = getEventListenerFactory(event);
// 僀儀儞僩儕僗僫偺惗惉
listener = factory.create(event);
// 僩儔儞僓僋僔儑儞偺愝掕
listener.setInTransaction(transaction);
// 張棟幚峴丒寢壥偺庢摼
return listener.execute(event);
}
/**
* 巜掕偝傟偨僀儀儞僩偵奩摉偡傞僀儀儞僩儕僗僫僼傽僋僩儕傪庢摼偟傑偡丅
* 捠忢偼偙偺儊僜僢僪傪巊梡偡傞昁梫偼偁傝傑偣傫丅{@link #createEvent(String, String, String)}偲{@link #dispatch(jp.co.intra_mart.framework.base.event.Event)}傪棙梡偟偰偔偩偝偄丅
*
* @param event 僀儀儞僩
* @return 僀儀儞僩儕僗僫僼傽僋僩儕
* @throws EventException 晄惓側僀儀儞僩偑搉偝傟偨
*/
private EventListenerFactory getEventListenerFactory(Event event)
throws EventException {
String factoryName;
EventListenerFactoryParam[] params;
EventListenerFactory factory = null;
// 僀儀儞僩偑揔惓側傕偺偐偳偆偐僠僃僢僋
String eventApp = event.getApplication();
String eventKey = event.getKey();
if (eventApp == null
|| eventApp.equals("")
|| eventKey == null
|| eventKey.equals("")) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("Common.IllegalEvent");
} catch (MissingResourceException e) {
}
throw new EventException(
message
+ " : event class = "
+ event.getClass().getName()
+ ", application = "
+ eventApp
+ ", key = "
+ eventKey);
}
String factoryKey = event.getApplication() + "." + event.getKey();
boolean dynamic = false;
try {
dynamic = getEventPropertyHandler().isDynamic();
} catch (EventPropertyException e) {
throw new EventException(e.getMessage(), e);
}
if (dynamic) {
factory = createEventListenerFactory(event);
} else {
synchronized (this.factories) {
factory = (EventListenerFactory)this.factories.get(factoryKey);
if (factory == null) {
factory = createEventListenerFactory(event);
this.factories.put(factoryKey, factory);
}
}
}
return factory;
}
private EventListenerFactory createEventListenerFactory(Event event)
throws EventException {
String factoryName = null;
Object factoryObject = null;
EventListenerFactory factory = null;
EventListenerFactoryParam[] params = null;
// 僀儀儞僩儕僗僫僼傽僋僩儕偺惗惉
try {
factoryName =
getEventPropertyHandler().getEventListenerFactoryName(
event.getApplication(),
event.getKey());
} catch (EventPropertyException e) {
throw new EventException(e.getMessage(), e);
}
try {
factoryObject = Class.forName(factoryName).newInstance();
} catch (Exception e) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FailedToCreateFactory");
} catch (MissingResourceException ex) {
}
throw new EventException(
message
+ " : factory class = "
+ factoryName
+ ", application = "
+ event.getApplication()
+ ", key = "
+ event.getKey(),
e);
}
if (factoryObject instanceof EventListenerFactory) {
factory = (EventListenerFactory)factoryObject;
} else {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FactoryImplemented");
} catch (MissingResourceException e) {
}
throw new EventException(
message
+ " : factory class = "
+ factoryName
+ ", application = "
+ event.getApplication()
+ ", key = "
+ event.getKey());
}
// 僀儀儞僩儕僗僫僼傽僋僩儕偺弶婜僷儔儊乕僞愝掕
try {
params =
getEventPropertyHandler().getEventListenerFactoryParams(
event.getApplication(),
event.getKey());
} catch (EventPropertyException e) {
throw new EventException(e.getMessage(), e);
}
if (params != null) {
for (int i = 0; i < params.length; i++) {
try {
factory.initParam(
params[i].getName(),
params[i].getValue());
} catch (EventListenerException e) {
throw new EventException(e.getMessage(), e);
}
}
}
return factory;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -