portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r643141 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/ components/jetspeed-portal/src/main/java/org/apache/jet...
Date Mon, 31 Mar 2008 20:42:06 GMT
Author: ate
Date: Mon Mar 31 13:42:02 2008
New Revision: 643141

URL: http://svn.apache.org/viewvc?rev=643141&view=rev
Log:
Many changes how to instatiate a Jetspeed Spring container: everything is now handled by the
SpringComponentManager.
This new SpringComponentManager replaces all standalone Spring application context instantiations
(like for test cases and utilities/tools).
Among things, it now ensures:
- the new Spring assembly filtering is enabled (if provided with a filter that is)
- proper (re)starting and stopping of the container
- providing the context with boot level properties (like ${applicationRoot}) without needing
to (mis)use global scoped System.setProperty(<property>) calls
  (well, that's now delegated to the extended and filtering Spring ApplicationContext implementations)

Note: this commit will break many testcases, all of which I already have fixed/updated locally
and will commit (together with several other improvements) shortly.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/registration/RegistrationTool.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java?rev=643141&r1=643140&r2=643141&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
Mon Mar 31 13:42:02 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.components;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -27,23 +26,18 @@
 import javax.servlet.ServletContext;
 
 import org.apache.jetspeed.engine.JetspeedEngineConstants;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.XmlWebApplicationContext;
 
 /**
  * <p>
  * SpringComponentManager
  * </p>
- * <p>
- * 
- * </p>
  * 
  * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
  * @version $Id$
  * 
  */
@@ -59,27 +53,30 @@
 
     private boolean started = false;
 
-    public SpringComponentManager(String[] bootConfigs, String[] appConfigs, ServletContext
servletContext,
+    public SpringComponentManager(JetspeedBeanDefinitionFilter filter, String[] bootConfigs,
String[] appConfigs, ServletContext servletContext,
             String appRoot)
     {
-        File appRootDir = new File(appRoot);
-        System.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, appRootDir.getAbsolutePath());
+        this(filter, bootConfigs, appConfigs, servletContext, appRoot, null);
+    }
 
+    public SpringComponentManager(JetspeedBeanDefinitionFilter filter, String[] bootConfigs,
String[] appConfigs, ServletContext servletContext,
+            String appRoot, Properties bootProperties)
+    {
+        if (bootProperties == null)
+        {
+            bootProperties = new Properties();
+        }
+        bootProperties.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, appRoot);
+        
         if (bootConfigs != null && bootConfigs.length > 0)
         {
-            bootCtx = new XmlWebApplicationContext();
-            ((XmlWebApplicationContext) bootCtx).setServletContext(servletContext);
-            ((XmlWebApplicationContext) bootCtx).setConfigLocations(bootConfigs);
+            bootCtx = new FilteringXmlWebApplicationContext(filter, bootConfigs, bootProperties,
servletContext);
         }
         else
         {
-            bootCtx = new GenericApplicationContext();
+            bootCtx = new FileSystemXmlApplicationContext();
         }
-
-        appContext = new XmlWebApplicationContext();
-        ((XmlWebApplicationContext) appContext).setParent(bootCtx);
-        ((XmlWebApplicationContext) appContext).setServletContext(servletContext);
-        ((XmlWebApplicationContext) appContext).setConfigLocations(appConfigs);
+        appContext = new FilteringXmlWebApplicationContext(filter, appConfigs, bootProperties,
servletContext, bootCtx);
 
         factories = new ArrayList();
         factories.add(appContext);
@@ -87,38 +84,45 @@
         servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
appContext);
     }
 
