Author: jboynes
Date: Fri Sep 8 11:40:43 2006
New Revision: 441608
URL: http://svn.apache.org/viewvc?view=rev&rev=441608
Log:
simpify lifecycle interface for webapp runtime
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java?view=diff&rev=441608&r1=441607&r2=441608
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
Fri Sep 8 11:40:43 2006
@@ -27,7 +27,6 @@
import java.util.StringTokenizer;
import java.util.logging.Level;
import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
import javax.servlet.http.HttpSessionEvent;
import org.osoa.sca.SCA;
@@ -85,17 +84,7 @@
private CompositeContextImpl context;
private ServletRequestInjector requestInjector;
- public SCA getContext() {
- return context;
- }
-
- public ServletRequestInjector getRequestInjector() {
- return requestInjector;
- }
-
- public void contextInitialized(ServletContextEvent event) {
- ServletContext servletContext = event.getServletContext();
-
+ public void initialize(ServletContext servletContext) {
// Read optional path to system SCDL from context-param
String systemScdlPath =
servletContext.getInitParameter(SYSTEM_SCDL_PATH_PARAM);
if (systemScdlPath == null) {
@@ -167,10 +156,18 @@
}
}
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ public void destroy() {
if (launcher != null) {
launcher.shutdownRuntime();
}
+ }
+
+ public SCA getContext() {
+ return context;
+ }
+
+ public ServletRequestInjector getRequestInjector() {
+ return requestInjector;
}
public void sessionCreated(HttpSessionEvent event) {
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java?view=diff&rev=441608&r1=441607&r2=441608
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
Fri Sep 8 11:40:43 2006
@@ -21,16 +21,16 @@
import java.net.URL;
import java.util.Collections;
import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
import junit.framework.TestCase;
+import static org.easymock.EasyMock.expect;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+
import org.apache.tuscany.api.TuscanyException;
import static
org.apache.tuscany.runtime.webapp.Constants.DEFAULT_EXTENSION_PATH_PARAM;
import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
import static
org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
-import static org.easymock.EasyMock.expect;
-import org.easymock.IAnswer;
-import org.easymock.classextension.EasyMock;
/**
* @version $Rev$ $Date$
@@ -59,11 +59,9 @@
expect(context.getResource("/WEB-INF/default.scdl")).andReturn(resource);
context.setAttribute(EasyMock.eq(RUNTIME_ATTRIBUTE),
EasyMock.isA(TuscanyWebappRuntime.class));
EasyMock.replay(context);
- ServletContextEvent event =
EasyMock.createMock(ServletContextEvent.class);
-
EasyMock.expect(event.getServletContext()).andReturn(context).anyTimes();
- EasyMock.replay(event);
- listener.contextInitialized(event);
- listener.contextDestroyed(event);
+
+ listener.initialize(context);
+ listener.destroy();
EasyMock.verify(context);
}
@@ -77,11 +75,9 @@
expect(context.getServletContextName()).andReturn("foo").anyTimes();
expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
EasyMock.replay(context);
- ServletContextEvent event =
EasyMock.createMock(ServletContextEvent.class);
- expect(event.getServletContext()).andReturn(context);
- EasyMock.replay(event);
+
try {
- listener.contextInitialized(event);
+ listener.initialize(context);
fail();
} catch (ServletLauncherInitException e) {
assertTrue(e.getCause() instanceof TuscanyException);
@@ -100,11 +96,9 @@
expect(context.getInitParameter(SYSTEM_SCDL_PATH_PARAM)).andReturn("notthere");
expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
EasyMock.replay(context);
- ServletContextEvent event =
EasyMock.createMock(ServletContextEvent.class);
- expect(event.getServletContext()).andReturn(context);
- EasyMock.replay(event);
+
try {
- listener.contextInitialized(event);
+ listener.initialize(context);
fail();
} catch (ServletLauncherInitException e) {
assertTrue(e.getCause() instanceof TuscanyException);
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java?view=diff&rev=441608&r1=441607&r2=441608
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Fri Sep 8 11:40:43 2006
@@ -68,16 +68,15 @@
return destroyed;
}
- public void contextInitialized(ServletContextEvent
servletContextEvent) {
+ public void initialize(ServletContext context) {
++initialized;
}
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ public void destroy() {
++destroyed;
}
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
-
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
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?view=diff&rev=441608&r1=441607&r2=441608
==============================================================================
---
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
Fri Sep 8 11:40:43 2006
@@ -59,7 +59,7 @@
try {
ClassLoader bootClassLoader = getBootClassLoader(servletContext);
runtime = getRuntime(servletContext, bootClassLoader);
- runtime.contextInitialized(event);
+ runtime.initialize(servletContext);
} catch (IOException e) {
servletContext.log("Error instantiating Tuscany bootstrap", e);
} catch (ClassNotFoundException e) {
@@ -71,7 +71,7 @@
public void contextDestroyed(ServletContextEvent event) {
if (runtime != null) {
- runtime.contextDestroyed(event);
+ runtime.destroy();
}
}
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java?view=diff&rev=441608&r1=441607&r2=441608
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
Fri Sep 8 11:40:43 2006
@@ -18,7 +18,7 @@
*/
package org.apache.tuscany.runtime.webapp;
-import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionListener;
import org.osoa.sca.SCA;
@@ -34,7 +34,19 @@
* @see TuscanyFilter
* @see TuscanySessionListener
*/
-public interface TuscanyWebappRuntime extends ServletContextListener,
HttpSessionListener {
+public interface TuscanyWebappRuntime extends HttpSessionListener {
+ /**
+ * Initialize a runtime for the supplied servlet context.
+ *
+ * @param context the servlet context the runtime should run in
+ */
+ void initialize(ServletContext context);
+
+ /**
+ * Destroy the runtime.
+ * Any further invocations should result in an error.
+ */
+ void destroy();
/**
* Returns the current SCA context
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]