📄 eventmanager.java
字号:
/*
* EventManager.java
*
* Created on 2001/11/30, 15:55
*/
package jp.co.intra_mart.framework.base.event;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import jp.co.intra_mart.framework.base.util.UserInfo;
import jp.co.intra_mart.framework.system.log.LogManager;
import jp.co.intra_mart.framework.system.log.LogConstant;
import jp.co.intra_mart.framework.system.property.PropertyManager;
import java.util.MissingResourceException;
import jp.co.intra_mart.framework.system.property.PropertyHandlerException;
import jp.co.intra_mart.framework.system.property.PropertyManagerException;
import jp.co.intra_mart.framework.system.exception.ApplicationException;
import jp.co.intra_mart.framework.system.exception.SystemException;
/**
* 僀儀儞僩儅僱乕僕儍偱偡丅
*
* @author INTRAMART
* @version 1.0
*/
public class EventManager {
/**
* 僀儀儞僩僼儗乕儉儚乕僋偺儘僌偺僾儗僼傿僢僋僗
*/
static String LOG_HEAD = "[J2EE][Event]";
/**
* 僀儀儞僩僾儘僷僥傿僴儞僪儔偺僉乕
*/
public static final String EVENT_PROPERTY_HANDLER_KEY = "event";
/**
* 僨乕僞儅僱乕僕儍庢摼僼儔僌
*/
private static Boolean managerFlag = new Boolean(false);
/**
* 僀儀儞僩儅僱乕僕儍
*/
private static EventManager manager;
/**
* 僀儀儞僩僾儘僷僥傿僴儞僪儔
*/
private EventPropertyHandler eventPropertyHandler;
/**
* 僀儀儞僩儕僗僫僼傽僋僩儕偺廤崌
*/
private Map factories;
/**
* 僀儀儞僩儅僱乕僕儍傪庢摼偟傑偡丅
*
* @return 僀儀儞僩儅僱乕僕儍
* @throws EventManagerException 僀儀儞僩儅僱乕僕儍偺惗惉帪偵椺奜偑敪惗
*/
public static EventManager getEventManager() throws EventManagerException {
if (!managerFlag.booleanValue()) {
synchronized (managerFlag) {
if (!managerFlag.booleanValue()) {
try {
manager = new EventManager();
} catch (EventManagerException e) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FailedToCreateManager");
} catch (MissingResourceException ex) {
}
LogManager.getLogManager().getLogAgent().sendMessage(
EventManager.class.getName(),
LogConstant.LEVEL_ERROR,
LOG_HEAD + message,
e);
throw e;
}
managerFlag = new Boolean(true);
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.SuccessedToCreateManager");
} catch (MissingResourceException e) {
}
LogManager.getLogManager().getLogAgent().sendMessage(
EventManager.class.getName(),
LogConstant.LEVEL_INFO,
LOG_HEAD + message);
}
}
}
return manager;
}
/**
* EventManager傪惗惉偡傞僐儞僗僩儔僋僞偱偡丅
* 偙偺僐儞僗僩儔僋僞偼柧帵揑偵屇傃弌偡偙偲偼偱偒傑偣傫丅
*
* @throws EventManagerException 僒乕價僗儅僱乕僕儍偺惗惉偵幐攕偟偨
*/
private EventManager() throws EventManagerException {
PropertyManager propertyManager;
// 僾儘僷僥傿儅僱乕僕儍偺庢摼
try {
propertyManager = PropertyManager.getPropertyManager();
} catch (PropertyManagerException e) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FailedToGetPropertyManager");
} catch (MissingResourceException ex) {
}
throw new EventManagerException(message, e);
}
// 僀儀儞僩僾儘僷僥傿僴儞僪儔偺庢摼
try {
this.eventPropertyHandler =
(EventPropertyHandler)propertyManager.getPropertyHandler(
EVENT_PROPERTY_HANDLER_KEY);
} catch (PropertyHandlerException e) {
String message = null;
try {
message =
ResourceBundle
.getBundle("jp.co.intra_mart.framework.base.event.i18n")
.getString("EventManager.FailedToGetEventPropertyHandler");
} catch (MissingResourceException ex) {
}
throw new EventManagerException(
message + " : " + EVENT_PROPERTY_HANDLER_KEY,
e);
}
// 僀儀儞僩儕僗僫僼傽僋僩儕偺廤崌偺弶婜壔
this.factories = new HashMap();
}
/**
* 僀儀儞僩僾儘僷僥傿僴儞僪儔傪庢摼偟傑偡丅
*
* @return 僀儀儞僩僾儘僷僥傿僴儞僪儔
*/
public EventPropertyHandler getEventPropertyHandler() {
return this.eventPropertyHandler;
}
/**
* 僷儔儊乕僞偱巜掕偝傟偨撪梕偵奩摉偡傞僀儀儞僩傪惗惉偟傑偡丅
* 奩摉偡傞僀儀儞僩偑{@link EventPropertyHandler}偺僷儔儊乕僞偱愝掕偝傟偰偄側偄応崌丄{@link EmptyEvent}傪曉偟傑偡丅
*
* @param application 傾僾儕働乕僔儑儞柤
* @param key 僉乕
* @param info 儘僌僀儞儐乕僓忣曬
* @return 僷儔儊乕僞偵奩摉偡傞僀儀儞僩
* @throws EventException 僀儀儞僩惗惉偵幐攕
* @throws EventPropertyException 僀儀儞僩僾儘僷僥傿偺庢摼偵幐攕
* @since 5.0
*/
public Event createEvent(
String application,
String key,
UserInfo info)
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.setUserInfo(info);
return event;
}
/**
* 僷儔儊乕僞偱巜掕偝傟偨撪梕偵奩摉偡傞僀儀儞僩傪惗惉偟傑偡丅
* 奩摉偡傞僀儀儞僩偑{@link EventPropertyHandler}偺僷儔儊乕僞偱愝掕偝傟偰偄側偄応崌丄{@link EmptyEvent}傪曉偟傑偡丅
*
* @param application 傾僾儕働乕僔儑儞柤
* @param key 僉乕
* @param loginUser 儘僌僀儞儐乕僓
* @param loginGroup 儘僌僀儞僌儖乕僾
* @return 僷儔儊乕僞偵奩摉偡傞僀儀儞僩
* @throws EventException 僀儀儞僩惗惉偵幐攕
* @throws EventPropertyException 僀儀儞僩僾儘僷僥傿偺庢摼偵幐攕
* @deprecated 偙偺儊僜僢僪偱偼側偔{@link #createEvent(String, String, UserInfo)}傪巊梡偟偰偔偩偝偄丅
*/
public Event createEvent(
String application,
String key,
String loginUser,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -