-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Leszek Gawron schrieb:
> Leszek Gawron wrote:
>> Felix Knecht wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>
>>> Giacomo Pati schrieb:
>>>>
>>>> Leszek Gawron wrote:
>>>>> with cocoon modes enabled for spring you can do something
>>>>> like this:
>>> I always get the error: Embedded error: Cannot invoke listener
>>> [EMAIL PROTECTED] No
>>> bean named 'myDao' is defined
>>>
>>> Putting the 'myDao' bean definition into the myContext.xml it
>>> works. Maybe I need to enable cocoon modes for spring, but
>>> where do I enable cocoon modes for spring?
>>
>> Let me test that...
> This is another question to Carsten (SettingsElementParser):
>
>> public BeanDefinition parse(Element element, ParserContext
>> parserContext) { 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
>> 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) {
>> beanDef.getPropertyValues().addPropertyValue("runningMode",
>> runningMode); }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This
> code does not take into consideration the fact that cocoon running
> mode may be passed using system property

Attached path.txt will take consideration of this fact.

>
>> // register settings bean this.register(beanDef, Settings.ROLE,
>> parserContext.getRegistry());
>>
>> // register a PropertyPlaceholderConfigurer
>> this.registerPropertyOverrideConfigurer(parserContext,
>> springConfigLocation);
>>
>> // add the servlet context as a bean
>> this.addComponent(ServletContextFactoryBean.class.getName(),
>> ServletContext.class.getName(), null, false,
>> parserContext.getRegistry());
>>
>> // handle includes try { this.handleBeanInclude(parserContext,
>> null, Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION, "*.xml",
>> true); this.handleBeanInclude(parserContext, null,
>> Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION + "/" +
>> runningMode, "*.xml", true);
>
> when running mode is set with system property the runningMode
> variable is null here.
>
>> } catch (Exception e) { throw new
>> BeanDefinitionStoreException("Unable to read spring
>> configurations from " +
>> Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION, e); } return
>> null; }
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFTzmF2lZVCB08qHERAvx6AKChw/2wHZw8UFIJWBhbrhHOwXF7CACdGGrI
4hf6llnM16ZDlKROdeN1cgs=
=uyI8
-----END PGP SIGNATURE-----

Index: 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
===================================================================
--- 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
   (revision 471715)
+++ 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
   (working copy)
@@ -60,7 +60,7 @@
                 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);
+        final String runningMode = 
getSystemProperty(Settings.PROPERTY_RUNNING_MODE, 
this.getAttributeValue(element, RUNNING_MODE_ATTR, null) );
         if (runningMode != null) {
             beanDef.getPropertyValues().addPropertyValue("runningMode", 
runningMode);
         }
Index: 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
===================================================================
--- 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
    (revision 471715)
+++ 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
    (working copy)
@@ -119,7 +119,7 @@
      * @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 runningMode = this.getAttributeValue(element, 
SettingsElementParser.RUNNING_MODE_ATTR, SettingsDefaults.DEFAULT_RUNNING_MODE);
+        final String runningMode = 
getSystemProperty(Settings.PROPERTY_RUNNING_MODE, 
this.getAttributeValue(element, SettingsElementParser.RUNNING_MODE_ATTR, 
SettingsDefaults.DEFAULT_RUNNING_MODE) );
         final String location = element.getAttribute("location");
         final ResourceLoader resourceLoader = 
parserContext.getReaderContext().getReader().getResourceLoader();
         try {
Index: 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
===================================================================
--- 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
   (revision 471715)
+++ 
core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractElementParser.java
   (working copy)
@@ -281,4 +281,17 @@
         this.register(beanDef, 
CocoonPropertyOverrideConfigurer.class.getName(), parserContext.getRegistry());
     }
 
+   protected String getSystemProperty(String key) {
+        return this.getSystemProperty(key, null);
+    }
+
+    protected String getSystemProperty(String key, String defaultValue) {
+        try {
+            return System.getProperty(key, defaultValue);
+        } catch (SecurityException se) {
+            // we ignore this
+            return defaultValue;
+        }
+    }
+
 }

Reply via email to