[seam-commits] Seam SVN: r8732 - in trunk/src/main/org/jboss/seam: init and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Aug 18 17:37:45 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-08-18 17:37:45 -0400 (Mon, 18 Aug 2008)
New Revision: 8732

Added:
   trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java
Modified:
   trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
   trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
   trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
   trunk/src/main/org/jboss/seam/init/Initialization.java
   trunk/src/main/org/jboss/seam/mock/MockServletContext.java
Log:
Merge page scanning into main scanner

Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java	2008-08-18 20:58:19 UTC (rev 8731)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -2,6 +2,7 @@
 
 import static org.jboss.seam.util.Strings.split;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -30,6 +31,8 @@
 
    private Scanner scanner;
    
+   private List<File> files = new ArrayList<File>();
+   
    private Map<String, DeploymentHandler> deploymentHandlers;
    
    /**
@@ -282,5 +285,15 @@
       }
       return null;
    }
+
+   public List<File> getFiles()
+   {
+      return files;
+   }
    
+   public void setFiles(List<File> files)
+   {
+      this.files = files;
+   }
+   
 }

Added: trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -0,0 +1,95 @@
+package org.jboss.seam.deployment;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.seam.contexts.Contexts;
+
+/**
+ * The {@link DotPageDotXmlDeploymentHandler} process .page.xml files
+ *  
+ * @author Pete Muir
+ *
+ */
+public class DotPageDotXmlDeploymentHandler extends AbstractDeploymentHandler
+{
+   /**
+    * Name under which this {@link DeploymentHandler} is registered
+    */
+   public static final String NAME = "org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler";
+
+   private Set<String> files;
+   
+   public DotPageDotXmlDeploymentHandler()
+   {
+      files = new HashSet<String>();
+   }
+
+   /**
+    * Get annotated Seam components
+    */
+   public Set<String> getFiles()
+   {
+      return Collections.unmodifiableSet(files);
+   }
+
+   /**
+    * @see DeploymentHandler#handle(String, ClassLoader)
+    */
+   public void handle(String name, ClassLoader classLoader)
+   {
+      if (name.endsWith(".page.xml")) 
+      {
+         files.add(name);
+      }
+   }
+   
+   public String getName()
+   {
+      return NAME;
+   }
+   
+   public static DotPageDotXmlDeploymentHandler instance()
+   {
+      if (Contexts.isEventContextActive())
+      {
+         if (Contexts.getEventContext().isSet(HotDeploymentStrategy.NAME))
+         {
+            DeploymentStrategy deploymentStrategy = (DeploymentStrategy) Contexts.getEventContext().get(StandardDeploymentStrategy.NAME); 
+            Object deploymentHandler = deploymentStrategy.getDeploymentHandlers().get(NAME);
+            if (deploymentHandler != null)
+            {
+               return (DotPageDotXmlDeploymentHandler) deploymentHandler;
+            }
+         }
+         return null;
+      }
+      else
+      {
+         throw new IllegalStateException("Event context not active");
+      }
+   }
+   
+   public static DotPageDotXmlDeploymentHandler hotInstance()
+   {
+      if (Contexts.isEventContextActive())
+      {
+         DeploymentStrategy deploymentStrategy = (DeploymentStrategy) Contexts.getEventContext().get(HotDeploymentStrategy.NAME);
+         if (deploymentStrategy != null)
+         {
+            Object deploymentHandler = deploymentStrategy.getDeploymentHandlers().get(NAME);
+            if (deploymentHandler != null)
+            {
+               return (DotPageDotXmlDeploymentHandler) deploymentHandler;
+            }
+         }
+         return null;
+      }
+      else
+      {
+         throw new IllegalStateException("Event context not active");
+      }
+   }
+   
+}


Property changes on: trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java	2008-08-18 20:58:19 UTC (rev 8731)
+++ trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -48,8 +48,6 @@
    
    private ClassLoader hotDeployClassLoader;
    
-   private File[] hotDeploymentPaths;
-   
    private ComponentDeploymentHandler componentDeploymentHandler;
    private AnnotationDeploymentHandler annotationDeploymentHandler;
    
