[jboss-cvs] jboss-seam/src/main/org/jboss/seam/init ...
Gavin King
gavin.king at jboss.com
Wed Mar 7 00:20:40 EST 2007
User: gavin
Date: 07/03/07 00:20:40
Modified: src/main/org/jboss/seam/init Initialization.java
Log:
hot deployment for JavaBean components
Revision Changes Path
1.156 +110 -19 jboss-seam/src/main/org/jboss/seam/init/Initialization.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Initialization.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/init/Initialization.java,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -b -r1.155 -r1.156
--- Initialization.java 27 Feb 2007 22:06:12 -0000 1.155
+++ Initialization.java 7 Mar 2007 05:20:40 -0000 1.156
@@ -5,9 +5,12 @@
*/
package org.jboss.seam.init;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
@@ -22,6 +25,7 @@
import javax.servlet.Filter;
import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
import org.dom4j.Attribute;
import org.dom4j.DocumentException;
@@ -58,7 +62,7 @@
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.155 $
+ * @version $Revision: 1.156 $
*/
public class Initialization
{
@@ -74,9 +78,16 @@
private Map<String, NamespaceDescriptor> namespaceMap = new HashMap<String, NamespaceDescriptor>();
private final Map<String, EventListenerDescriptor> eventListenerDescriptors = new HashMap<String, EventListenerDescriptor>();
+ private File[] hotDeployPaths;
+ private ClassLoader hotDeployClassLoader;
+
public Initialization(ServletContext servletContext)
{
this.servletContext = servletContext;
+ }
+
+ public Initialization create()
+ {
addNamespaces();
initComponentsFromXmlDocument("/WEB-INF/components.xml");
initComponentsFromXmlDocument("/WEB-INF/events.xml"); //deprecated
@@ -84,6 +95,7 @@
initPropertiesFromServletContext();
initPropertiesFromResource();
initJndiProperties();
+ return this;
}
private void initComponentsFromXmlDocuments()
@@ -472,22 +484,105 @@
public Initialization init()
{
log.info("initializing Seam");
- scanForComponents();
Lifecycle.beginInitialization(servletContext);
Contexts.getApplicationContext().set(Component.PROPERTIES, properties);
- addComponents();
+ initHotDeployClassLoader();
+ scanForHotDeployableComponents();
+ scanForComponents();
+
+ addComponent( new ComponentDescriptor(Init.class), Contexts.getApplicationContext() );
+ Init init = (Init) Component.getInstance(Init.class, ScopeType.APPLICATION);
+ ComponentDescriptor desc = findDescriptor(Jbpm.class);
+ if (desc != null && desc.isInstalled())
+ {
+ init.setJbpmInstalled(true);
+ }
+ init.setTimestamp( System.currentTimeMillis() );
+ init.setHotDeployPaths(hotDeployPaths);
+
+ addSpecialComponents(init);
+ installComponents(init);
Lifecycle.endInitialization();
log.info("done initializing Seam");
return this;
}
- private void scanForComponents()
+ public Initialization redeploy(HttpSession session)
+ {
+ log.info("redeploying");
+ Lifecycle.beginReinitialization(servletContext, session);
+ Init init = Init.instance();
+ for ( String name: init.getHotDeployableComponents() )
+ {
+ Component component = Component.forName(name);
+ ScopeType scope = component.getScope();
+ if (scope.isContextActive())
+ {
+ scope.getContext().remove(name);
+ }
+ Contexts.getApplicationContext().remove(name + ".component");
+ }
+ initHotDeployClassLoader();
+ scanForHotDeployableComponents();
+ init.setTimestamp( System.currentTimeMillis() );
+ init.setHotDeployPaths(hotDeployPaths);
+ installComponents(init);
+ Lifecycle.endInitialization();
+ log.info("done redeploying");
+ return this;
+ }
+
+ private void initHotDeployClassLoader()
+ {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ String webxmlPath = contextClassLoader.getResource("META-INF/debug.xhtml").toExternalForm();
+ String hotDeployDirectory = webxmlPath.substring( 9, webxmlPath.length()-46 ) + "dev";
+ File directory = new File(hotDeployDirectory);
+ log.info(directory);
+ URL url = directory.toURL();
+ log.info(url);
+ /*File[] jars = directory.listFiles( new FilenameFilter() {
+ public boolean accept(File file, String name) { return name.endsWith(".jar"); }
+ } );
+ URL[] urls = new URL[jars.length];
+ for (int i=0; i<jars.length; i++)
+ {
+ urls[i] = jars[i].toURL();
+ }*/
+ URL[] urls = {url};
+ hotDeployClassLoader = new URLClassLoader(urls, contextClassLoader);
+ hotDeployPaths = new File[] {directory};
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new RuntimeException(mue);
+ }
+ }
+
+ private void scanForHotDeployableComponents()
+ {
+ if ( hotDeployClassLoader!=null )
{
+ Set<Class<Object>> scannedClasses = new HashSet<Class<Object>>();
+ scannedClasses.addAll( new ComponentScanner(null, hotDeployClassLoader).getClasses() );
Set<Package> scannedPackages = new HashSet<Package>();
+ for (Class<Object> scannedClass: scannedClasses)
+ {
+ installScannedClass(scannedPackages, scannedClass);
+ }
+ }
+ }
+
+ private void scanForComponents()
+ {
Set<Class<Object>> scannedClasses = new HashSet<Class<Object>>();
scannedClasses.addAll( new ComponentScanner("seam.properties").getClasses() );
scannedClasses.addAll( new ComponentScanner("META-INF/seam.properties").getClasses() );
scannedClasses.addAll( new ComponentScanner("META-INF/components.xml").getClasses() );
+
+ Set<Package> scannedPackages = new HashSet<Package>();
for (Class<Object> scannedClass: scannedClasses)
{
installScannedClass(scannedPackages, scannedClass);
@@ -668,20 +763,8 @@
return null;
}
- protected void addComponents()
+ private void addSpecialComponents(Init init)
{
- Context context = Contexts.getApplicationContext();
-
- // force instantiation of Init
- addComponent( new ComponentDescriptor(Init.class), context );
- Init init = (Init) Component.getInstance(Init.class, ScopeType.APPLICATION);
-
- ComponentDescriptor desc = findDescriptor(Jbpm.class);
- if (desc != null && desc.isInstalled())
- {
- init.setJbpmInstalled(true);
- }
-
try
{
Reflections.classForName("org.jboss.cache.aop.PojoCache");
@@ -698,8 +781,12 @@
addComponentDescriptor( new ComponentDescriptor(Introspector.class, true) );
addComponentDescriptor( new ComponentDescriptor(org.jboss.seam.debug.Contexts.class, true) );
}
+ }
+ private void installComponents(Init init)
+ {
log.info("Installing components...");
+ Context context = Contexts.getApplicationContext();
boolean installedSomething = false;
do
{
@@ -827,6 +914,10 @@
descriptor.getJndiName()
);
context.set(componentName, component);
+ if ( descriptor.getComponentClass().getClassLoader()==hotDeployClassLoader )
+ {
+ Init.instance().addHotDeployableComponent( component.getName() );
+ }
}
catch (Throwable e)
{
More information about the jboss-cvs-commits
mailing list