cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From volker.schm...@basf-it-services.com
Subject Antwort: Re: cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/source/impl PartSource.java PartSourceFactory.java
Date Mon, 27 Oct 2003 07:54:41 GMT

Hi Geoff,

I think the reason is, that the PartSourceFactory isn't ThreadSafe. So
every time you access a PartSourceFactory a new Component is created and
the contextualize Method is called.
Calling "this.objectModel = ContextHelper.getObjectModel(context)" inside
the "contextualize"-Method can't work, because contextualize is called only
once. You need to call "ContextHelper.getObjectModel(context)" inside the
actual Thead, instead you don't get the right objectModel.

My proposal is change getSource to:

public Source getSource(String uri, Map parameters) throws IOException,
MalformedURLException
{
    return new PartSource(uri, ContextHelper.getObjectModel(this.context));
}

Volker




Oh, by the way - when I was testing this I traced things through a few
times with the debugger and found that contextualize() is being called
twice for each request.  Is that expected?  Is there any conceivable
mis-coding or mis-configuration of the component that could cause this?

Geoff

ghoward@apache.org wrote:

>ghoward     2003/10/25 15:31:39
>
>  Modified:    src/java/org/apache/cocoon/components/source/impl
>                        PartSource.java PartSourceFactory.java
>  Log:
>  use contextualize instead of static
>
>  CocoonComponentManager.getCurrentEnvironment()
>
>
>
>
>  Revision  Changes    Path
>  1.2       +2 -7
cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java

>
>  Index: PartSource.java
>  ===================================================================
>  RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java,v

>  retrieving revision 1.1
>  retrieving revision 1.2
>  diff -u -r1.1 -r1.2
>  --- PartSource.java         23 Oct 2003 01:45:34 -0000          1.1
>  +++ PartSource.java         25 Oct 2003 22:31:39 -0000          1.2
>  @@ -58,8 +58,6 @@
>   import org.apache.cocoon.servlet.multipart.Part;
>   import org.apache.cocoon.environment.ObjectModelHelper;
>   import org.apache.cocoon.environment.Request;
>  -import org.apache.cocoon.components.CocoonComponentManager;
>  -
>   import java.net.MalformedURLException;
>   import java.util.Map;
>   import java.io.IOException;
>  @@ -91,7 +89,7 @@
>        * @throws SourceException
>        * @throws MalformedURLException
>        */
>  -         public PartSource(String uri) throws MalformedURLException,
SourceException
>  +         public PartSource(String uri, Map objectModel) throws
MalformedURLException, SourceException
>            {
>                        // set the uri for use in getURI()
>                this.uri = uri;
>  @@ -110,9 +108,6 @@
>
>                        // get the request parameter name: the bit after
://
>                        String location = uri.substring(position + 2);
>  -
>  -                     // get the object model from the component
managers curr env.
>  -                     Map objectModel =
CocoonComponentManager.getCurrentEnvironment().getObjectModel();
>
>                        // get the cocoon request from the object model.
>                        Request request =
ObjectModelHelper.getRequest(objectModel);
>
>
>
>  1.2       +16 -3
cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java

>
>  Index: PartSourceFactory.java
>  ===================================================================
>  RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java,v

>  retrieving revision 1.1
>  retrieving revision 1.2
>  diff -u -r1.1 -r1.2
>  --- PartSourceFactory.java        23 Oct 2003 01:45:34 -0000
1.1
>  +++ PartSourceFactory.java        25 Oct 2003 22:31:39 -0000
1.2
>  @@ -50,6 +50,9 @@
>   */
>   package org.apache.cocoon.components.source.impl;
>
>  +import org.apache.avalon.framework.context.ContextException;
>  +import org.apache.avalon.framework.context.Contextualizable;
>  +import org.apache.cocoon.components.ContextHelper;
>   import org.apache.excalibur.source.Source;
>   import org.apache.excalibur.source.SourceFactory;
>
>  @@ -62,16 +65,18 @@
>    *
>    * @author <a href="mailto:paul.crabtree@dna.co.uk">Paul Crabtree</a>
>    */
>  -public class PartSourceFactory implements SourceFactory
>  +public class PartSourceFactory implements SourceFactory,
Contextualizable
>   {
>  -         /*
>  +         Map objectModel;
>  +
>  +    /*
>             * Returns a new {@link PartSource} based on the uri.
>             *
>             * @see
org.apache.excalibur.source.SourceFactory#getSource(java.lang.String,
java.util.Map)
>             */
>       public Source getSource(String uri, Map parameters) throws
IOException, MalformedURLException
>       {
>  -        return new PartSource(uri);
>  +        return new PartSource(uri, this.objectModel);
>       }
>
>            /**
>  @@ -82,5 +87,13 @@
>       public void release(Source source)
>       {
>           // Nothing to do here
>  +    }
>  +
>  +         /**
>  +     * Get the objectModel from the Context
>  +     */
>  +    public void
contextualize(org.apache.avalon.framework.context.Context context)
>  +    throws ContextException {
>  +         this.objectModel = ContextHelper.getObjectModel(context);
>       }
>   }
>
>
>
>
>
>
>
>








Mime
View raw message