[seam-commits] Seam SVN: r9162 - trunk/src/main/org/jboss/seam/deployment.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Oct 1 11:58:12 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-10-01 11:58:12 -0400 (Wed, 01 Oct 2008)
New Revision: 9162

Added:
   trunk/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.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
Log:
Factor out the deployment properties reading code

Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java	2008-10-01 13:48:02 UTC (rev 9161)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java	2008-10-01 15:58:12 UTC (rev 9162)
@@ -1,21 +1,13 @@
 package org.jboss.seam.deployment;
 
-import static org.jboss.seam.util.Strings.split;
-
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 
-
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
 
@@ -49,87 +41,9 @@
    
    
    
-   /**
-    * The resource bundle used to control Seam deployment
-    */
-   public static final String RESOURCE_BUNDLE = "META-INF/seam-deployment.properties";
    
-   // All resource bundles to use, including legacy names
-   private static final String[] RESOURCE_BUNDLES = { RESOURCE_BUNDLE, "META-INF/seam-scanner.properties" };
    
    /**
-    * Get a list of possible values for a given key.
-    * 
-    * First, System properties are tried, followed by the specified resource
-    * bundle (first in classpath only).
-    * 
-    * Colon (:) deliminated lists are split out.
-    * 
-    */
-   protected List<String> getPropertyValues(String key)
-   {
-      List<String>values = new ArrayList<String>();
-      addPropertyFromSystem(key, values);
-      addPropertyFromResourceBundle(key, values);
-      return values;
-   }
-   
-   private void addPropertyFromSystem(String key, List<String> values)
-   {
-      addProperty(key, System.getProperty(key), values);
-   }
-   
-   private void addPropertyFromResourceBundle(String key, List<String> values)
-   {
-      for (String resourceName : RESOURCE_BUNDLES)
-      {        
-         try
-         {
-            // Hard to cache as we have to get it off the correct classloader
-            Enumeration<URL> urlEnum = getClassLoader().getResources(resourceName);
-            while ( urlEnum.hasMoreElements() )
-            {
-               URL url = urlEnum.nextElement();
-               Properties properties = new Properties();
-               InputStream propertyStream = url.openStream();
-               try
-               {
-                  properties.load(propertyStream);
-                  addProperty(key, properties.getProperty(key), values);
-               }
-               finally
-               {
-                  if (propertyStream != null)
-                  {
-                     propertyStream.close();
-                  }
-               }
-            }
-         }
-         catch (IOException e)
-         {
-            // No-op, optional file
-         }
-      }
-   }
-   
-   /*
-    * Add the property to the set of properties only if it hasn't already been added
-    */
-   private void addProperty(String key, String value, List<String> values)
-   {
-      if (value != null)
-      {
-         String[] properties = split(value, ":");
-         for (String property : properties)
-         {
-            values.add(property);
-         }
-         
-      }
-   }
-   
-   /**
     * Do the scan for resources
     * 
     * Should only be called by Seam
@@ -173,7 +87,8 @@
    private void initDeploymentHandlers()
    {
       this.deploymentHandlers = new HashMap<String, DeploymentHandler>();
-      addHandlers(getPropertyValues(getDeploymentHandlersKey()));
+      List<String> deploymentHandlersClassNames = new SeamDeploymentProperties(getClassLoader()).getPropertyValues(getDeploymentHandlersKey());
+      addHandlers(deploymentHandlersClassNames);
    }
 
    protected abstract String getDeploymentHandlersKey();
@@ -193,7 +108,7 @@
       
    private void initScanner()
    {
-      List<String> scanners = getPropertyValues(SCANNERS_KEY);
+      List<String> scanners = new SeamDeploymentProperties(getClassLoader()).getPropertyValues(SCANNERS_KEY);
       for ( String className : scanners )
       {
          Scanner scanner = instantiateScanner(className);

Modified: trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java	2008-10-01 13:48:02 UTC (rev 9161)
+++ trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java	2008-10-01 15:58:12 UTC (rev 9162)
@@ -50,8 +50,6 @@
    
    private ComponentDeploymentHandler componentDeploymentHandler;
    private AnnotationDeploymentHandler annotationDeploymentHandler;
-   
-   private long timestamp = 0L;
 
    private ClassLoader classLoader;
    
@@ -70,7 +68,7 @@
             initHotDeployClassLoader(classLoader, hotDeployDirectory);
             componentDeploymentHandler = new ComponentDeploymentHandler();
             getDeploymentHandlers().put(ComponentDeploymentHandler.NAME, componentDeploymentHandler);
-            annotationDeploymentHandler = new AnnotationDeploymentHandler(getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
+            annotationDeploymentHandler = new AnnotationDeploymentHandler(new SeamDeploymentProperties(classLoader).getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
             getDeploymentHandlers().put(AnnotationDeploymentHandler.NAME, annotationDeploymentHandler);
          }
          getDeploymentHandlers().put(DotPageDotXmlDeploymentHandler.NAME, new DotPageDotXmlDeploymentHandler());

Added: trunk/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java	2008-10-01 15:58:12 UTC (rev 9162)
@@ -0,0 +1,116 @@
+package org.jboss.seam.deployment;
+
+import static org.jboss.seam.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.seam.util.EnumerationEnumeration;
+
+public class SeamDeploymentProperties
+{
+   
+   private ClassLoader classLoader;
+   private Enumeration<URL> urlEnum;
+   
+   public SeamDeploymentProperties(ClassLoader classLoader)
+   {
+      this.classLoader = classLoader;
+   }
+
+   /**
+    * The resource bundle used to control Seam deployment
+    */
+   public static final String RESOURCE_BUNDLE = "META-INF/seam-deployment.properties";
+   
+   // All resource bundles to use, including legacy names
+   private static final String[] RESOURCE_BUNDLES = { RESOURCE_BUNDLE, "META-INF/seam-scanner.properties" };
+   
+   /**
+    * Get a list of possible values for a given key.
+    * 
+    * First, System properties are tried, followed by the specified resource
+    * bundle (first in classpath only).
+    * 
+    * Colon (:) deliminated lists are split out.
+    * 
+    */
+   public List<String> getPropertyValues(String key)
+   {
+      List<String>values = new ArrayList<String>();
+      addPropertiesFromSystem(key, values);
+      addPropertiesFromResourceBundle(key, values);
+      return values;
+   }
+   
+   private void addPropertiesFromSystem(String key, List<String> values)
+   {
+      addProperty(key, System.getProperty(key), values);
+   }
+   
+   private void addPropertiesFromResourceBundle(String key, List<String> values)
+   {
+      try
+      {  
+         while ( getResources().hasMoreElements() )
+         {
+            URL url = getResources().nextElement();
+            Properties properties = new Properties();
+            InputStream propertyStream = url.openStream();
+            try
+            {
+               properties.load(propertyStream);
+               addProperty(key, properties.getProperty(key), values);
+            }
+            finally
+            {
+               if (propertyStream != null)
+               {
+                  propertyStream.close();
+               }
+            }
+         }
+      }
+      catch (IOException e) 
+      {
+         // No - op, file is optional
+      }
+   }
+   
+   /*
+    * Add the property to the set of properties only if it hasn't already been added
+    */
+   private void addProperty(String key, String value, List<String> values)
+   {
+      if (value != null)
+      {
+         String[] properties = split(value, ":");
+         for (String property : properties)
+         {
+            values.add(property);
+         }
+         
+      }
+   }
+   
+   private Enumeration<URL> getResources() throws IOException
+   {
+      
+      if (urlEnum == null)
+      {
+         Enumeration<URL>[] enumerations = new Enumeration[RESOURCE_BUNDLES.length]; 
+         for (int i = 0; i < RESOURCE_BUNDLES.length; i ++)
+         {   
+            enumerations[i] = classLoader.getResources(RESOURCE_BUNDLES[i]);
+         }
+         urlEnum = new EnumerationEnumeration<URL>(enumerations);
+      }
+      return urlEnum;
+   }
+   
+}


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

Modified: trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java	2008-10-01 13:48:02 UTC (rev 9161)
+++ trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java	2008-10-01 15:58:12 UTC (rev 9162)
@@ -54,7 +54,7 @@
       getDeploymentHandlers().put(ComponentsXmlDeploymentHandler.NAME, componentsXmlDeploymentHandler);
       namespaceDeploymentHandler = new NamespaceDeploymentHandler();
       getDeploymentHandlers().put(NamespaceDeploymentHandler.NAME, namespaceDeploymentHandler);
-      annotationDeploymentHandler = new AnnotationDeploymentHandler(getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
+      annotationDeploymentHandler = new AnnotationDeploymentHandler(new SeamDeploymentProperties(classLoader).getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY), classLoader);
       getDeploymentHandlers().put(AnnotationDeploymentHandler.NAME, annotationDeploymentHandler);
    }
 




More information about the seam-commits mailing list