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/01/23 18:46:02 UTC

svn commit: r371605 - in /beehive/trunk/controls/src: runtime/org/apache/beehive/controls/runtime/bean/ spi/org/apache/beehive/controls/spi/context/

Author: ekoneil
Date: Mon Jan 23 09:45:56 2006
New Revision: 371605

URL: http://svn.apache.org/viewcvs?rev=371605&view=rev
Log:
Add enhancement captured in BEEHIVE-1047.  

The ControlBeanContextFactory can be used to allow control containers to add a custom implementation of a ControlBean's ControlBeanContext.  This allows additional functionality to be exposed to ControlBean(s).

BB: self
Test: Controls && System Controls pass


Added:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java   (with props)
    beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/
    beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java   (with props)
Modified:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?rev=371605&r1=371604&r2=371605&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java Mon Jan 23 09:45:56 2006
@@ -52,8 +52,10 @@
 import org.apache.beehive.controls.api.context.ControlThreadContext;
 import org.apache.beehive.controls.api.events.EventRef;
 import org.apache.beehive.controls.api.events.EventSet;
+import org.apache.beehive.controls.spi.context.ControlBeanContextFactory;
 import org.apache.beehive.controls.spi.svc.Interceptor;
 import org.apache.beehive.controls.spi.svc.InterceptorPivotException;
+import org.apache.commons.discovery.tools.DiscoverClass;
 
 /**
  * The ControlBean class is an abstract base class for the JavaBean classes generated to support
@@ -90,7 +92,18 @@
         _controlIntf = controlIntf;
 
         // Create the context that acts as the BeanContextProxy for this bean (the context that this bean _defines_).
-        _cbc = new ControlBeanContext( this );
+        try
+        {
+            DiscoverClass discoverer = new DiscoverClass();
+            Class factoryClass = discoverer.find(ControlBeanContextFactory.class, DefaultControlBeanContextFactory.class.getName());
+            ControlBeanContextFactory factory = (ControlBeanContextFactory)factoryClass.newInstance();
+            _cbc = factory.instantiate(this);
+        }
+        catch (Exception e) {
+            throw new ControlException("Exception creating ControlBeanContext", e);
+        }
+
+        //_cbc = new ControlBeanContext( this );
 
         //
         // If no containing context was specified during construction, see if there is a current
@@ -362,7 +375,7 @@
      * Returns the implementation instance associated with this ControlBean.
      */
     /* package */ Object getImplementation() {
-        return _control; 
+        return _control;
     }
 
     /**
@@ -371,7 +384,7 @@
      * and other common services, it also provides a hook for interceptors.
      */
     protected void preInvoke(Method m, Object [] args, String [] interceptorNames)
-    	throws InterceptorPivotException
+        throws InterceptorPivotException
     {
         //
         // If the implementation expects single threaded behavior and our container does
@@ -492,7 +505,7 @@
         postInvoke(m, args, retval, t, null, null);
     }
 
-    
+
     /**
      * Sets the EventNotifier for this ControlBean
      */
@@ -645,7 +658,7 @@
      * Dispatches the requested operation event on the ControlBean.
      * @see org.apache.beehive.controls.runtime.bean.ControlContainerContext#dispatchEvent
      */
-    /* package */ Object dispatchEvent(EventRef event, Object [] args) 
+    /* package */ Object dispatchEvent(EventRef event, Object [] args)
                          throws IllegalAccessException,IllegalArgumentException,
                                 InvocationTargetException
     {
@@ -656,7 +669,7 @@
         //
         Class controlInterface = getControlInterface();
         Method method = event.getEventMethod(controlInterface);
-        
+
         //
         // Locate the target of the event
         //
@@ -669,7 +682,7 @@
             // how/when to dispatch to any external listeners (via a @Client notifier 
             // instance)
             //
-            eventTarget = _control; 
+            eventTarget = _control;
         }
         else
         {
@@ -898,7 +911,7 @@
     /**
      * Implementation of the Java serialization writeObject method
      */
-    private synchronized void writeObject(ObjectOutputStream oos) 
+    private synchronized void writeObject(ObjectOutputStream oos)
         throws IOException
     {
         if (_control != null)
@@ -920,7 +933,7 @@
             }
             else
             {
-                getImplInitializer().resetServices(this, _control);    
+                getImplInitializer().resetServices(this, _control);
                 _hasServices = false;
             }
         }
@@ -931,7 +944,7 @@
     /**
      * Called during XMLDecoder reconstruction of a ControlBean.
      */
-    public void decodeImpl(Object impl) 
+    public void decodeImpl(Object impl)
     {
         if (impl != _control)
             throw new ControlException("Cannot change implementation");

Added: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java?rev=371605&view=auto
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java (added)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java Mon Jan 23 09:45:56 2006
@@ -0,0 +1,55 @@
+/*
+   Copyright 2004 The Apache Software Foundation.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+   
+       http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  
+   $Header:$
+*/
+package org.apache.beehive.controls.runtime.bean;
+
+import org.apache.beehive.controls.api.bean.ControlBean;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.spi.context.ControlBeanContextFactory;
+
+/**
+ * Default implementation of the {@link ControlBeanContextFactory} that simply creates an instance of a
+ * {@link ControlBeanContext} given the current {@link ControlBean}.
+ */
+public class DefaultControlBeanContextFactory
+    implements ControlBeanContextFactory {
+
+    /**
+     * Create the {@link ControlBeanContext} for the {@link ControlBean}.
+     * @param controlBean
+     * @return the {@link ControlBeanContext}
+     */
+    public ControlBeanContext instantiate(ControlBean controlBean) {
+        if(!(controlBean instanceof org.apache.beehive.controls.runtime.bean.ControlBean))
+            throw new IllegalArgumentException("The ControlBean of type \"" + controlBean.getClass().getName() +
+                "\" is unsupported.  The ControlBean must extend " +
+                org.apache.beehive.controls.runtime.bean.ControlBean.class.getName());
+
+        /*
+        The provided ControlBean is a "api.bean.ControlBean"; this factory implementation only creates
+        ControlBeanContext implementations for "runtime.bean.ControlBean" types.  Ensuare that this is
+        of that type.
+         */
+        org.apache.beehive.controls.runtime.bean.ControlBean runtimeControlBean =
+            (org.apache.beehive.controls.runtime.bean.ControlBean)controlBean;
+
+        /*
+        Create a simple new ControlBeanContext.
+        */
+        return new org.apache.beehive.controls.runtime.bean.ControlBeanContext(runtimeControlBean);
+    }
+}

Propchange: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java?rev=371605&view=auto
==============================================================================
--- beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java (added)
+++ beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java Mon Jan 23 09:45:56 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.spi.context;
+
+import org.apache.beehive.controls.api.bean.ControlBean;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+/**
+ * The ControlBeanContextFactory defines a service provider interface for providing implementations
+ * of factories to create a {@link org.apache.beehive.controls.api.context.ControlBeanContext}
+ * object.  This factory is <b>only</b> used to create ControlBeanContexts that are associated
+ * with a ControlBean instance; it is not used to create
+ * {@link org.apache.beehive.controls.api.context.ControlContainerContext} objects.
+ */
+public interface ControlBeanContextFactory {
+
+    /**
+     * Instantiate a {@link ControlBeanContext} object that will be associated with the
+     * provided {@link ControlBean}.
+     *
+     * @param controlBean
+     * @return the ControlBeanContext instance
+     */
+    public <T extends ControlBeanContext> T instantiate(ControlBean controlBean);
+}

Propchange: beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/context/ControlBeanContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native