cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r470825 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring: AbstractElementParser.java SettingsElementParser.java
Date Fri, 03 Nov 2006 14:01:21 GMT
Author: lgawron
Date: Fri Nov  3 06:01:20 2006
New Revision: 470825

URL: http://svn.apache.org/viewvc?view=rev&rev=470825
Log:
import sprint context files directly from classpath (no need for cocoon deployer here)

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java?view=diff&rev=470825&r1=470824&r2=470825
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
Fri Nov  3 06:01:20 2006
@@ -38,10 +38,11 @@
 import org.w3c.dom.Element;
 
 /**
- * This is a base class for all bean definition parser used in Cocoon.
- * It provides some utility methods.
- *
- * @version $Id$
+ * This is a base class for all bean definition parser used in Cocoon. It
+ * provides some utility methods.
+ * 
+ * @version $Id: AbstractElementParser.java 463297 2006-10-12 16:03:45Z
+ *          cziegeler $
  * @since 2.2
  */
 public abstract class AbstractElementParser implements BeanDefinitionParser {
@@ -49,16 +50,14 @@
     /** Logger (we use the same logging mechanism as Spring!) */
     protected final Log logger = LogFactory.getLog(getClass());
 
-    /** Get the value of an attribute or if the attribute is not present
-     * return the default value.
-     * For any strange reason, getAttribute() does not return null if the
-     * attribute is not present but an empty string!
-     */
-    protected String getAttributeValue(Element element,
-                                       String  attributeName,
-                                       String  defaultValue) {
+    /**
+     * Get the value of an attribute or if the attribute is not present return
+     * the default value. For any strange reason, getAttribute() does not return
+     * null if the attribute is not present but an empty string!
+     */
+    protected String getAttributeValue(Element element, String attributeName, String defaultValue)
{
         String value = element.getAttribute(attributeName);
-        if ( value == null || value.trim().length() == 0 ) {
+        if (value == null || value.trim().length() == 0) {
             value = defaultValue;
         }
         return value;
@@ -66,35 +65,38 @@
 
     /**
      * Register a bean definition.
-     * @param beanDef  The bean definition.
-     * @param beanName The name of the bean.
-     * @param registry The registry.
-     */
-    protected void register(BeanDefinition beanDef,
-                            String         beanName,
-                            BeanDefinitionRegistry registry) {
+     * 
+     * @param beanDef
+     *            The bean definition.
+     * @param beanName
+     *            The name of the bean.
+     * @param registry
+     *            The registry.
+     */
+    protected void register(BeanDefinition beanDef, String beanName, BeanDefinitionRegistry
registry) {
         this.register(beanDef, beanName, null, registry);
     }
 
     /**
      * Register a bean definition.
-     * @param beanDef  The bean definition.
-     * @param beanName The name of the bean.
-     * @param alias    Optional alias.
-     * @param registry The registry.
-     */
-    protected void register(BeanDefinition beanDef,
-                            String         beanName,
-                            String         alias,
-                            BeanDefinitionRegistry registry) {
-        if ( this.logger.isDebugEnabled() ) {
-            this.logger.debug("Registering bean with name " + beanName +
-                              (alias != null ? " (alias=" + alias + ") " : " ") +
-                              beanDef);
+     * 
+     * @param beanDef
+     *            The bean definition.
+     * @param beanName
+     *            The name of the bean.
+     * @param alias
+     *            Optional alias.
+     * @param registry
+     *            The registry.
+     */
+    protected void register(BeanDefinition beanDef, String beanName, String alias, BeanDefinitionRegistry
registry) {
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug("Registering bean with name " + beanName
+                    + (alias != null ? " (alias=" + alias + ") " : " ") + beanDef);
         }
         final BeanDefinitionHolder holder;
-        if ( alias != null ) {
-            holder = new BeanDefinitionHolder(beanDef, beanName, new String[] {alias});
+        if (alias != null) {
+            holder = new BeanDefinitionHolder(beanDef, beanName, new String[] { alias });
         } else {
             holder = new BeanDefinitionHolder(beanDef, beanName);
         }
@@ -103,22 +105,25 @@
 
     /**
      * Helper method to create a new bean definition.
-     * @param componentClass    The class of the implementation.
-     * @param initMethod        Optional initialization method.
-     * @param requiresSettings  If set to true, this bean has a property "settings" for the
settings object.
+     * 
+     * @param componentClass
+     *            The class of the implementation.
+     * @param initMethod
+     *            Optional initialization method.
+     * @param requiresSettings
+     *            If set to true, this bean has a property "settings" for the
+     *            settings object.
      * @return A new root bean definition.
      */
-    protected RootBeanDefinition createBeanDefinition(Class   componentClass,
-                                                      String  initMethod,
-                                                      boolean requiresSettings) {
+    protected RootBeanDefinition createBeanDefinition(Class componentClass, String initMethod,
boolean requiresSettings) {
         final RootBeanDefinition beanDef = new RootBeanDefinition();
-        beanDef.setBeanClass(componentClass);      
+        beanDef.setBeanClass(componentClass);
         beanDef.setSingleton(true);
         beanDef.setLazyInit(false);
-        if ( initMethod != null ) {
+        if (initMethod != null) {
             beanDef.setInitMethodName(initMethod);
         }
-        if ( requiresSettings ) {
+        if (requiresSettings) {
             beanDef.getPropertyValues().addPropertyValue("settings", new RuntimeBeanReference(Settings.ROLE));
         }
         return beanDef;
@@ -126,22 +131,25 @@
 
     /**
      * Helper method to create a new bean definition.
-     * @param componentClass    The class of the implementation.
-     * @param initMethod        Optional initialization method.
-     * @param requiresSettings  If set to true, this bean has a property "settings" for the
settings object.
+     * 
+     * @param componentClass
+     *            The class of the implementation.
+     * @param initMethod
+     *            Optional initialization method.
+     * @param requiresSettings
+     *            If set to true, this bean has a property "settings" for the
+     *            settings object.
      * @return A new root bean definition.
      */
-    protected RootBeanDefinition createBeanDefinition(String   componentClass,
-                                                      String  initMethod,
-                                                      boolean requiresSettings) {
+    protected RootBeanDefinition createBeanDefinition(String componentClass, String initMethod,
boolean requiresSettings) {
         final RootBeanDefinition beanDef = new RootBeanDefinition();
-        beanDef.setBeanClassName(componentClass);      
+        beanDef.setBeanClassName(componentClass);
         beanDef.setSingleton(true);
         beanDef.setLazyInit(false);
-        if ( initMethod != null ) {
+        if (initMethod != null) {
             beanDef.setInitMethodName(initMethod);
         }
-        if ( requiresSettings ) {
+        if (requiresSettings) {
             beanDef.getPropertyValues().addPropertyValue("settings", new RuntimeBeanReference(Settings.ROLE));
         }
         return beanDef;
@@ -149,17 +157,21 @@
 
     /**
      * Add a new bean definition to the registry.
-     * @param componentClass    The class of the implementation.
-     * @param beanName          The name of the bean.
-     * @param initMethod        Optional initialization method.
-     * @param requiresSettings  If set to true, this bean has a property "settings" for the
settings object.
-     * @param registry          The bean registry.
-     */
-    protected void addComponent(Class                  componentClass,
-                                String                 beanName,
-                                String                 initMethod,
-                                boolean                requiresSettings,
-                                BeanDefinitionRegistry registry) {
+     * 
+     * @param componentClass
+     *            The class of the implementation.
+     * @param beanName
+     *            The name of the bean.
+     * @param initMethod
+     *            Optional initialization method.
+     * @param requiresSettings
+     *            If set to true, this bean has a property "settings" for the
+     *            settings object.
+     * @param registry
+     *            The bean registry.
+     */
+    protected void addComponent(Class componentClass, String beanName, String initMethod,
boolean requiresSettings,
+            BeanDefinitionRegistry registry) {
         final RootBeanDefinition beanDef = this.createBeanDefinition(componentClass, initMethod,
requiresSettings);
 
         this.register(beanDef, beanName, registry);
@@ -167,17 +179,21 @@
 
     /**
      * Add a new bean definition to the registry.
-     * @param componentClass    The class of the implementation.
-     * @param beanName          The name of the bean.
-     * @param initMethod        Optional initialization method.
-     * @param requiresSettings  If set to true, this bean has a property "settings" for the
settings object.
-     * @param registry          The bean registry.
-     */
-    protected void addComponent(String                 componentClass,
-                                String                 beanName,
-                                String                 initMethod,
-                                boolean                requiresSettings,
-                                BeanDefinitionRegistry registry) {
+     * 
+     * @param componentClass
+     *            The class of the implementation.
+     * @param beanName
+     *            The name of the bean.
+     * @param initMethod
+     *            Optional initialization method.
+     * @param requiresSettings
+     *            If set to true, this bean has a property "settings" for the
+     *            settings object.
+     * @param registry
+     *            The bean registry.
+     */
+    protected void addComponent(String componentClass, String beanName, String initMethod,
boolean requiresSettings,
+            BeanDefinitionRegistry registry) {
         final RootBeanDefinition beanDef = this.createBeanDefinition(componentClass, initMethod,
requiresSettings);
 
         this.register(beanDef, beanName, registry);
@@ -185,23 +201,21 @@
 
     /**
      * Handle include for spring bean configurations.
+     * 
      * @throws ConfigurationException
      */
-    protected void handleBeanInclude(ParserContext parserContext,
-                                     String        src,
-                                     String        dir,
-                                     String        pattern,
-                                     boolean       optional)
-    throws Exception {
+    protected void handleBeanInclude(ParserContext parserContext, String src, String path,
String pattern,
+            boolean optional) throws Exception {
         final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
         ServletContextResourcePatternResolver resolver = new ServletContextResourcePatternResolver(resourceLoader);
+
         final String includeURI = src;
-        String directoryURI = null;
+        String pathURI = null;
         if (includeURI == null) {
             // check for directories
-            directoryURI = dir;
+            pathURI = path;
         }
-        if (includeURI == null && directoryURI == null) {
+        if (includeURI == null && pathURI == null) {
             throw new Exception("Include statement must either have a 'src' or 'dir' attribute.");
         }
 
@@ -209,52 +223,42 @@
             Resource rsrc = null;
             try {
                 rsrc = resourceLoader.getResource(includeURI);
-
                 this.handleImport(parserContext, rsrc.getURL().toExternalForm());
             } catch (Exception e) {
                 throw new Exception("Cannot load '" + includeURI + "'.", e);
             }
 
         } else {
-            // test if directory exists
-            Resource dirResource = resourceLoader.getResource(directoryURI);
-            if ( dirResource.exists() ) {
-                try {
-                    Resource[] resources = resolver.getResources(directoryURI + '/' + pattern);
-                    if ( resources != null ) {
-                        Arrays.sort(resources, ResourceUtils.getResourceComparator());
-                        for(int i=0; i < resources.length; i++) {
-                            this.handleImport(parserContext, resources[i].getURL().toExternalForm());
-                        }
-                    }
-                } catch (IOException ioe) {
-                    throw new Exception("Unable to read configurations from " + directoryURI);
-                }
-            } else {
-                if ( !optional ) {
-                    throw new Exception("Directory '" + directoryURI + "' does not exist.");
+            try {
+                Resource[] resources = resolver.getResources(pathURI + '/' + pattern);
+                Arrays.sort(resources, ResourceUtils.getResourceComparator());
+                for (int i = 0; i < resources.length; i++) {
+                    this.handleImport(parserContext, resources[i].getURL().toExternalForm());
                 }
+            } catch (IOException ioe) {
+                throw new Exception("Unable to read configurations from " + pathURI);
             }
         }
     }
 
     protected void handleImport(ParserContext parserContext, String uri) {
         final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
-        parserContext.getDelegate().getReaderContext().getReader().loadBeanDefinitions(resourceLoader.getResource(uri));
       
+        parserContext.getDelegate().getReaderContext().getReader().loadBeanDefinitions(resourceLoader.getResource(uri));
     }
 
     /**
-     * Register a property placeholder configurer.
-     * The configurer will read all *.properties files from the specified location.
+     * Register a property placeholder configurer. The configurer will read all
+     * *.properties files from the specified location.
+     * 
      * @param parserContext
      * @param springConfigLocation
      */
     protected void registerPropertyPlaceholderConfigurer(final ParserContext parserContext,
final String location) {
         final RootBeanDefinition beanDef = this.createBeanDefinition(CocoonPropertyOverrideConfigurer.class.getName(),
-                null,
-                false);
+                null, true);
         beanDef.getPropertyValues().addPropertyValue("location", location);
-        beanDef.getPropertyValues().addPropertyValue("resourceLoader",  parserContext.getReaderContext().getReader().getResourceLoader());
+        beanDef.getPropertyValues().addPropertyValue("resourceLoader",
+                parserContext.getReaderContext().getReader().getResourceLoader());
         beanDef.getPropertyValues().addPropertyValue("beanNameSeparator", "/");
         this.register(beanDef, CocoonPropertyOverrideConfigurer.class.getName(), parserContext.getRegistry());
     }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java?view=diff&rev=470825&r1=470824&r2=470825
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
Fri Nov  3 06:01:20 2006
@@ -29,32 +29,39 @@
 
 /**
  * Add a bean definition for the settings object to the bean factory.
- *
+ * 
  * @see CocoonNamespaceHandler
  * @see SettingsBeanFactoryPostProcessor
- * @version $Id$
+ * @version $Id: SettingsElementParser.java 470732 2006-11-03 09:10:13Z
+ *          cziegeler $
  * @since 2.2
  */
 public class SettingsElementParser extends AbstractElementParser {
 
-    /** The name of the configuration attribute to use a different processor class. */
+    /**
+     * The name of the configuration attribute to use a different processor
+     * class.
+     */
     public static final String PROCESSOR_CLASS_NAME_ATTR = "processorClassName";
 
     /** The name of the configuration attribute to specify the running mode. */
     public static final String RUNNING_MODE_ATTR = "runningMode";
 
     /**
-     * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
org.springframework.beans.factory.xml.ParserContext)
+     * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
+     *      org.springframework.beans.factory.xml.ParserContext)
      */
     public BeanDefinition parse(Element element, ParserContext parserContext) {
-        final String springConfigLocation = this.getAttributeValue(element, "location", Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION);
+        final String springConfigLocation = this.getAttributeValue(element, "location",
+                Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION);
 
         // create bean definition for settings object
-        final String componentClassName = this.getAttributeValue(element, PROCESSOR_CLASS_NAME_ATTR,
SettingsBeanFactoryPostProcessor.class.getName());
+        final String componentClassName = this.getAttributeValue(element, PROCESSOR_CLASS_NAME_ATTR,
+                SettingsBeanFactoryPostProcessor.class.getName());
         final RootBeanDefinition beanDef = this.createBeanDefinition(componentClassName,
"init", false);
         // if running mode is specified add it as a property
         final String runningMode = this.getAttributeValue(element, RUNNING_MODE_ATTR, null);
-        if ( runningMode != null ) {
+        if (runningMode != null) {
             beanDef.getPropertyValues().addPropertyValue("runningMode", runningMode);
         }
         // register settings bean
@@ -64,14 +71,21 @@
         this.registerPropertyPlaceholderConfigurer(parserContext, springConfigLocation);
 
         // add the servlet context as a bean
-        this.addComponent(ServletContextFactoryBean.class.getName(), ServletContext.class.getName(),
null, false, parserContext.getRegistry());
+        this.addComponent(ServletContextFactoryBean.class.getName(), ServletContext.class.getName(),
null, false,
+                parserContext.getRegistry());
 
         // handle includes
+        String classPathLocation = "classpath*:META-INF/cocoon/spring";
+        try {
+            this.handleBeanInclude(parserContext, null, classPathLocation, "*.xml", true);
+        } catch (Exception e) {
+            throw new BeanDefinitionStoreException("Unable to read spring configurations
from " + classPathLocation, e);
+        }
         try {
-            this.handleBeanInclude(parserContext, null, "classpath*:/META-INF/cocoon/spring",
"*.xml", true);
             this.handleBeanInclude(parserContext, null, springConfigLocation, "*.xml", true);
         } catch (Exception e) {
-            throw new BeanDefinitionStoreException("Unable to read spring configurations
from " + springConfigLocation, e);
+            throw new BeanDefinitionStoreException("Unable to read spring configurations
from " + springConfigLocation,
+                    e);
         }
         return null;
     }



Mime
View raw message