You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cs...@apache.org on 2006/05/18 17:43:03 UTC
svn commit: r407573 - in /beehive/trunk/controls:
src/runtime/org/apache/beehive/controls/runtime/bean/
src/runtime/org/apache/beehive/controls/runtime/servlet/
src/test-container/org/apache/beehive/controls/test/container/
test/src/junit-tests/org/apa...
Author: cschoett
Date: Thu May 18 08:43:02 2006
New Revision: 407573
URL: http://svn.apache.org/viewvc?rev=407573&view=rev
Log:
This commit fixes several issues with using the new ControlBeanContextSupport bean contexts.
The first issue is that when the WebContextFactoryProvider class is modified to use the o.a.b.c.r.webcontext bean context support
classes, only the top-level context (such as ServletBeanContext) actually uses these classes instead of the java.beans.beancontext
support classes. This is because when a control bean is about to be added to a top-level context it first creates its control
bean context, however; since the top-level context does not have a parent, and can only invoke its getService() call for one of
its children (it doesn't have any at this point) so the cbc gets created with the default j.b.b support classes. If that control
bean has nested controls within it, the nested control bean contexts are created with the proper o.a.b.c.r.webcontext support classes.
To fix this issue I have modified the ServletBeanContext class to override the ControlBeanContext.getService() method and to return
the proper factory type if the getService request cannot be handled by ControlBeanContext.getService().
Other issues:
-> I've also updated the ControlTestContainerContext to use the o.a.b.c.r.webcontext support classes, which involved pretty much
the same modification that was necessary for the ServletBeanContext.
-> There was another bug in ControlBeanContext where the serialization methods readObject() and writeObject() needed to be tweaked
to work correctly with the o.a.b.c.r.webcontext support classes.
-> Removed empty test from the SimpleSerializationTest.
Modified:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
beehive/trunk/controls/src/test-container/org/apache/beehive/controls/test/container/ControlTestContainerContext.java
beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/SimpleSerializationTest.java
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?rev=407573&r1=407572&r2=407573&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Thu May 18 08:43:02 2006
@@ -762,8 +762,11 @@
private synchronized void writeObject(ObjectOutputStream oos)
throws IOException {
oos.defaultWriteObject();
- if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport)
+ if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport) {
((java.beans.beancontext.BeanContextSupport)_beanContextServicesDelegate).writeChildren(oos);
+ } else if(_beanContextServicesDelegate instanceof org.apache.beehive.controls.runtime.webcontext.ControlBeanContextSupport) {
+ ((org.apache.beehive.controls.runtime.webcontext.ControlBeanContextSupport)_beanContextServicesDelegate).writeChildren(oos);
+ }
else assert false;
}
@@ -771,8 +774,11 @@
throws IOException, ClassNotFoundException {
ois.defaultReadObject();
- if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport)
+ if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport) {
((java.beans.beancontext.BeanContextSupport)_beanContextServicesDelegate).readChildren(ois);
+ } else if(_beanContextServicesDelegate instanceof org.apache.beehive.controls.runtime.webcontext.ControlBeanContextSupport) {
+ ((org.apache.beehive.controls.runtime.webcontext.ControlBeanContextSupport)_beanContextServicesDelegate).readChildren(ois);
+ }
else assert false;
// Re-initialize a deserialized control hierarchy.
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java?rev=407573&r1=407572&r2=407573&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java Thu May 18 08:43:02 2006
@@ -20,7 +20,6 @@
import java.util.Stack;
import java.io.InputStream;
import java.beans.beancontext.BeanContextChild;
-import java.beans.beancontext.BeanContextServices;
import java.beans.beancontext.BeanContextServiceProvider;
import java.net.URL;
import java.net.MalformedURLException;
@@ -71,8 +70,8 @@
// Register an *internal* service that is used to create ControlBeanContext objects for
// children of this control container
//
- BeanContextServiceProvider cbcFactoryProvider = WebContextFactoryProvider.getProvider();
- addService(ControlBeanContextFactory.class, cbcFactoryProvider);
+ _bcsp = WebContextFactoryProvider.getProvider();
+ addService(ControlBeanContextFactory.class, _bcsp);
}
/**
@@ -226,6 +225,27 @@
return null;
}
+ /**
+ * Override ControlBeanContext.getService(). A control bean creates its bean context using the
+ * ControlBeanContextFactory service provided by this context. A control bean will attempt to create
+ * its context before adding its self to this context as a child. This creates a chicken/egg problem since
+ * only a child of a context may request a service from it.
+ *
+ * This method provides a way to crack the chicken/egg problem by first trying to get the service using the
+ * control bean context's getService() method, and if that call returns null and the requested service is
+ * the ControlBeanContextFactory then returning an instance of the service provider.
+ *
+ * @param serviceClass
+ * @param selector
+ */
+ public <T> T getService(Class<T> serviceClass, Object selector)
+ {
+ T service = super.getService(serviceClass, selector);
+ if (service == null && serviceClass.equals(ControlBeanContextFactory.class)) {
+ return (T)_bcsp.getService(this, this, serviceClass, selector);
+ }
+ return service;
+ }
protected boolean useWrappers() {
return _useWrappers;
}
@@ -246,4 +266,5 @@
private boolean _useWrappers = true;
private transient Stack<RequestContext> _reqStack;
+ private transient BeanContextServiceProvider _bcsp;
}
Modified: beehive/trunk/controls/src/test-container/org/apache/beehive/controls/test/container/ControlTestContainerContext.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/test-container/org/apache/beehive/controls/test/container/ControlTestContainerContext.java?rev=407573&r1=407572&r2=407573&view=diff
==============================================================================
--- beehive/trunk/controls/src/test-container/org/apache/beehive/controls/test/container/ControlTestContainerContext.java (original)
+++ beehive/trunk/controls/src/test-container/org/apache/beehive/controls/test/container/ControlTestContainerContext.java Thu May 18 08:43:02 2006
@@ -19,8 +19,11 @@
import java.io.InputStream;
import java.beans.beancontext.BeanContextChild;
+import java.beans.beancontext.BeanContextServiceProvider;
import org.apache.beehive.controls.runtime.bean.ControlContainerContext;
+import org.apache.beehive.controls.runtime.bean.WebContextFactoryProvider;
+import org.apache.beehive.controls.spi.context.ControlBeanContextFactory;
/**
* ControlContainerContext implementation used to test controls in a standalone JVM.
@@ -28,9 +31,56 @@
public class ControlTestContainerContext
extends ControlContainerContext {
+ private transient BeanContextServiceProvider _cbcFactoryProvider;
+
+ public ControlTestContainerContext(){
+ //
+ // This sets the BeanContextServicesFactory instance on the ControlBeanContext and allows this
+ // CCC object to be created with a BeanContextServicesDelegate of the type returned by this factory
+ //
+ super(WebContextFactoryProvider.WEB_CONTEXT_BCS_FACTORY);
+ }
+
+ /**
+ * Called by BeanContextSupport superclass during construction and deserialization to
+ * initialize subclass transient state
+ */
+ public void initialize()
+ {
+ super.initialize();
+ // Register an *internal* service that is used to create ControlBeanContext objects for
+ // children of this control container
+ //
+ _cbcFactoryProvider = WebContextFactoryProvider.getProvider();
+ addService(ControlBeanContextFactory.class, _cbcFactoryProvider);
+ }
+
+ /**
+ * Override ControlBeanContext.getService(). A control bean creates its bean context using the
+ * ControlBeanContextFactory service provided by this context. A control bean will attempt to create
+ * its context before adding its self to this context as a child. This creates a chicken/egg problem since
+ * only a child of a context may request a service from it.
+ *
+ * This method provides a way to crack the chicken/egg problem by first trying to get the service using the
+ * control bean context's getService() method, and if that call returns null and the requested service is
+ * the ControlBeanContextFactory then returning an instance of the service provider.
+ *
+ * @param serviceClass
+ * @param selector
+ * @return
+ */
+ public <T> T getService(Class<T> serviceClass, Object selector)
+ {
+ T service = super.getService(serviceClass, selector);
+ if (service == null && serviceClass.equals(ControlBeanContextFactory.class)) {
+ return (T)_cbcFactoryProvider.getService(this, this, serviceClass, selector);
+ }
+ return service;
+ }
+
public InputStream getResourceAsStream(String name, BeanContextChild bcc) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(name);
return inputStream;
- }
+ }
}
Modified: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/SimpleSerializationTest.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/SimpleSerializationTest.java?rev=407573&r1=407572&r2=407573&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/SimpleSerializationTest.java (original)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/SimpleSerializationTest.java Thu May 18 08:43:02 2006
@@ -49,8 +49,6 @@
/* intentionally, this does not call super */
}
- public void testFoo() {}
-
public void testSimpleSerialization() throws Exception {
//