-    public SpringComponentManager(String[] bootConfigs, String[] appConfigs, ServletContext
servletContext,
-            String appRoot, Map preconfiguredBeans)
-    {
-        this(bootConfigs, appConfigs, servletContext, appRoot);
-        this.preconfiguredBeans = preconfiguredBeans;
+    public SpringComponentManager(JetspeedBeanDefinitionFilter filter, String[] bootConfigs,
String[] appConfigs, String appRoot, boolean fileSystem)
+    {        
+        this(filter, bootConfigs, appConfigs, appRoot, null, fileSystem);
     }
-
     
-    public SpringComponentManager(String[] bootConfigs, String[] appConfigs, String appRoot)
+    public SpringComponentManager(JetspeedBeanDefinitionFilter filter, String[] bootConfigs,
String[] appConfigs, String appRoot, Properties bootProperties, boolean fileSystem)
     {        
-        PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
-        Properties p = new Properties();
-        //p.setProperty(APPLICATION_ROOT_KEY,appRootDir.getAbsolutePath());
-        ppc.setProperties(p);
+        if (bootProperties == null)
+        {
+            bootProperties = new Properties();
+        }
+        bootProperties.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, appRoot);
         
         if (bootConfigs != null && bootConfigs.length > 0)
         {
-            bootCtx = new FileSystemXmlApplicationContext(bootConfigs, false);
-            bootCtx.addBeanFactoryPostProcessor(ppc);
-            bootCtx.refresh();
+            if (fileSystem)
+            {
+                bootCtx = new FilteringFileSystemXmlApplicationContext(filter, bootConfigs,
bootProperties);
+            }
+            else
+            {
+                bootCtx = new FilteringClassPathXmlApplicationContext(filter, bootConfigs,
bootProperties);
+            }
         }
         else
         {
-            bootCtx = new GenericApplicationContext();
+            bootCtx = new FileSystemXmlApplicationContext();
         }
-
-        appContext = new FileSystemXmlApplicationContext(appConfigs, false, bootCtx);
-        appContext.addBeanFactoryPostProcessor(ppc);
-        appContext.refresh();
-        factories = new ArrayList();
-        factories.add(appContext);
         
+        if (fileSystem)
+        {
+            appContext = new FilteringFileSystemXmlApplicationContext(filter, appConfigs,
bootProperties, bootCtx);
+        }
+        else
+        {
+            appContext = new FilteringClassPathXmlApplicationContext(filter, appConfigs,
bootProperties, bootCtx);
+        }
+        factories = new ArrayList();
+        factories.add(appContext);        
     }
     
     /**
@@ -248,5 +252,4 @@
         appContext.refresh();
         started = true;
     }
-
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java?rev=643141&r1=643140&r2=643141&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
Mon Mar 31 13:42:02 2008
@@ -316,7 +316,7 @@
         String[] bootConfigs = new String[] {"/WEB-INF/assembly/boot/*.xml"};
         String[] appConfigs =  new String[] {assemblyDir+"/*"+assemblyFileExtension, assemblyDir+"/override/*"+assemblyFileExtension};
         ServletContext servletContext = servletConfig.getServletContext();
-        SpringComponentManager cm = new SpringComponentManager(bootConfigs, appConfigs, servletContext,
appRoot);      
+        SpringComponentManager cm = new SpringComponentManager(null, bootConfigs, appConfigs,
servletContext, appRoot);      
         
         return cm;        
     }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/registration/RegistrationTool.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/registration/RegistrationTool.java?rev=643141&r1=643140&r2=643141&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/registration/RegistrationTool.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/registration/RegistrationTool.java
Mon Mar 31 13:42:02 2008
@@ -20,16 +20,14 @@
 import java.io.FileReader;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.jetspeed.components.SpringComponentManager;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
-import org.apache.jetspeed.engine.JetspeedEngineConstants;
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
 import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
 import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata;
 import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor;
 import org.apache.jetspeed.util.descriptor.WebApplicationDescriptor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * <p>
@@ -54,21 +52,12 @@
         try
         {
             File appRootDir = new File("./src/webapp");            
-            System.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, appRootDir.getAbsolutePath());
           
             configuration.load(fileName);        
             String [] bootAssemblies = configuration.getStringArray("boot.assemblies");
-            String [] assemblies = configuration.getStringArray("assemblies");          
 
-            ClassPathXmlApplicationContext ctx;            
-            
-            if (bootAssemblies != null)
-            {
-                ApplicationContext bootContext = new ClassPathXmlApplicationContext(bootAssemblies,
true);
-                ctx = new ClassPathXmlApplicationContext(assemblies, true, bootContext);
-            }
-            else
-            {
-                ctx = new ClassPathXmlApplicationContext(assemblies, true);
-            }
+            String [] assemblies = configuration.getStringArray("assemblies");      
+            SpringComponentManager scm = new SpringComponentManager(null, bootAssemblies,
assemblies, appRootDir.getAbsolutePath(), false);
+
+            scm.start();
             
             boolean overwriteApps = configuration.getBoolean("overwrite.apps", true);
             String registryBean = configuration.getString("registry.component", "");
@@ -76,7 +65,7 @@
             String[] appDescriptors = configuration.getStringArray("descriptors");
             String[] webappDescriptors = configuration.getStringArray("webapp.descriptors");
             String[] extendedDescriptors = configuration.getStringArray("extended.descriptors");
-            PortletRegistry registry = (PortletRegistry)ctx.getBean(registryBean);
+            PortletRegistry registry = (PortletRegistry)scm.getComponent(registryBean);
             RegistrationTool tool = new RegistrationTool(registry, overwriteApps);
             
             for (int ix=0; ix < appNames.length; ix++)

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml?rev=643141&r1=643140&r2=643141&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
Mon Mar 31 13:42:02 2008
@@ -181,6 +181,9 @@
                 <value>file:///${applicationRoot}/WEB-INF/conf/override.properties</value>
             </list>
         </property>
+        <property name="properties">
+          <value>applicationRoot=${applicationRoot}</value>
+        </property>
     </bean>
 
     <!-- HeaderResource Factory -->



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message