import orgapachelog4jLogger;
/
@ 服务器类型探测
@Date 2011/04/13
/
public class ServerUtil {
public static final String GERONIMO_CLASS = "/org/apache/geronimo/system/main/Daemonclass";
public static final String JBOSS_CLASS = "/org/jboss/Mainclass";
public static final String JETTY_CLASS = "/org/mortbay/jetty/Serverclass";
public static final String JONAS_CLASS = "/org/objectweb/jonas/server/Serverclass";
public static final String OC4J_CLASS = "/oracle/jsp/oc4jutil/Oc4jUtilclass";
public static final String ORION_CLASS = "/com/evermind/server/ApplicationServerclass";
public static final String PRAMATI_CLASS = "/com/pramati/Serverclass";
public static final String RESIN_CLASS = "/com/caucho/server/resin/Resinclass";
public static final String REXIP_CLASS = "/com/tcc/Mainclass";
public static final String SUN7_CLASS = "/com/iplanet/ias/tools/cli/IasAdminMainclass";
public static final String SUN8_CLASS = "/com/sun/enterprise/cli/framework/CLIMainclass";
public static final String TOMCAT_CLASS = "/org/apache/catalina/startup/Bootstrapclass";
public static final String WEBLOGIC_CLASS = "/weblogic/Serverclass";
public static final String WEBSPHERE_CLASS = "/com/ibm/websphere/product/VersionInfoclass";
public static String getServerId() {
ServerUtil sd = _instance;
if (sd_serverId == null) {
if (ServerUtilisGeronimo()) {
sd_serverId = "geronimo";
} else if (ServerUtilisJBoss()) {
sd_serverId = "jboss";
} else if (ServerUtilisJOnAS()) {
sd_serverId = "jonas";
} else if (ServerUtilisOC4J()) {
sd_serverId = "oc4j";
} else if (ServerUtilisOrion()) {
sd_serverId = "orion";
} else if (ServerUtilisResin()) {
sd_serverId = "resin";
} else if (ServerUtilisWebLogic()) {
sd_serverId = "weblogic";
} else if (ServerUtilisWebSphere()) {
sd_serverId = "websphere";
}
if (ServerUtilisJetty()) {
if (sd_serverId == null) {
sd_serverId = "jetty";
} else {
sd_serverId += "-jetty";
}
} else if (ServerUtilisTomcat()) {
if (sd_serverId == null) {
sd_serverId = "tomcat";
} else {
sd_serverId += "-tomcat";
}
}
if (_logisInfoEnabled()) {
_loginfo("Detected server " + sd_serverId);
}
if (sd_serverId == null) {
throw new RuntimeException("Server is not supported");
}
}
return sd_serverId;
}
public static boolean isGeronimo() {
ServerUtil sd = _instance;
if (sd_geronimo == null) {
Class c = sdgetClass();
if (cgetResource(GERONIMO_CLASS) != null) {
sd_geronimo = BooleanTRUE;
} else {
sd_geronimo = BooleanFALSE;
}
}
return sd_geronimobooleanValue();
}
public static boolean isJBoss() {
ServerUtil sd = _instance;
if (sd_jBoss == null) {
Class c = sdgetClass();
if (cgetResource(JBOSS_CLASS) != null) {
sd_jBoss = BooleanTRUE;
} else {
sd_jBoss = BooleanFALSE;
}
}
return sd_jBossbooleanValue();
}
public static boolean isJetty() {
ServerUtil sd = _instance;
if (sd_jetty == null) {
Class c = sdgetClass();
if (cgetResource(JETTY_CLASS) != null) {
sd_jetty = BooleanTRUE;
} else {
sd_jetty = BooleanFALSE;
}
}
return sd_jettybooleanValue();
}
public static boolean isJOnAS() {
ServerUtil sd = _instance;
if (sd_jonas == null) {
Class c = sdgetClass();
if (cgetResource(JONAS_CLASS) != null) {
sd_jonas = BooleanTRUE;
} else {
sd_jonas = BooleanFALSE;
}
}
return sd_jonasbooleanValue();
}
public static boolean isOC4J() {
ServerUtil sd = _instance;
if (sd_oc4j == null) {
Class c = sdgetClass();
if (cgetResource(OC4J_CLASS) != null) {
sd_oc4j = BooleanTRUE;
} else {
sd_oc4j = BooleanFALSE;
}
}
return sd_oc4jbooleanValue();
}
public static boolean isOrion() {
ServerUtil sd = _instance;
if (sd_orion == null) {
Class c = sdgetClass();
if (cgetResource(ORION_CLASS) != null) {
sd_orion = BooleanTRUE;
} else {
sd_orion = BooleanFALSE;
}
}
return sd_orionbooleanValue();
}
public static boolean isPramati() {
ServerUtil sd = _instance;
if (sd_pramati == null) {
Class c = sdgetClass();
if (cgetResource(PRAMATI_CLASS) != null) {
sd_pramati = BooleanTRUE;
} else {
sd_pramati = BooleanFALSE;
}
}
return sd_pramatibooleanValue();
}
public static boolean isResin() {
ServerUtil sd = _instance;
if (sd_resin == null) {
Class c = sdgetClass();
if (cgetResource(RESIN_CLASS) != null) {
sd_resin = BooleanTRUE;
} else {
sd_resin = BooleanFALSE;
}
}
return sd_resinbooleanValue();
}
public static boolean isRexIP() {
ServerUtil sd = _instance;
if (sd_rexIP == null) {
Class c = sdgetClass();
if (cgetResource(REXIP_CLASS) != null) {
sd_rexIP = BooleanTRUE;
} else {
sd_rexIP = BooleanFALSE;
}
}
return sd_rexIPbooleanValue();
}
public static boolean isSun() {
if (isSun7() || isSun8()) {
return true;
} else {
return false;
}
}
public static boolean isSun7() {
ServerUtil sd = _instance;
if (sd_sun7 == null) {
Class c = sdgetClass();
if (cgetResource(SUN7_CLASS) != null) {
sd_sun7 = BooleanTRUE;
} else {
sd_sun7 = BooleanFALSE;
}
}
return sd_sun7booleanValue();
}
public static boolean isSun8() {
ServerUtil sd = _instance;
if (sd_sun8 == null) {
Class c = sdgetClass();
if (cgetResource(SUN8_CLASS) != null) {
sd_sun8 = BooleanTRUE;
} else {
sd_sun8 = BooleanFALSE;
}
}
return sd_sun8booleanValue();
}
public static boolean isTomcat() {
ServerUtil sd = _instance;
if (sd_tomcat == null) {
Class c = sdgetClass();
if (cgetResource(TOMCAT_CLASS) != null) {
sd_tomcat = BooleanTRUE;
} else {
sd_tomcat = BooleanFALSE;
}
}
return sd_tomcatbooleanValue();
}
public static boolean isWebLogic() {
ServerUtil sd = _instance;
if (sd_webLogic == null) {
Class c = sdgetClass();
if (cgetResource(WEBLOGIC_CLASS) != null) {
sd_webLogic = BooleanTRUE;
} else {
sd_webLogic = BooleanFALSE;
}
}
return sd_webLogicbooleanValue();
}
public static boolean isWebSphere() {
ServerUtil sd = _instance;
if (sd_webSphere == null) {
Class c = sdgetClass();
if (cgetResource(WEBSPHERE_CLASS) != null) {
sd_webSphere = BooleanTRUE;
} else {
sd_webSphere = BooleanFALSE;
}
}
return sd_webSpherebooleanValue();
}
private ServerUtil() {
}
private static Logger _log = LoggergetLogger(ServerUtilclass);
private static ServerUtil _instance = new ServerUtil();
private String _serverId;
private Boolean _geronimo;
private Boolean _jBoss;
private Boolean _jetty;
private Boolean _jonas;
private Boolean _oc4j;
private Boolean _orion;
private Boolean _pramati;
private Boolean _resin;
private Boolean _rexIP;
private Boolean _sun7;
private Boolean _sun8;
private Boolean _tomcat;
private Boolean _webLogic;
private Boolean _webSphere;
}
代码来自 javaRoger 的博客,求采纳
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)