一、前言
这个通过分享系统运行Runtime类代码,反应对于在系统运行阶段设计所要兼顾考虑非功能性的管理的事情 - ApplicationManager(应用管理)、DomainManager(区空间管理)、LogManager(日志管理)、ThreadManager(线程管理)、FileManager(文件管理)、ConnectionManager(连接管理)、TransportManager(事物管理)、EventManager(事件管理)、PlatformManager(平台管理)、ClassLoaderManager(类加载器管理)、DocumentManager(文档管理)、DataManager(数据管理)、PersistenceManager(持久化管理)、ExpressionManager(表达式管理)、TemplateManager(模板管理)、BuilderManager(构造器管理)、CollectionManager(集合管理)、NamingManager(命名空间管理)、SecurityManager(安全管理)、SessionManager(会话管理)、SchemaManager(结构化文档管理)。
二、代码示例
public class Runtime extends BaseDispatcher<String, Event>@b@ implements BeanPostProcessor, ApplicationContextAware, PriorityOrdered, Activatable@b@{@b@ private static Runtime a;@b@ private AnnotationBeanPostProcessor b = new AnnotationBeanPostProcessor();@b@ private ApplicationManager c;@b@ private boolean d;@b@ private DomainManager e;@b@ private LogManager f;@b@ private ThreadManager g;@b@ private FileManager h;@b@ private ConnectionManager i;@b@ private TransportManager j;@b@ private EventManager k;@b@ private PlatformManager l;@b@ private ClassLoaderManager m;@b@ private DocumentManager n;@b@ private DataManager o;@b@ private PersistenceManager p;@b@ private ExpressionManager q;@b@ private TemplateManager r;@b@ private BuilderManager s;@b@ private CollectionManager t;@b@ private NamingManager u;@b@ private SecurityManager v;@b@ private SessionManager w;@b@ private SchemaManager x;@b@@b@ public static Runtime getInstance()@b@ {@b@ if (a == null) {@b@ try {@b@ Properties localProperties = System.getProperties();@b@ localProperties.loadFromXML(Thread.currentThread().getContextClassLoader().getResourceAsStream("properties.xml"));@b@ System.setProperties(localProperties);@b@ } catch (Exception localException) {@b@ localException.printStackTrace(System.err);@b@ }@b@@b@ Java.setDomainType(Java.getDomainType());@b@ Java.setDomainName(Java.getDomainName());@b@ Java.setDomainHome(Java.getDomainHome());@b@ Java.setDomainConfig(Java.getDomainConfig());@b@ Java.setDomainSite(Java.getDomainSite());@b@ Java.setDomainPersistenceDriver(Java.getDomainPersistenceDriver());@b@ Java.setDomainPersistenceUrl(Java.getDomainPersistenceUrl());@b@ Java.setDomainPersistenceUser(Java.getDomainPersistenceUser());@b@ Java.setDomainPersistencePassword(Java.getDomainPersistencePassword());@b@ Java.setDomainPersistenceCacheType(Java.getDomainPersistenceCacheType());@b@@b@ ClassPathXmlApplicationContext localClassPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath*:META-INF/domain/application.xml");@b@ a = new Runtime();@b@ }@b@ return a;@b@ }@b@@b@ public Runtime()@b@ {@b@ if (a == null)@b@ a = this;@b@ else@b@ throw new RuntimeException("Runtime must be singleton instance.");@b@ }@b@@b@ public Properties getProperties()@b@ {@b@ return System.getProperties();@b@ }@b@@b@ public void setProperties(Properties paramProperties) {@b@ System.getProperties().putAll(paramProperties);@b@ }@b@@b@ public ApplicationContext getApplicationContext()@b@ {@b@ return this.b.getApplicationContext();@b@ }@b@@b@ public void setApplicationContext(ApplicationContext paramApplicationContext)@b@ {@b@ this.b.setApplicationContext(paramApplicationContext);@b@ }@b@@b@ public Object postProcessBeforeInitialization(Object paramObject, String paramString)@b@ {@b@ return this.b.postProcessBeforeInitialization(paramObject, paramString);@b@ }@b@@b@ public Object postProcessAfterInitialization(Object paramObject, String paramString)@b@ {@b@ return this.b.postProcessAfterInitialization(paramObject, paramString);@b@ }@b@@b@ public int getOrder()@b@ {@b@ return this.b.getOrder();@b@ }@b@@b@ public boolean isActivated()@b@ {@b@ return this.d;@b@ }@b@@b@ public void activate()@b@ {@b@ if (isActivated())@b@ return;@b@ this.d = true;@b@@b@ getSecurityManager().activate();@b@ getLogManager().activate();@b@ getThreadManager().activate();@b@ getFileManager().activate();@b@ getNamingManager().activate();@b@ if (("context".equals(Java.getDomainType())) || ("domain".equals(Java.getDomainType()))) {@b@ getTransportManager().activate();@b@ getConnectionManager().activate();@b@ }@b@ }@b@@b@ public void passivate()@b@ {@b@ if (!(isActivated()))@b@ return;@b@ this.d = false;@b@@b@ if (("context".equals(Java.getDomainType())) || ("domain".equals(Java.getDomainType()))) {@b@ getConnectionManager().passivate();@b@ getTransportManager().passivate();@b@ }@b@ getNamingManager().passivate();@b@ getFileManager().passivate();@b@ getThreadManager().passivate();@b@ getLogManager().passivate();@b@ getSecurityManager().passivate();@b@ }@b@@b@ public ApplicationManager getApplicationManager()@b@ {@b@ if (this.c == null)@b@ this.c = new BaseApplicationManager();@b@ return this.c;@b@ }@b@@b@ public DomainManager getDomainManager()@b@ {@b@ if (this.e == null)@b@ this.e = ((DomainManager)getApplicationContext().getBean("domainManager"));@b@ return this.e;@b@ }@b@@b@ public LogManager getLogManager()@b@ {@b@ if (this.f == null)@b@ this.f = ((LogManager)getApplicationContext().getBean("logManager"));@b@ return this.f;@b@ }@b@@b@ public DataManager getDataManager()@b@ {@b@ if (this.o == null)@b@ this.o = ((DataManager)getApplicationContext().getBean("dataManager"));@b@ return this.o;@b@ }@b@@b@ public ThreadManager getThreadManager()@b@ {@b@ if (this.g == null)@b@ this.g = ((ThreadManager)getApplicationContext().getBean("threadManager"));@b@ return this.g;@b@ }@b@@b@ public FileManager getFileManager()@b@ {@b@ if (this.h == null)@b@ this.h = ((FileManager)getApplicationContext().getBean("fileManager"));@b@ return this.h;@b@ }@b@@b@ public ConnectionManager getConnectionManager()@b@ {@b@ if (this.i == null)@b@ this.i = ((ConnectionManager)getApplicationContext().getBean("connectionManager"));@b@ return this.i;@b@ }@b@@b@ public TransportManager<? extends Transport<?, ?, ?>> getTransportManager()@b@ {@b@ if (this.j == null)@b@ this.j = ((TransportManager)getApplicationContext().getBean("transportManager"));@b@ return this.j;@b@ }@b@@b@ public EventManager getEventManager()@b@ {@b@ if (this.k == null)@b@ this.k = ((EventManager)getApplicationContext().getBean("eventManager"));@b@ return this.k;@b@ }@b@@b@ public PersistenceManager getPersistenceManager()@b@ {@b@ if (this.p == null)@b@ this.p = ((PersistenceManager)getApplicationContext().getBean("persistenceManager"));@b@ return this.p;@b@ }@b@@b@ public DocumentManager getDocumentManager()@b@ {@b@ if (this.n == null)@b@ this.n = ((DocumentManager)getApplicationContext().getBean("documentManager"));@b@ return this.n;@b@ }@b@@b@ public ExpressionManager getExpressionManager()@b@ {@b@ if (this.q == null)@b@ this.q = ((ExpressionManager)getApplicationContext().getBean("expressionManager"));@b@ return this.q;@b@ }@b@@b@ public TemplateManager getTemplateManager()@b@ {@b@ if (this.r == null)@b@ this.r = ((TemplateManager)getApplicationContext().getBean("templateManager"));@b@ return this.r;@b@ }@b@@b@ public SchemaManager getSchemaManager()@b@ {@b@ if (this.x == null)@b@ this.x = ((SchemaManager)getApplicationContext().getBean("schemaManager"));@b@ return this.x;@b@ }@b@@b@ public NamingManager getNamingManager()@b@ {@b@ if (this.u == null)@b@ this.u = ((NamingManager)getApplicationContext().getBean("namingManager"));@b@ return this.u;@b@ }@b@@b@ public SecurityManager getSecurityManager()@b@ {@b@ if (this.v == null)@b@ this.v = ((SecurityManager)getApplicationContext().getBean("securityManager"));@b@ return this.v;@b@ }@b@@b@ public SessionManager getSessionManager()@b@ {@b@ if (this.w == null)@b@ this.w = ((SessionManager)getApplicationContext().getBean("sessionManager"));@b@ return this.w;@b@ }@b@@b@ public ClassLoaderManager getClassLoaderManager()@b@ {@b@ if (this.m == null)@b@ this.m = ((ClassLoaderManager)getApplicationContext().getBean("classLoaderManager"));@b@ return this.m;@b@ }@b@@b@ public PlatformManager getPlatformManager()@b@ {@b@ if (this.l == null)@b@ this.l = ((PlatformManager)getApplicationContext().getBean("platformManager"));@b@ return this.l;@b@ }@b@@b@ public BuilderManager getBuilderManager()@b@ {@b@ if (this.s == null)@b@ this.s = ((BuilderManager)getApplicationContext().getBean("builderManager"));@b@ return this.s;@b@ }@b@@b@ public CollectionManager getCollectionManager()@b@ {@b@ if (this.t == null)@b@ this.t = ((CollectionManager)getApplicationContext().getBean("collectionManager"));@b@ return this.t;@b@ }@b@}
public class Core {@b@ public static final String JAVA_HOME = "java.home";@b@ public static final String SYSTEM_HOME = "system.home";@b@ public static final String SYSTEM = "sys";@b@ public static final String SYSTEM_NAME = "sys.name";@b@ public static final String SYSTEM_HOME = "sys.home";@b@ public static final String SYSTEM_OS = "sys.os";@b@ public static final String SYSTEM_VAR = "sys.var";@b@ public static final String SYSTEM_VERSION = "sys.version";@b@ public static final String SYSTEM_PROPERTIES = "sys.properties";@b@ public static final String SYSTEM_DOMAIN_TYPE = "sys.domain.type";@b@ public static final String SYSTEM_DOMAIN_NAME = "sys.domain.name";@b@ public static final String SYSTEM_DOMAIN_HOME = "sys.domain.home";@b@ public static final String SYSTEM_DOMAIN_CONFIG = "sys.domain.config";@b@ public static final String SYSTEM_DOMAIN_SITE = "sys.domain.site";@b@ public static final String SYSTEM_DOMAIN_PERSISTENCE_JDBC_DRIVER = "sys.domain.persistence.jdbc.driver";@b@ public static final String SYSTEM_DOMAIN_PERSISTENCE_JDBC_URL = "sys.domain.persistence.jdbc.url";@b@ public static final String SYSTEM_DOMAIN_PERSISTENCE_JDBC_USER = "sys.domain.persistence.jdbc.user";@b@ public static final String SYSTEM_DOMAIN_PERSISTENCE_JDBC_PASSWORD = "sys.domain.persistence.jdbc.password";@b@ public static final String SYSTEM_DOMAIN_PERSISTENCE_JDBC_CACHE_TYPE = "sys.domain.persistence.cache.type.default";@b@ public static final String EMBEDDED = "embedded";@b@ public static final String RUNTIME = "runtime";@b@ public static final String DOMAIN = "domain";@b@ public static final String CONTEXT = "context";@b@ public static final String APPLICATION = "application";@b@ private static String a;@b@ private static String b;@b@ private static String c;@b@ private static String d;@b@ private static String e;@b@ private static String f;@b@ private static String g;@b@ private static String h;@b@ private static String i;@b@ private static String j;@b@@b@ public static Properties getProperties() {@b@ Class localClass;@b@ Object localObject1;@b@ try {@b@ localClass = Class.forName("osi.system.SystemEnvironment");@b@ localObject1 = localClass.getMethod("getSystemEnvironment",@b@ new Class[0]).invoke(null, new Object[0]);@b@ return ((Properties) localClass.getMethod("getProperties",@b@ new Class[0]).invoke(localObject1, new Object[0]));@b@ } catch (Throwable localThrowable1) {@b@ localObject1 = new Properties();@b@ try {@b@ Object localObject2 = null;@b@ File localFile = new File("sys.properties");@b@ if (localFile.exists())@b@ localObject2 = new FileInputStream(localFile);@b@ else@b@ localObject2 = ClassLoader@b@ .getSystemResourceAsStream("sys.properties");@b@ if (localObject2 != null)@b@ ((Properties) localObject1)@b@ .load((InputStream) localObject2);@b@@b@ for (Enumeration localEnumeration = ((Properties) localObject1)@b@ .propertyNames(); localEnumeration.hasMoreElements();) {@b@ String str = (String) localEnumeration.nextElement();@b@ System.setProperty(str,@b@ ((Properties) localObject1).getProperty(str));@b@ }@b@ } catch (Throwable localThrowable2) {@b@ System.err.println("sys.properties not found.");@b@ }@b@ }@b@ return ((Properties) (Properties) localObject1);@b@ }@b@@b@ public static String getName() {@b@ String str = System.getProperty("sys.name");@b@ if ((str == null) || (str.length() == 0)) {@b@ try {@b@ Class localClass = Class@b@ .forName("osi.system.SystemEnvironment");@b@ Object localObject = localClass.getMethod(@b@ "getSystemEnvironment", new Class[0]).invoke(null,@b@ new Object[0]);@b@ str = (String) localClass.getMethod("getName", new Class[0])@b@ .invoke(localObject, new Object[0]);@b@ } catch (Throwable localThrowable) {@b@ str = getProperties().getProperty("sys.name");@b@ }@b@ if ((str == null) || (str.length() == 0))@b@ str = "sys";@b@ }@b@ return str;@b@ }@b@@b@ public static void setName(String paramString) {@b@ System.setProperty("sys.name", paramString);@b@ }@b@@b@ public static String getHome() {@b@ String str = System.getProperty("sys.home");@b@ if ((str == null) || (str.length() == 0))@b@ try {@b@ Class localClass = Class@b@ .forName("osi.system.SystemEnvironment");@b@ Object localObject = localClass.getMethod(@b@ "getSystemEnvironment", new Class[0]).invoke(null,@b@ new Object[0]);@b@ str = (String) localClass.getMethod("getHome", new Class[0])@b@ .invoke(localObject, new Object[0]);@b@ } catch (Throwable localThrowable) {@b@ str = getProperties().getProperty("sys.home");@b@ if ((str == null) || (str.length() == 0))@b@ str = System.getProperty("user.home") + "/" + getName();@b@ }@b@@b@ return str;@b@ }@b@@b@ public static void setHome(String paramString) {@b@ System.setProperty("sys.home", paramString);@b@ }@b@@b@ public static String getOs() {@b@ String str = System.getProperty("sys.os");@b@ if ((str == null) || (str.length() == 0))@b@ try {@b@ Class localClass = Class@b@ .forName("osi.system.SystemEnvironment");@b@ Object localObject = localClass.getMethod(@b@ "getSystemEnvironment", new Class[0]).invoke(null,@b@ new Object[0]);@b@ str = (String) localClass.getMethod("getOs", new Class[0])@b@ .invoke(localObject, new Object[0]);@b@ } catch (Throwable localThrowable) {@b@ str = getProperties().getProperty("sys.os");@b@ }@b@@b@ return str;@b@ }@b@@b@ public static void setOs(String paramString) {@b@ System.setProperty("sys.os", paramString);@b@ }@b@@b@ public static String getVar() {@b@ String str = System.getProperty("sys.var");@b@ if ((str == null) || (str.length() == 0))@b@ try {@b@ Class localClass = Class@b@ .forName("osi.system.SystemEnvironment");@b@ Object localObject = localClass.getMethod(@b@ "getSystemEnvironment", new Class[0]).invoke(null,@b@ new Object[0]);@b@ str = (String) localClass.getMethod("getVar", new Class[0])@b@ .invoke(localObject, new Object[0]);@b@ } catch (Throwable localThrowable) {@b@ str = getProperties().getProperty("sys.var");@b@ }@b@@b@ return str;@b@ }@b@@b@ public static void setVar(String paramString) {@b@ System.setProperty("sys.var", paramString);@b@ }@b@@b@ public static String getVersion() {@b@ return System.getProperty("sys.version");@b@ }@b@@b@ public static void setVersion(String paramString) {@b@ System.setProperty("sys.version", paramString);@b@ }@b@@b@ public static String getDomainType() {@b@ if ((a == null) || (a.length() == 0)) {@b@ a = System.getProperty("sys.domain.type");@b@ if ((a == null) || (a.length() == 0))@b@ a = "embedded";@b@ }@b@ return a;@b@ }@b@@b@ public static void setDomainType(String paramString) {@b@ a = paramString;@b@ if ((paramString != null) && (paramString.length() != 0))@b@ System.setProperty("sys.domain.type", paramString);@b@ }@b@@b@ public static String getDomainName() {@b@ if ((b == null) || (b.length() == 0)) {@b@ b = System.getProperty("sys.domain.name");@b@ if ((b == null) || (b.length() == 0))@b@ b = getName();@b@ }@b@ return b;@b@ }@b@@b@ public static void setDomainName(String paramString) {@b@ b = paramString;@b@ if ((b != null) && (b.length() != 0))@b@ System.setProperty("sys.domain.name", b);@b@ }@b@@b@ public static String getDomainHome() {@b@ if ((c == null) || (c.length() == 0)) {@b@ c = System.getProperty("sys.domain.home");@b@ if ((c == null) || (c.length() == 0))@b@ c = getHome();@b@ if ((c == null) || (c.length() == 0))@b@ c = ".";@b@ }@b@ return c;@b@ }@b@@b@ public static void setDomainHome(String paramString) {@b@ c = paramString;@b@ if ((c != null) && (c.length() != 0))@b@ System.setProperty("sys.domain.home", c);@b@ }@b@@b@ public static String getDomainConfig() {@b@ if ((d == null) || (d.length() == 0)) {@b@ d = System.getProperty("sys.domain.config");@b@ if ((d == null) || (d.length() == 0))@b@ d = "config.xml";@b@ }@b@ return d;@b@ }@b@@b@ public static void setDomainConfig(String paramString) {@b@ d = paramString;@b@ if ((d != null) && (d.length() != 0))@b@ System.setProperty("sys.domain.config", d);@b@ }@b@@b@ public static String getDomainSite() {@b@ if ((e == null) || (e.length() == 0)) {@b@ e = System.getProperty("sys.domain.site");@b@ if ((e == null) || (e.length() == 0))@b@ e = getDomainName();@b@ }@b@ return e;@b@ }@b@@b@ public static void setDomainSite(String paramString) {@b@ e = paramString;@b@ if ((e != null) && (e.length() != 0))@b@ System.setProperty("sys.domain.site", e);@b@ }@b@@b@ public static String getDomainPersistenceDriver() {@b@ if ((f == null) || (f.length() == 0)) {@b@ f = System.getProperty("sys.domain.persistence.jdbc.driver");@b@ if ((f == null) || (f.length() == 0))@b@ f = "org.apache.derby.jdbc.EmbeddedDriver";@b@ }@b@ return f;@b@ }@b@@b@ public static void setDomainPersistenceDriver(String paramString) {@b@ f = paramString;@b@ if ((f != null) && (f.length() != 0))@b@ System.setProperty("sys.domain.persistence.jdbc.driver", f);@b@ }@b@@b@ public static String getDomainPersistenceUrl() {@b@ if ((g == null) || (g.length() == 0)) {@b@ g = System.getProperty("sys.domain.persistence.jdbc.url");@b@ if ((g == null) || (g.length() == 0))@b@ g = "jdbc:derby:xma;create=true";@b@ }@b@ return g;@b@ }@b@@b@ public static void setDomainPersistenceUrl(String paramString) {@b@ g = paramString;@b@ if ((g != null) && (g.length() != 0))@b@ System.setProperty("sys.domain.persistence.jdbc.url", g);@b@ }@b@@b@ public static String getDomainPersistenceUser() {@b@ if ((h == null) || (h.length() == 0)) {@b@ h = System.getProperty("sys.domain.persistence.jdbc.user");@b@ if ((h == null) || (h.length() == 0))@b@ h = getName();@b@ }@b@ return h;@b@ }@b@@b@ public static void setDomainPersistenceUser(String paramString) {@b@ h = paramString;@b@ if ((h != null) && (h.length() != 0))@b@ System.setProperty("sys.domain.persistence.jdbc.user", h);@b@ }@b@@b@ public static String getDomainPersistencePassword() {@b@ if ((i == null) || (i.length() == 0)) {@b@ i = System.getProperty("sys.domain.persistence.jdbc.password");@b@ if ((i == null) || (i.length() == 0))@b@ i = getName();@b@ }@b@ return i;@b@ }@b@@b@ public static void setDomainPersistencePassword(String paramString) {@b@ i = paramString;@b@ if ((i != null) && (i.length() != 0))@b@ System.setProperty("sys.domain.persistence.jdbc.password", i);@b@ }@b@@b@ public static String getDomainPersistenceCacheType() {@b@ if ((j == null) || (j.length() == 0)) {@b@ j = System.getProperty("sys.domain.persistence.cache.type.default");@b@ if ((j == null) || (j.length() == 0))@b@ j = "NONE";@b@ }@b@ return j;@b@ }@b@@b@ public static void setDomainPersistenceCacheType(String paramString) {@b@ j = paramString;@b@ if ((j != null) && (j.length() != 0))@b@ System.setProperty("sys.domain.persistence.cache.type.default", j);@b@ }@b@@b@ public static Runtime getRuntime() {@b@ return Runtime.getInstance();@b@ }@b@@b@ public static Domain getDomain() {@b@ return getDomainManager().getDomain();@b@ }@b@@b@ public static Domain getDomain(String paramString) {@b@ return getDomainManager().getDomain(paramString);@b@ }@b@@b@ public static Application getApplication() {@b@ return getDomain().getApplicationManager().getApplication();@b@ }@b@@b@ public static Application getApplication(Object paramObject) {@b@ return getDomain().getApplicationManager().getApplication(paramObject);@b@ }@b@@b@ public static DomainManager getDomainManager() {@b@ return getRuntime().getDomainManager();@b@ }@b@@b@ public static DataManager getDataManager() {@b@ return getRuntime().getDataManager();@b@ }@b@@b@ public static LogManager getLogManager() {@b@ return getRuntime().getLogManager();@b@ }@b@@b@ public static ThreadManager getThreadManager() {@b@ return getRuntime().getThreadManager();@b@ }@b@@b@ public static FileManager getFileManager() {@b@ return getRuntime().getFileManager();@b@ }@b@@b@ public static TransportManager<? extends Transport<?, ?, ?>> getTransportManager() {@b@ return getRuntime().getTransportManager();@b@ }@b@@b@ public static ConnectionManager getConnectionManager() {@b@ return getRuntime().getConnectionManager();@b@ }@b@@b@ public static EventManager getEventManager() {@b@ return getRuntime().getEventManager();@b@ }@b@@b@ public static PersistenceManager getPersistenceManager() {@b@ return getRuntime().getPersistenceManager();@b@ }@b@@b@ public static DocumentManager getDocumentManager() {@b@ return getRuntime().getDocumentManager();@b@ }@b@@b@ public static ExpressionManager<? extends Expression> getExpressionManager() {@b@ return getRuntime().getExpressionManager();@b@ }@b@@b@ public static TemplateManager getTemplateManager() {@b@ return getRuntime().getTemplateManager();@b@ }@b@@b@ public static SchemaManager<? extends Schema<?>> getSchemaManager() {@b@ return getRuntime().getSchemaManager();@b@ }@b@@b@ public static NamingManager getNamingManager() {@b@ return getRuntime().getNamingManager();@b@ }@b@@b@ public static SecurityManager getSecurityManager() {@b@ return getRuntime().getSecurityManager();@b@ }@b@@b@ public static SessionManager getSessionManager() {@b@ return getRuntime().getSessionManager();@b@ }@b@@b@ public static ClassLoaderManager getClassLoaderManager() {@b@ return getRuntime().getClassLoaderManager();@b@ }@b@@b@ public static PlatformManager getPlatformManager() {@b@ return getRuntime().getPlatformManager();@b@ }@b@@b@ public static BuilderManager<Builder> getBuilderManager() {@b@ return getRuntime().getBuilderManager();@b@ }@b@@b@ public static CollectionManager getCollectionManager() {@b@ return getRuntime().getCollectionManager();@b@ }@b@}