You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/05/03 19:30:08 UTC
svn commit: r399361 -
/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Author: ekoneil
Date: Wed May 3 10:29:51 2006
New Revision: 399361
URL: http://svn.apache.org/viewcvs?rev=399361&view=rev
Log:
Change the ControlBeanContext object to delegate to an instance of the java.beans.beancontext.BeanContextServices interface. This change makes it possible to have the CBC object itself delegate to an instance of BeanContextServices to receive functionality captured in the BeanContext, BeanContextChild, and BeanContextServices interfaces.
Any existing applications that used this class should have compatible behavior as long as they used methods from the interfaces in java.beans.beancontext rather than from the implementation classes. Otherwise, existing CBC users will need to port to these interfaces. But, you'd never code to an internal impl from your applications, would you? :)
I've run all of the tests that I can find to make this work -- certainly doesn't mean that the implementation is flawless, though... So, report bugs if you see them.
BB: self
Test: Everything passes
Modified:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?rev=399361&r1=399360&r2=399361&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 Wed May 3 10:29:51 2006
@@ -19,11 +19,17 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
+import java.beans.PropertyChangeListener;
+import java.beans.VetoableChangeListener;
import java.beans.beancontext.BeanContext;
import java.beans.beancontext.BeanContextServiceRevokedEvent;
import java.beans.beancontext.BeanContextServiceProvider;
import java.beans.beancontext.BeanContextServices;
-import java.beans.beancontext.BeanContextServicesSupport;
+import java.beans.beancontext.BeanContextChild;
+import java.beans.beancontext.BeanContextServiceRevokedListener;
+import java.beans.beancontext.BeanContextServicesListener;
+import java.beans.beancontext.BeanContextMembershipListener;
+import java.beans.beancontext.BeanContextServiceAvailableEvent;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
@@ -36,6 +42,12 @@
import java.util.Set;
import java.util.TooManyListenersException;
import java.util.Vector;
+import java.util.Collection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.net.URL;
import org.apache.beehive.controls.api.ControlException;
import org.apache.beehive.controls.api.context.ControlHandle;
@@ -55,32 +67,38 @@
* - it acts as the BeanContextServicesRevokedListener when an associated control
* bean has lost access to services.
*/
-public class ControlBeanContext
- extends BeanContextServicesSupport
+public class ControlBeanContext
implements org.apache.beehive.controls.api.context.ControlBeanContext,
java.beans.PropertyChangeListener,
- java.beans.VetoableChangeListener
+ java.beans.VetoableChangeListener,
+ java.io.Serializable
{
/**
* Creates a new ControlBeanContext instance associated with a specific
* control bean.
*
- * @param bean The control bean that contains/scopes the ControlBeanContext. If null,
+ * @param bean The control bean that contains/scopes the ControlBeanContext. If null,
it means the ControlBeanContext is for a top-level container.
*/
protected ControlBeanContext(ControlBean bean)
{
_bean = bean;
+
+ //
+ // For now, just create an implementation of the classes in the JDK as a delegate.
+ //
+ _beanContextServicesDelegate =
+ new java.beans.beancontext.BeanContextServicesSupport(this);
+
+ initialize();
}
/**
- * Called by BeanContextSupport superclass during construction and deserialization to
+ * Called by BeanContextSupport superclass during construction and deserialization to
* initialize subclass transient state
*/
public void initialize()
{
- super.initialize();
-
//
// Register the ControlBeanContext provider on all new context instances.
//
@@ -128,7 +146,7 @@
}
- super.setBeanContext(beanContext);
+ _beanContextServicesDelegate.setBeanContext(beanContext);
resetControlID();
@@ -145,7 +163,7 @@
* The NameGenerator class is a simple helper class that creates new unique names based
* upon a base prefix and an incrementing counter
*/
- private static class NameGenerator implements java.io.Serializable
+ private static class NameGenerator implements java.io.Serializable
{
NameGenerator(String namePrefix)
{
@@ -231,7 +249,7 @@
}
}
- boolean added = super.add(targetChild);
+ boolean added = _beanContextServicesDelegate.add(targetChild);
if (added && beanID != null)
_childMap.put(beanID, targetChild);
@@ -245,14 +263,14 @@
public boolean remove(Object targetChild)
{
assert targetChild instanceof ControlBean; // should be guaranteed above
- boolean removed = super.remove(targetChild);
+ boolean removed = _beanContextServicesDelegate.remove(targetChild);
if (removed)
- {
+ {
//
// Remove from the locally maintained child map
//
- String localID = ((ControlBean)targetChild).getLocalID();
+ String localID = ((ControlBean)targetChild).getLocalID();
Object removedChild = _childMap.remove(localID);
assert removedChild == targetChild; // just being safe
}
@@ -282,7 +300,7 @@
}
/**
- * Returns the ControlBean associated directly with the ControlBeanContext. If the
+ * Returns the ControlBean associated directly with the ControlBeanContext. If the
* context represents a top-level container, will return null.
*/
public ControlBean getControlBean()
@@ -342,8 +360,8 @@
if (beanContext instanceof ControlContainerContext)
return beanContext.getBeanAnnotationMap(_bean, annotElem);
beanContext = (ControlBeanContext)beanContext.getBeanContext();
- }
-
+ }
+
// No ControlContainerContext was found, so just use the default implementation
return getBeanAnnotationMap(_bean, annotElem);
}
@@ -359,7 +377,7 @@
// REVIEW: is this the right place to handle the general control client case?
if ( bean != null )
setDelegateMap( map, bean, annotElem );
-
+
return map;
}
@@ -481,11 +499,11 @@
public Object getParameterValue(Method m, String parameterName, Object [] parameters)
throws IllegalArgumentException
{
- String [] names = getParameterNames(m);
+ String [] names = getParameterNames(m);
// Validate the input parameter array
if (parameters.length != names.length)
- throw new IllegalArgumentException("Expected " + names.length + " parameters," +
+ throw new IllegalArgumentException("Expected " + names.length + " parameters," +
"Found " + parameters.length);
// Finding the index of the matching parameter name
@@ -651,7 +669,7 @@
String parentID = ((ControlBeanContext)bc).getControlID();
if (parentID != null)
{
- id = parentID +
+ id = parentID +
org.apache.beehive.controls.api.bean.ControlBean.IDSeparator +
id;
}
@@ -683,7 +701,7 @@
// java.beans.beancontext.BeanContextServicesSuppport. The reason for this is a bug/
// flaw in its underlying implementation. It does not include any services exposed
// by any nesting contexts. This is contradictory to the implementation of hasService()
- // and getService() which do delegate up to a parent context to find services if not
+ // and getService() which do delegate up to a parent context to find services if not
// available on the local context. This means hasService() could return 'true' for a
// service that isn't returned by getCurrentServiceClasses(), which seems like a bug.
//
@@ -694,18 +712,10 @@
while (bcs != null)
{
- // Optimize the case where we can do a direct copy based upon superclass impl knowledge.
- if (bcs instanceof ControlBeanContext)
- {
- classSet.addAll(((ControlBeanContext)bcs).services.keySet());
- }
- else
- {
- Iterator iter = bcs.getCurrentServiceClasses();
- while (iter.hasNext())
- classSet.add(iter.next());
- }
-
+ Iterator iter = bcs.getCurrentServiceClasses();
+ while (iter.hasNext())
+ classSet.add(iter.next());
+
// Go up to the parent, if it is a service provider as well
BeanContext bc = getBeanContext();
if (bc instanceof BeanContextServices && bcs != bc)
@@ -723,8 +733,8 @@
public Iterator getCurrentServiceSelectors(Class serviceClass)
{
if (hasService(serviceClass))
- return super.getCurrentServiceSelectors(serviceClass);
-
+ return _beanContextServicesDelegate.getCurrentServiceSelectors(serviceClass); //
+
BeanContext bc = getBeanContext();
if (bc instanceof BeanContextServices)
return ((BeanContextServices)bc).getCurrentServiceSelectors(serviceClass);
@@ -732,6 +742,197 @@
return null;
}
+ private synchronized void writeObject(ObjectOutputStream oos)
+ throws IOException {
+ oos.defaultWriteObject();
+ if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport)
+ ((java.beans.beancontext.BeanContextSupport)_beanContextServicesDelegate).writeChildren(oos);
+ else assert false;
+ }
+
+ private synchronized void readObject(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ ois.defaultReadObject();
+
+ if(_beanContextServicesDelegate instanceof java.beans.beancontext.BeanContextSupport)
+ ((java.beans.beancontext.BeanContextSupport)_beanContextServicesDelegate).readChildren(ois);
+ else assert false;
+
+ // Re-initialize a deserialized control hierarchy.
+ initialize();
+ }
+
+ public boolean equals(Object o) {
+ /* todo: make sure this logic is right / sufficient */
+ if (this == o)
+ return true;
+
+ if(!(o instanceof org.apache.beehive.controls.api.context.ControlBeanContext))
+ return false;
+
+ return o instanceof ControlBeanContext &&
+ _beanContextServicesDelegate.equals(((ControlBeanContext)o)._beanContextServicesDelegate);
+ }
+
+ public int hashCode() {
+ /* todo: make sure this logic is right / sufficient */
+ int result;
+ result = (_bean != null ? _bean.hashCode() : 0);
+ result = 31 * result + (_beanContextServicesDelegate != null ? _beanContextServicesDelegate.hashCode() : 0);
+ return result;
+ }
+
+ /* --------------------------------------------------------------------------
+
+ Implementation of java.beans.beancontext.BeanContextServices
+
+ -------------------------------------------------------------------------- */
+ public boolean addService(Class serviceClass, BeanContextServiceProvider serviceProvider) {
+ return _beanContextServicesDelegate.addService(serviceClass, serviceProvider);
+ }
+
+ public void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow) {
+ _beanContextServicesDelegate.revokeService(serviceClass, serviceProvider, revokeCurrentServicesNow);
+ }
+
+ public boolean hasService(Class serviceClass) {
+ return _beanContextServicesDelegate.hasService(serviceClass);
+ }
+
+ public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
+ return _beanContextServicesDelegate.getService(child, requestor, serviceClass, serviceSelector, bcsrl);
+ }
+
+ public void releaseService(BeanContextChild child, Object requestor, Object service) {
+ _beanContextServicesDelegate.releaseService(child, requestor, service);
+ }
+
+ public void addBeanContextServicesListener(BeanContextServicesListener bcsl) {
+ _beanContextServicesDelegate.addBeanContextServicesListener(bcsl);
+ }
+
+ public void removeBeanContextServicesListener(BeanContextServicesListener bcsl) {
+ _beanContextServicesDelegate.removeBeanContextServicesListener(bcsl);
+ }
+
+ public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException {
+ return _beanContextServicesDelegate.instantiateChild(beanName);
+ }
+
+ public InputStream getResourceAsStream(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return _beanContextServicesDelegate.getResourceAsStream(name, bcc);
+ }
+
+ public URL getResource(String name, BeanContextChild bcc) throws IllegalArgumentException {
+ return _beanContextServicesDelegate.getResource(name, bcc);
+ }
+
+ public void addBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ _beanContextServicesDelegate.addBeanContextMembershipListener(bcml);
+ }
+
+ public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml) {
+ _beanContextServicesDelegate.removeBeanContextMembershipListener(bcml);
+ }
+
+ public BeanContext getBeanContext() {
+ return _beanContextServicesDelegate.getBeanContext();
+ }
+
+ public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
+ _beanContextServicesDelegate.addPropertyChangeListener(name, pcl);
+ }
+
+ public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
+ _beanContextServicesDelegate.removePropertyChangeListener(name, pcl);
+ }
+
+ public void addVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ _beanContextServicesDelegate.addVetoableChangeListener(name, vcl);
+ }
+
+ public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) {
+ _beanContextServicesDelegate.removeVetoableChangeListener(name, vcl);
+ }
+
+ public int size() {
+ return _beanContextServicesDelegate.size();
+ }
+
+ public boolean isEmpty() {
+ return _beanContextServicesDelegate.isEmpty();
+ }
+
+ public boolean contains(Object o) {
+ return _beanContextServicesDelegate.contains(o);
+ }
+
+ public Iterator iterator() {
+ return _beanContextServicesDelegate.iterator();
+ }
+
+ public Object[] toArray() {
+ return _beanContextServicesDelegate.toArray();
+ }
+
+ public Object[] toArray(Object[] a) {
+ return _beanContextServicesDelegate.toArray(a);
+ }
+
+ public boolean containsAll(Collection c) {
+ return _beanContextServicesDelegate.containsAll(c);
+ }
+
+ public boolean addAll(Collection c) {
+ return _beanContextServicesDelegate.addAll(c);
+ }
+
+ public boolean removeAll(Collection c) {
+ return _beanContextServicesDelegate.removeAll(c);
+ }
+
+ public boolean retainAll(Collection c) {
+ return _beanContextServicesDelegate.retainAll(c);
+ }
+
+ public void clear() {
+ _beanContextServicesDelegate.clear();
+ }
+
+ public void setDesignTime(boolean designTime) {
+ _beanContextServicesDelegate.setDesignTime(designTime);
+ }
+
+ public boolean isDesignTime() {
+ return _beanContextServicesDelegate.isDesignTime();
+ }
+
+ public boolean needsGui() {
+ return _beanContextServicesDelegate.needsGui();
+ }
+
+ public void dontUseGui() {
+ _beanContextServicesDelegate.dontUseGui();
+ }
+
+ public void okToUseGui() {
+ _beanContextServicesDelegate.okToUseGui();
+ }
+
+ public boolean avoidingGui() {
+ return _beanContextServicesDelegate.avoidingGui();
+ }
+
+ public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) {
+ _beanContextServicesDelegate.serviceAvailable(bcsae);
+ }
+
+ /* --------------------------------------------------------------------------
+
+ Static / deprecated methods.
+
+ -------------------------------------------------------------------------- */
+
/**
* Filename that contains ordering priority for controls interceptor services.
* Each line in the file is a fully qualified interface name. The first line in the file
@@ -739,7 +940,6 @@
* @deprecated Use {@link InterceptorUtils#INTERCEPTOR_CONFIG_FILE} instead. This constant
* will be removed in the next point release.
*/
- public static final String INTERCEPTOR_CONFIG_FILE = "controls-interceptors.config";
/**
* Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for
@@ -867,4 +1067,13 @@
* can be easily recomputed when needed.
*/
private transient String _controlID;
+
+ /**
+ * Object that implements the java.beans.beancontext APIs from the JDK to provide compliance with the
+ * JavaBeans BeanContext / BeanContextChild specification. The ControlBeanContext class uses
+ * this object as a delegate to provide this functionality rather than extending the BeanContext
+ * support classes directly. This allows for more flexibility in how the BeanContextServices (et al)
+ * API implementations evolve over time.
+ */
+ private BeanContextServices _beanContextServicesDelegate;
}