You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/08/17 23:38:42 UTC
svn commit: r432397 -
/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
Author: jboynes
Date: Thu Aug 17 14:38:42 2006
New Revision: 432397
URL: http://svn.apache.org/viewvc?rev=432397&view=rev
Log:
new context listener with isolated classloader
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
Modified: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java?rev=432397&r1=432396&r2=432397&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java Thu Aug 17 14:38:42 2006
@@ -18,8 +18,15 @@
*/
package org.apache.tuscany.runtime.webapp;
+import java.util.Set;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URLClassLoader;
+import java.beans.Beans;
+import java.io.IOException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContext;
/**
* Launcher for runtime environment that loads info from servlet context params.
@@ -31,13 +38,67 @@
*/
public class TuscanyContextListener implements ServletContextListener {
/**
- * Servlet context-param name for user-specified system SCDL path.
+ * Name of the context parameter that defines the directory containing bootstrap jars.
*/
- public static final String SYSTEM_SCDL_PATH_PARAM = "systemScdlPath";
+ public static final String BOOTDIR_PARAM = "tuscany.bootDir";
+
+ /**
+ * Name of the class to load to launch the runtime.
+ */
+ public static final String LAUNCHER_PARAM = "tuscany.launcherClass";
+
+ private ServletContextListener runtime;
public void contextInitialized(ServletContextEvent servletContextEvent) {
+ ServletContext servletContext = servletContextEvent.getServletContext();
+ ClassLoader bootClassLoader = getBootClassLoader(servletContext);
+
+ runtime = getLauncher(servletContext, bootClassLoader);
+
+ runtime.contextInitialized(servletContextEvent);
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ if (runtime != null) {
+ runtime.contextDestroyed(servletContextEvent);
+ }
+ }
+
+ protected ClassLoader getBootClassLoader(ServletContext servletContext) {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ String bootDirName = servletContext.getInitParameter(BOOTDIR_PARAM);
+ if (bootDirName == null) {
+ bootDirName = "/WEB-INF/tuscany/boot/";
+ }
+ Set paths = servletContext.getResourcePaths(bootDirName);
+ if (paths == null) {
+ // nothing in boot directory, assume everything is in the webapp classloader
+ return contextClassLoader;
+ }
+ URL[] urls = new URL[paths.size()];
+ int i =0;
+ for (Object path : paths) {
+ try {
+ urls[i++] = servletContext.getResource((String) path);
+ } catch (MalformedURLException e) {
+ throw new AssertionError("getResourcePaths returned an invalid path");
+ }
+ }
+ return new URLClassLoader(urls, contextClassLoader);
+ }
+
+ protected ServletContextListener getLauncher(ServletContext servletContext, ClassLoader bootClassLoader) {
+ String launcherClass = servletContext.getInitParameter(LAUNCHER_PARAM);
+ if (launcherClass == null) {
+ launcherClass = "org.apache.tuscany.core.launcher.ServletLauncherListener";
+ }
+
+ try {
+ return (ServletContextListener) Beans.instantiate(bootClassLoader, launcherClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org