You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2007/05/21 15:52:43 UTC

svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Author: giacomo
Date: Mon May 21 06:52:41 2007
New Revision: 540144

URL: http://svn.apache.org/viewvc?view=rev&rev=540144
Log:
enhance the bean-map for service servlet use case

Added:
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd   (with props)
Modified:
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/META-INF/spring.schemas

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java?view=diff&rev=540144&r1=540143&r2=540144
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java Mon May 21 06:52:41 2007
@@ -16,13 +16,17 @@
  */
 package org.apache.cocoon.spring.configurator.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.StringTokenizer;
 
+import org.springframework.beans.BeanWrapperImpl;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.BeanFactory;
@@ -66,6 +70,12 @@
     /** Do we check the parent factories? */
     protected boolean checkParent = true;
 
+    /** Do we check for properties? */
+    protected List hasProperties = new ArrayList();
+
+    /** Which property should we use to key the map? */
+    protected String keyProperty;
+
     /**
      * Get all the bean's from the bean factory and put them into
      * a map using their id.
@@ -81,7 +91,31 @@
             if ( this.stripPrefix && (beanName.startsWith(prefix1) || beanName.startsWith(prefix2)) ) {
                 key = key.substring(prefix1.length());
             }
-            this.beanMap.put(key, this.beanFactory.getBean(beanName));
+            if(this.hasProperties.size() > 0) {
+                final Object bean = this.beanFactory.getBean(beanName);
+                final BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
+                boolean isOk = true;
+                final Iterator iter = this.hasProperties.iterator();
+                while(iter.hasNext()) {
+                    final String propName = (String)iter.next();
+                    if(!wrapper.isReadableProperty(propName)) {
+                        isOk = false;
+                    }
+                }
+                if(isOk) {
+                    if( this.keyProperty != null && this.keyProperty.length() > 0 && wrapper.isReadableProperty(this.keyProperty)) {
+                        key = (String)wrapper.getPropertyValue(this.keyProperty);
+                    }
+                    this.beanMap.put(key, bean);
+                }
+            } else {
+                final Object bean = this.beanFactory.getBean(beanName);
+                final BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
+                if( this.keyProperty != null && this.keyProperty.length() > 0 && wrapper.isReadableProperty(this.keyProperty)) {
+                    key = (String)wrapper.getPropertyValue(this.keyProperty);
+                }
+                this.beanMap.put(key, bean);
+            }
         }
     }
 
@@ -143,6 +177,19 @@
 
     public void setCheckParent(boolean checkParent) {
         this.checkParent = checkParent;
+    }
+
+    public void setHasProperties(String pHasProperties) {
+        final StringTokenizer tokenizer = new StringTokenizer(pHasProperties, " \t\n\r\f,");
+        final List propNames = new ArrayList();
+        while(tokenizer.hasMoreTokens()) {
+            propNames.add( tokenizer.nextToken() );
+        }
+        this.hasProperties = propNames;
+    }
+
+    public void setKeyProperty(String pKeyProperty) {
+        this.keyProperty = pKeyProperty;
     }
 
     public void setType(Class typeClass) {

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java?view=diff&rev=540144&r1=540143&r2=540144
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java Mon May 21 06:52:41 2007
@@ -47,6 +47,8 @@
         beanDef.getPropertyValues().addPropertyValue("type", typeClass);
         beanDef.getPropertyValues().addPropertyValue("checkParent", this.getAttributeValue(element, "check-parent", "true"));
         beanDef.getPropertyValues().addPropertyValue("stripPrefix", this.getAttributeValue(element, "strip-prefix", "true"));
+        beanDef.getPropertyValues().addPropertyValue("hasProperties", this.getAttributeValue(element, "has-properties", ""));
+        beanDef.getPropertyValues().addPropertyValue("keyProperty", this.getAttributeValue(element, "key-property", ""));
 
         // register bean if it's a global definition
         if ( !parserContext.isNested() ) {

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/META-INF/spring.schemas?view=diff&rev=540144&r1=540143&r2=540144
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/META-INF/spring.schemas (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/META-INF/spring.schemas Mon May 21 06:52:41 2007
@@ -15,3 +15,4 @@
 #
 http\://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.xsd=org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd
 http\://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd=org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.1.xsd
+http\://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.2.xsd=org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd

Added: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd?view=auto&rev=540144
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd (added)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd Mon May 21 06:52:41 2007
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- @version $Id: cocoon-configurator-1.0.1.xsd 509512 2007-02-20 11:24:10Z cziegeler $ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            targetNamespace="http://cocoon.apache.org/schema/configurator"
+            xmlns:tns="http://cocoon.apache.org/schema/configurator"
+            xmlns="http://cocoon.apache.org/schema/configurator">
+
+    <xsd:element name="settings">
+      <xsd:complexType>
+    	<xsd:sequence>
+    	    <xsd:element ref="include-beans" minOccurs="0" maxOccurs="unbounded"/>
+    	    <xsd:element ref="include-properties" minOccurs="0" maxOccurs="unbounded"/>
+    	    <xsd:element ref="property" minOccurs="0" maxOccurs="unbounded"/>
+    	</xsd:sequence>
+    	<xsd:attribute name="runningMode" type="xsd:string" use="optional"/>
+    	<xsd:attribute name="readFromClasspath" type="xsd:boolean" use="optional"/>
+    	<xsd:attribute name="readFromGlobalLocation" type="xsd:boolean" use="optional"/>
+        <xsd:attribute name="extractBlockResources" type="xsd:boolean" use="optional"/>
+      </xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="child-settings">
+      <xsd:complexType>
+    	<xsd:sequence>
+    	    <xsd:element ref="include-beans" minOccurs="0" maxOccurs="unbounded"/>
+    	    <xsd:element ref="include-properties" minOccurs="0" maxOccurs="unbounded"/>
+    	    <xsd:element ref="property" minOccurs="0" maxOccurs="unbounded"/>
+    	</xsd:sequence>
+    	<xsd:attribute name="name" type="xsd:string" use="required"/>
+      </xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="include-beans">
+      <xsd:complexType>
+    	<xsd:attribute name="dir" type="xsd:string" use="optional"/>
+      </xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="include-properties">
+      <xsd:complexType>
+    	<xsd:attribute name="dir" type="xsd:string" use="required"/>
+      </xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="property">
+      <xsd:complexType>
+    	<xsd:attribute name="name" type="xsd:string" use="required"/>
+    	<xsd:attribute name="value" type="xsd:string" use="required"/>
+      </xsd:complexType>
+    </xsd:element>
+
+    <!-- Since 1.0.1: -->
+    <xsd:element name="bean-map">
+      <xsd:complexType>
+        <xsd:attribute name="name" type="xsd:string" use="optional"/>
+        <xsd:attribute name="id" type="xsd:ID" use="optional"/>
+    	<xsd:attribute name="type" type="xsd:string" use="required"/>
+    	<xsd:attribute name="check-parent" type="xsd:boolean" use="optional" default="true"/>
+    	<xsd:attribute name="strip-prefix" type="xsd:boolean" use="optional" default="true"/>
+        <!-- Since 1.0.2: -->
+        <!-- beans should have all these properties (comma separated list) -->
+    	<xsd:attribute name="has-properties" type="xsd:string" use="optional" default=""/>
+        <!-- use value of this bean property to key the map instead of bean id -->
+        <xsd:attribute name="key-property" type="xsd:string" use="optional" default=""/>
+      </xsd:complexType>
+    </xsd:element>
+</xsd:schema>

Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Joerg Heinicke wrote:
> On 22.05.2007 07:10, Giacomo Pati wrote:
>
>>> 1. Could you please provide links to the thread discussing applied
>>> changes? It really helps to understand these changes 2 months later.
>>
>> Well, the changes are freshly discussed (not 2 month later).
>
> I guess it's meant the other way around: What's known in 2 months (or
> thereafter) when somebody has a look on the code/commit message?
It was a silly language mistake that did not show my intention.

Thanks Joerg for explaining it.

-- 
Grzegorz Kossakowski

Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Joerg Heinicke <jo...@gmx.de>.
On 22.05.2007 07:10, Giacomo Pati wrote:

>> 1. Could you please provide links to the thread discussing applied
>> changes? It really helps to understand these changes 2 months later.
> 
> Well, the changes are freshly discussed (not 2 month later).

I guess it's meant the other way around: What's known in 2 months (or 
thereafter) when somebody has a look on the code/commit message?

Joerg

Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Giacomo Pati <gi...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Grzegorz Kossakowski wrote:
> giacomo@apache.org pisze:
>> Author: giacomo
>> Date: Mon May 21 06:52:41 2007
>> New Revision: 540144
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=540144
>> Log:
>> enhance the bean-map for service servlet use case
> 
> Giacomo, thanks for implementing this. I have few comments:
> 1. Could you please provide links to the thread discussing applied
> changes? It really helps to understand these changes 2 months later.

Well, the changes are freshly discussed (not 2 month later). The changes to the bean-map provider is
the refactoring of the DispatcherServlet's logic collecting block servlets (as discussed in the
recent thread about DispatcherServlet)

> 2. If you modify schema don't forget to publish changes, otherwise
> people's svn copies will break soon or later. (I've done it myself
> already so don't bother yourself)

Thanks. Didn't know they need to be published.

> 3. Could you please add information about your changes to changes.xml file?

I have not thought that change would have enough importance to be mentioned there!

> I have updated the schema by moving your comments to xsd:documentation
> elements. I hope you don't mind.

Thanks alot, it's your code as well as mine ;-)

- --
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (GNU/Linux)

iD8DBQFGUnszLNdJvZjjVZARAgO1AJ9CH5NDDGalOgmWsdTIARAbeDXhTgCfdTrg
W4JFPCM90nLKKeudmNeCnjE=
=xPAU
-----END PGP SIGNATURE-----

Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Grzegorz Kossakowski <gk...@apache.org>.
giacomo@apache.org pisze:
> Author: giacomo
> Date: Mon May 21 06:52:41 2007
> New Revision: 540144
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=540144
> Log:
> enhance the bean-map for service servlet use case

Giacomo, thanks for implementing this. I have few comments:
1. Could you please provide links to the thread discussing applied changes? It really helps to understand these changes 2 months later.
2. If you modify schema don't forget to publish changes, otherwise people's svn copies will break soon or later. (I've done it myself 
already so don't bother yourself)
3. Could you please add information about your changes to changes.xml file?

I have updated the schema by moving your comments to xsd:documentation elements. I hope you don't mind.

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/

Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Giacomo Pati <gi...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Reinhard Poetz wrote:
> giacomo@apache.org wrote:
>> Author: giacomo
>> Date: Mon May 21 06:52:41 2007
>> New Revision: 540144
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=540144
>> Log:
>> enhance the bean-map for service servlet use case
>>
>> Added:
>>    
>> cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd  
>> (with props)
> 
> Since we haven't released 1.0.1 so far, it's not necessary to increment
> the version number.

Ok, thanks. I've merged 1.0.2 into 1.0.1

- --
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (GNU/Linux)

iD8DBQFGUcFELNdJvZjjVZARAvbwAJ48n2pU8f/YeK+QcpYwHLdrIthTcwCdGsiD
o4m9tO/Rc+6fNsTDq2jkyA4=
=8dm/
-----END PGP SIGNATURE-----

Re: svn commit: r540144 - in /cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main: java/org/apache/cocoon/spring/configurator/impl/ resources/META-INF/ resources/org/apache/cocoon/spring/configurator/schema/

Posted by Reinhard Poetz <re...@apache.org>.
giacomo@apache.org wrote:
> Author: giacomo
> Date: Mon May 21 06:52:41 2007
> New Revision: 540144
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=540144
> Log:
> enhance the bean-map for service servlet use case
> 
> Added:
>     cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.2.xsd   (with props)

Since we haven't released 1.0.1 so far, it's not necessary to increment the 
version number.

-- 
Reinhard Pötz           Independent Consultant, Trainer & (IT)-Coach 

{Software Engineering, Open Source, Web Applications, Apache Cocoon}

                                        web(log): http://www.poetz.cc
--------------------------------------------------------------------