Author: kylem
Date: Thu Apr 28 15:36:26 2005
New Revision: 165218
URL: http://svn.apache.org/viewcvs?rev=165218&view=rev
Log:
Due traversal up the BeanContext nesting hierarchy for
getCurrentServiceClasses() and getCurrentServiceSelectors(), so they mirror the
behavior of getService() and hasService().
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?rev=165218&r1=165217&r2=165218&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Thu Apr 28 15:36:26 2005
@@ -848,6 +848,61 @@
}
}
+ //
+ // BeanContextServices.getCurrentServiceClasses
+ // Override the default implementatino of getCurrentServiceClasses
inherited from
+ // 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
+ // 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.
+ //
+ synchronized public Iterator getCurrentServiceClasses()
+ {
+ Set classSet = new HashSet();
+ BeanContextServices bcs = this;
+
+ while (bcs != null)
+ {
+ // Optimize the case where we can do a direct copy based upon impl
knowledge.
+ if (bcs instanceof ControlBeanContext)
+ {
+ classSet.addAll(((ControlBeanContext)bcs).services.keySet());
+ }
+ else
+ {
+ 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)
+ bcs = (BeanContextServices)bc;
+ else
+ bcs = null;
+ }
+ return classSet.iterator();
+ }
+
+ //
+ // BeanContextServices.getCurrentServiceSelectors
+ // Override getCurrentServiceSelectors for the same reason as above
+ //
+ public Iterator getCurrentServiceSelectors(Class serviceClass)
+ {
+ if (hasService(serviceClass))
+ return super.getCurrentServiceSelectors(serviceClass);
+
+ BeanContext bc = getBeanContext();
+ if (bc instanceof BeanContextServices)
+ return
((BeanContextServices)bc).getCurrentServiceSelectors(serviceClass);
+
+ return null;
+ }
+
/**
* The ControlBean instance that this context is providing services for.
This value can
* be null, if the context instance is associated with top-level
(non-control) context.