@@ -65,6 +63,7 @@
       getDeploymentHandlers().put(ComponentDeploymentHandler.NAME, componentDeploymentHandler);
       annotationDeploymentHandler = new AnnotationDeploymentHandler(getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
       getDeploymentHandlers().put(AnnotationDeploymentHandler.NAME, annotationDeploymentHandler);
+      getDeploymentHandlers().put(DotPageDotXmlDeploymentHandler.NAME, new DotPageDotXmlDeploymentHandler());
    }
    
    private void initHotDeployClassLoader(ClassLoader classLoader, File hotDeployDirectory)
@@ -76,7 +75,7 @@
             URL url = hotDeployDirectory.toURL();
             URL[] urls = { url };
             hotDeployClassLoader = new URLClassLoader(urls, classLoader);
-            hotDeploymentPaths = new File[] { hotDeployDirectory };
+            getFiles().add(hotDeployDirectory);
          }
 
       }
@@ -97,7 +96,7 @@
     */
    public File[] getHotDeploymentPaths()
    {
-      return hotDeploymentPaths;
+      return getFiles().toArray(new File[0]);
    }
 
    /**
@@ -153,7 +152,7 @@
    @Override
    public void scan()
    {
-      getScanner().scanDirectories(getHotDeploymentPaths());
+      getScanner().scanDirectories(getFiles().toArray(new File[0]));
       
    }
    

Modified: trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java	2008-08-18 20:58:19 UTC (rev 8731)
+++ trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -1,5 +1,6 @@
 package org.jboss.seam.deployment;
 
+import java.io.File;
 import java.util.Map;
 import java.util.Set;
 
@@ -55,6 +56,7 @@
       getDeploymentHandlers().put(NamespaceDeploymentHandler.NAME, namespaceDeploymentHandler);
       annotationDeploymentHandler = new AnnotationDeploymentHandler(getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
       getDeploymentHandlers().put(AnnotationDeploymentHandler.NAME, annotationDeploymentHandler);
+      getDeploymentHandlers().put(DotPageDotXmlDeploymentHandler.NAME, new DotPageDotXmlDeploymentHandler());
    }
 
    @Override
@@ -102,6 +104,7 @@
    public void scan()
    {
       getScanner().scanResources(RESOURCE_NAMES);
+      getScanner().scanDirectories(getFiles().toArray(new File[0]));
    }
    
    public static StandardDeploymentStrategy instance()

Modified: trunk/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- trunk/src/main/org/jboss/seam/init/Initialization.java	2008-08-18 20:58:19 UTC (rev 8731)
+++ trunk/src/main/org/jboss/seam/init/Initialization.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -43,10 +43,12 @@
 import org.jboss.seam.core.Expressions;
 import org.jboss.seam.core.Init;
 import org.jboss.seam.core.PojoCache;
+import org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler;
 import org.jboss.seam.deployment.HotDeploymentStrategy;
 import org.jboss.seam.deployment.StandardDeploymentStrategy;
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
+import org.jboss.seam.navigation.Pages;
 import org.jboss.seam.util.Conversions;
 import org.jboss.seam.util.Naming;
 import org.jboss.seam.util.Reflections;
@@ -81,6 +83,9 @@
    private StandardDeploymentStrategy standardDeploymentStrategy;
    private HotDeploymentStrategy hotDeploymentStrategy;
    
+   private File warRootDirectory;
+   private File hotDeployDirectory;
+   
    private Set<String> nonPropertyAttributes = new HashSet<String>();
    
    {
@@ -98,11 +103,14 @@
    public Initialization(ServletContext servletContext)
    {
       this.servletContext = servletContext;
+      this.warRootDirectory = getRealFile(servletContext, "/");
+      this.hotDeployDirectory = getRealFile(servletContext, HotDeploymentStrategy.DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH);
    }
    
    public Initialization create()
    {
       standardDeploymentStrategy = new StandardDeploymentStrategy(Thread.currentThread().getContextClassLoader());
+      standardDeploymentStrategy.getFiles().add(warRootDirectory);
       standardDeploymentStrategy.scan();
       addNamespaces();
       initComponentsFromXmlDocument("/WEB-INF/components.xml");
@@ -597,7 +605,7 @@
       }
       ServletLifecycle.beginInitialization();
       Contexts.getApplicationContext().set(Component.PROPERTIES, properties);
-      scanForHotDeployableComponents();
+      createHotDeployment(Thread.currentThread().getContextClassLoader());
       scanForComponents();
       addComponent( new ComponentDescriptor(Init.class), Contexts.getApplicationContext());
       Init init = (Init) Component.getInstance(Init.class, ScopeType.APPLICATION);    
@@ -653,7 +661,11 @@
          Contexts.getApplicationContext().remove(name + COMPONENT_SUFFIX);
       }
       //TODO open the ability to reuse the classloader by looking at the components class classloaders
-      scanForHotDeployableComponents();
+      // Rescan
+      hotDeploymentStrategy.scan();
+      // And install
+      installHotDeployableComponents();
+      Pages.instance().setHotDotPageDotXmlFileNames(DotPageDotXmlDeploymentHandler.hotInstance().getFiles());
       init.setTimestamp( System.currentTimeMillis() );
       init.setHotDeployPaths(hotDeploymentStrategy.getHotDeploymentPaths());
       installComponents(init);
@@ -662,22 +674,16 @@
       return this;
    }
 
-   private void scanForHotDeployableComponents()
+   private void installHotDeployableComponents()
    {
-      createHotDeploymentStrategy(Thread.currentThread().getContextClassLoader());
-      if (hotDeploymentStrategy != null)
+      for (Class<Object> scannedClass: hotDeploymentStrategy.getScannedComponentClasses() )
       {
-         hotDeploymentStrategy.scan();
-         for (Class<Object> scannedClass: hotDeploymentStrategy.getScannedComponentClasses() )
-         {
-            installScannedComponentAndRoles(scannedClass);
-         }
+         installScannedComponentAndRoles(scannedClass);
       }
    }
    
-   private void createHotDeploymentStrategy(ClassLoader classLoader)
+   private void createHotDeployment(ClassLoader classLoader)
    {
-      File hotDeployDirectory = getHotDeployDirectory(servletContext);
       if ( isDebugEnabled() && hotDeployDirectory != null )
       {
          if (isGroovyPresent())
@@ -690,22 +696,28 @@
             log.debug("Using Java hot deploy");
             hotDeploymentStrategy = new HotDeploymentStrategy(classLoader, hotDeployDirectory);
          }
+         hotDeploymentStrategy.scan();
+         installHotDeployableComponents();
+
+         // Add the WAR root to the hot deploy path to pick up .page.xml
+         // We don't add it for the initial scan as StandardDeploymentStrategy deals with that
+         hotDeploymentStrategy.getFiles().add(warRootDirectory);
       }
    }
    
-   private static File getHotDeployDirectory(ServletContext servletContext)
+   private static File getRealFile(ServletContext servletContext, String path)
    {
-      String path = servletContext.getRealPath(HotDeploymentStrategy.DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH);
-      if (path==null) //WebLogic!
+      String realPath = servletContext.getRealPath(path);
+      if (realPath==null) //WebLogic!
       {
-         log.debug("Could not find path for " + HotDeploymentStrategy.DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH);
+         log.debug("Could not find path for " + path);
       }
       else
       {
-         File hotDeployDir = new File(path);
-         if (hotDeployDir.exists())
+         File file = new File(realPath);
+         if (file.exists())
          {
-            return hotDeployDir;
+            return file;
          }
       }
       return null;

Modified: trunk/src/main/org/jboss/seam/mock/MockServletContext.java
===================================================================
--- trunk/src/main/org/jboss/seam/mock/MockServletContext.java	2008-08-18 20:58:19 UTC (rev 8731)
+++ trunk/src/main/org/jboss/seam/mock/MockServletContext.java	2008-08-18 21:37:45 UTC (rev 8732)
@@ -50,6 +50,10 @@
             // call processing of context parameters
             processContextParameters(webxml);
          }
+         else
+         {
+            webappRoot = new File(getClass().getResource("/").toURI());
+         }
       }
       catch (URISyntaxException e)
       {
@@ -253,8 +257,7 @@
 
    public String getRealPath(String relativePath)
    {
-       // spec says to return null if we can't figure it out
-       return null;
+      return webappRoot.getAbsolutePath() + relativePath;
    }
 
    public String getServerInfo()




More information about the seam-commits mailing list