enterpriseapplication.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 805 行 · 第 1/2 页
JAVA
805 行
if (! _lifecycle.toInit()) return; Vfs.setPwd(_rootDir, _loader); _loader.addJarManifestClassPath(_rootDir); // server/13bb vs TCK if ("1.4".equals(_version)) { // XXX: tck ejb30/persistence/basic needs to add the lib/*.jar // to find the META-INF/persistence.xml fillDefaultLib(); } else { fillDefaultModules(); } if (_ejbPaths.size() != 0) { EjbContainer ejbContainer = EjbContainer.create(); for (Path path : _ejbPaths) { ejbContainer.addRoot(path); _loader.addJar(path); } _loader.validate(); // XXX:?? /* Path ejbJar = _rootDir.lookup("META-INF/ejb-jar.xml"); if (ejbJar.canRead()) { ejbContainer.addRoot(path); } */ // starts with the environment // ejbServer.start(); } // updates the invocation caches if (_container != null) _container.clearCache(); } private void fillDefaultModules() { try { fillDefaultLib(); for (String file : _rootDir.list()) { if (file.endsWith(".jar")) { Path path = _rootDir.lookup(file); Path jar = JarPath.create(path); try { if (jar.lookup("META-INF/application-client.xml").canRead()) { // app-client jar } else if (jar.lookup("META-INF/ejb-jar.xml").canRead()) { addEjbPath(path); _loader.addJar(path); _loader.addJarManifestClassPath(path); } else { addEjbPath(path); _loader.addJar(path); } } catch (java.util.zip.ZipException e) { // XXX: jpa tck, error in opening zip file // canRead() is throwing an exception when // META-INF/application-client.xml does not exist? log.log(Level.WARNING, e.toString(), e); } } else if (file.endsWith(".war")) { Module module = createModule(); WebModule web = new WebModule(); web.setWebURI(file); module.addWeb(web); } } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw ConfigException.create(e); } } private void fillDefaultLib() throws Exception { String libDir = "lib"; // ejb/0fa0 if (_libraryDirectory != null) libDir = _libraryDirectory; if (_rootDir.lookup(libDir).isDirectory()) { Path lib = _rootDir.lookup(libDir); for (String file : lib.list()) { if (file.endsWith(".jar")) { _loader.addJar(lib.lookup(file)); } } } } /** * Configures the application. */ public void start() { if (! _lifecycle.toStarting()) return; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClassLoader()); for (int i = 0; i < _webConfigList.size(); i++) { WebModule web = _webConfigList.get(i); initWeb(web); } getClassLoader().start(); for (WebAppController webApp : _webApps) { _container.getWebAppGenerator().update(webApp.getContextPath()); } } finally { _lifecycle.toActive(); thread.setContextClassLoader(oldLoader); } } void initWeb(WebModule web) { String webUri = web.getWebURI(); String contextUrl = web.getContextRoot(); Path path = _rootDir.lookup(webUri); Path archivePath = null; if (contextUrl == null) contextUrl = webUri; WebAppController controller = null; if (webUri.endsWith(".war")) { // server/2a16 String name = webUri.substring(0, webUri.length() - 4); int p = name.lastIndexOf('/'); if (p > 0) name = name.substring(p + 1); // XXX: if (contextUrl.equals("")) contextUrl = "/" + name; if (contextUrl.endsWith(".war")) contextUrl = contextUrl.substring(0, contextUrl.length() - 4); Path expandPath = _webappsPath; try { expandPath.mkdirs(); } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } archivePath = path; path = expandPath.lookup(name); } else { // server/2a15 if (contextUrl.equals("")) { String name = webUri; int p = name.lastIndexOf('/'); if (p > 0) name = name.substring(p + 1); contextUrl = "/" + name; } // server/2a17 if (contextUrl.endsWith(".war")) contextUrl = contextUrl.substring(0, contextUrl.length() - 4); } controller = findWebAppEntry(contextUrl); if (controller == null) { controller = new WebAppController(contextUrl, contextUrl, path, _container); _webApps.add(controller); } if (archivePath != null) controller.setArchivePath(archivePath); controller.setDynamicDeploy(true); if (_configException != null) controller.setConfigException(_configException); for (WebAppConfig config : web.getWebAppList()) controller.addConfigDefault(config); } /** * Returns any matching web-app. */ public WebAppController findWebAppEntry(String name) { for (int i = 0; i < _webApps.size(); i++) { WebAppController controller = _webApps.get(i); if (controller.isNameMatch(name)) return controller; } return null; } private void addDepend(Path path) { _loader.addDependency(new com.caucho.vfs.Depend(path)); } /** * Returns the webapps for the enterprise-application. */ public ArrayList<WebAppController> getApplications() { return _webApps; } /** * Stops the e-application. */ public void stop() { if (! _lifecycle.toStopping()) return; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_loader); //log.info(this + " stopping"); _loader.stop(); //log.fine(this + " stopped"); } finally { _lifecycle.toStop(); thread.setContextClassLoader(oldLoader); } } /** * destroys the e-application. */ public void destroy() { stop(); if (! _lifecycle.toDestroy()) return; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClassLoader()); log.fine(this + " destroying"); ArrayList<WebAppController> webApps = _webApps; _webApps = null; if (webApps != null) { for (WebAppController webApp : webApps) { _container.getWebAppGenerator().update(webApp.getContextPath()); } } } finally { thread.setContextClassLoader(oldLoader); _loader.destroy(); log.fine(this + " destroyed"); } } // // JMX utilities // public String getClientRefs() { EjbContainer ejbContainer = EjbContainer.create(); return ejbContainer.getClientRemoteConfig(); } public String toString() { return "EnterpriseApplication[" + getName() + "]"; } public class Module { /** * Sets the module id. */ public void setId(String id) { } /** * Creates a new web module. */ public void addWeb(WebModule web) throws Exception { String webUri = web.getWebURI(); WebModule oldWeb = findWebModule(webUri); if (oldWeb != null) { String contextUrl = web.getContextRoot(); if (contextUrl != null && ! "".equals(contextUrl)) oldWeb.setContextRoot(contextUrl); oldWeb.addWebAppList(web.getWebAppList()); } else addWebModule(web); } /** * Adds a new ejb module. */ public void addEjb(Path path) throws Exception { addEjbPath(path); _loader.addJar(path); // ejb/0853 _loader.addJarManifestClassPath(path); } /** * Adds a new java module. */ public void addJava(Path path) throws ConfigException { if (! path.canRead()) throw new ConfigException(L.l("<java> module {0} must be a valid path.", path)); } /** * Adds a new connector */ public void addConnector(String path) { } /** * Adds a new alt-dd module. */ public void addAltDD(String path) { } } private void addEjbPath(Path ejbPath) { if (_ejbPaths.contains(ejbPath)) return; _ejbPaths.add(ejbPath); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?