NC的运行环境 类
2023-12-25 12:15:27
NC的运行环境类
package nc.bs.framework.common;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import nc.bs.framework.common.RuntimeEnv.1;
import nc.bs.framework.exception.FrameworkRuntimeException;
import nc.bs.framework.util.PropertyUtil;
import nc.bs.logging.Logger;
import nc.vo.jcom.env.EnvironmentUtil;
import nc.vo.jcom.util.ClassUtil;
public final class RuntimeEnv {
public static final String VMID_PROPERTY = "VMID";
public static final String SERVER_LOCATION_PROPERTY = "nc.server.location";
public static final String MODULES_LOCATION_PROPERTY = "nc.modules.location";
public static final String LINE_SEP = PropertyUtil.getSystemProperty("line.separator");
private static RuntimeEnv runtimeEnv = new RuntimeEnv();
private Boolean runingServer;
private Properties abitraryProperty = new Properties();
private ClassLoader bizClassLoader = ClassUtil.getContextClassLoader();
private Boolean developmentMode;
private ThreadLocal<Boolean> threadRunningInServer = new 1(this);
public static RuntimeEnv getInstance() {
return runtimeEnv;
}
public void setBizClassLoader(ClassLoader classLoader) {
this.bizClassLoader = classLoader;
}
public ClassLoader getBizClassLoader() {
return this.bizClassLoader;
}
public boolean isRunningInBrowser() {
return !this.isRunningInServer();
}
public void setRunningInServer(boolean runningInServer) {
this.runingServer = runningInServer;
System.setProperty("nc.run.side", runningInServer ? "server" : "client");
System.setProperty("run.side", runningInServer ? "server" : "client");
}
public void setThreadRunningInServer(boolean runningInserver) {
this.threadRunningInServer.set(runningInserver);
}
public boolean isThreadRunningInServer() {
return (Boolean) this.threadRunningInServer.get();
}
public boolean isRunningInServer() {
if (this.runingServer == null) {
this.runingServer = "server".equals(System.getProperty("nc.run.side"));
}
return this.runingServer;
}
public Properties getArbitraryProperties() {
return this.abitraryProperty;
}
public Object newBizObject(String bizClassName) {
ClassLoader loader = this.getBizClassLoader();
try {
Class<?> clazz = loader.loadClass(bizClassName);
return clazz.newInstance();
} catch (ClassNotFoundException var4) {
Logger.error("Can't find the class", var4);
throw new FrameworkRuntimeException("Can't find the specified class: " + bizClassName, var4);
} catch (InstantiationException var5) {
Logger.error("Can't instantaite the object", var5);
throw new FrameworkRuntimeException("CCan't instantaite the specified object ", var5);
} catch (IllegalAccessException var6) {
Logger.error("Illegal argument excetion", var6);
throw new FrameworkRuntimeException("Illegal argument excetion ", var6);
}
}
public static boolean isRunningInWeblogic() {
return EnvironmentUtil.isRunningInWeblogic();
}
public static boolean isRunningInWebSphere() {
return EnvironmentUtil.isRunningInWebSphere();
}
public void setProperty(String name, String value) {
this.abitraryProperty.put(name, value);
}
public String getProperty(String name) {
return this.abitraryProperty.getProperty(name);
}
public String getProperty(String name, String defaultValue) {
return this.abitraryProperty.getProperty(name, defaultValue);
}
public String getNCHome() {
return this.getProperty("nc.server.location", System.getProperty("user.dir"));
}
public String getCanonicalNCHome() {
String home = this.getNCHome();
File f = new File(home);
try {
home = f.getCanonicalFile().getPath();
} catch (IOException var4) {
;
}
return home;
}
public String getModuleHome(String module) {
String moduleHome = this.getProperty("MODULE_HOME/" + module);
if (moduleHome == null) {
moduleHome = this.getNCHome() + "/modules/" + module;
}
return moduleHome;
}
public void setModuleHome(String module, String home) {
if (home != null) {
File f = new File(home);
try {
home = f.getCanonicalFile().getPath();
} catch (IOException var5) {
;
}
this.setProperty("MODULE_HOME/" + module, home);
}
}
public boolean isDevelopMode() {
if (this.developmentMode == null) {
String mode = System.getProperty("nc.runMode");
if (mode == null) {
if (!this.isRunningInServer()) {
String[] classNames = new String[]{"nc.bs.mw.fm.ServiceManager"};
int i = 0;
while (i < classNames.length) {
try {
Class.forName(classNames[i]);
this.developmentMode = Boolean.TRUE;
break;
} catch (Exception var5) {
++i;
}
}
if (this.developmentMode == null) {
this.developmentMode = Boolean.FALSE;
}
} else {
this.developmentMode = Boolean.FALSE;
}
} else {
this.developmentMode = "develop".equals(mode);
}
}
return this.developmentMode;
}
}
判断是否是开发环境
文章来源:https://blog.csdn.net/u010741112/article/details/135194128
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!