Hi Geoff,Ah, I hadn't noticed this. Still, does that explain why it's called twice for every request?
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));
}
Ah, it's thread local. I get it. Ok, will do.
Geoff
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
[EMAIL PROTECTED] wrote:
ghoward 2003/10/25 15:31:39cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java
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
Index: PartSource.java/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java,v
===================================================================
RCS file:
retrieving revision 1.1SourceException
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,
+ public PartSource(String uri, Map objectModel) throwsMalformedURLException, 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);managers curr env.
-
- // get the object model from the component
- Map objectModel =CocoonComponentManager.getCurrentEnvironment().getObjectModel();
// get the cocoon request from the object model.ObjectModelHelper.getRequest(objectModel);
Request request =
cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java
1.2 +16 -3
Index: PartSourceFactory.java/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java,v
===================================================================
RCS file:
retrieving revision 1.11.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PartSourceFactory.java 23 Oct 2003 01:45:34 -0000
+++ PartSourceFactory.java 25 Oct 2003 22:31:39 -00001.2
Contextualizable@@ -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:[EMAIL PROTECTED]">Paul Crabtree</a>
*/
-public class PartSourceFactory implements SourceFactory
+public class PartSourceFactory implements SourceFactory,
{org.apache.excalibur.source.SourceFactory#getSource(java.lang.String,
- /*
+ Map objectModel;
+
+ /*
* Returns a new [EMAIL PROTECTED] PartSource} based on the uri.
*
* @see
java.util.Map)
*/IOException, MalformedURLException
public Source getSource(String uri, Map parameters) throws
contextualize(org.apache.avalon.framework.context.Context context){ - 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
+ throws ContextException { + this.objectModel = ContextHelper.getObjectModel(context); } }
