svn commit: r168407 - in /incubator/beehive/trunk: controls/src/api/org/apache/beehive/controls/api/properties/ controls/src/runtime/org/apache/beehive/controls/runtime/bean/ controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/ controls/test/src/units/org/apache/beehive/controls/test/java/inherit/ samples/controls-spring/ samples/controls-spring/external/ samples/controls-spring/integration/ samples/controls-spring/integration/src/ samples/controls-spring/integration/src/META-INF/ samples/controls-spring/integration/src/META-INF/services/ samples/controls-spring/integration/src/org/ samples/controls-spring/integration/src/org/apache/ samples/controls-spring/integration/src/org/apache/beehive/ samples/controls-spring/integration/src/org/apache/beehive/samples/ samples/controls-spring/integration/src/org/apache/beehive/samples/spring/ samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/ samples/controls-spring/web/ samples/controls-spring/web/WEB-INF/ samples/controls-spring/web/WEB-INF/lib/ samples/controls-spring/web/WEB-INF/src/ samples/controls-spring/web/WEB-INF/src/org/ samples/controls-spring/web/WEB-INF/src/org/apache/ samples/controls-spring/web/WEB-INF/src/org/apache/beehive/ samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/ samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/ samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/

5 May 2005 20:57:14 -0000

Author: kylem
Date: Thu May  5 13:57:01 2005
New Revision: 168407

URL: http://svn.apache.org/viewcvs?rev=168407&view=rev
Log:
Added simple webapp sample that demonstrates Spring-Controls integration.  
External configuration of Controls is done using Spring bean definition files, 
and either Controls or Spring factory methods can be used to instantiate them.

Made the @BaseProperties(controlImplementation) property of Controls be a 
settable property, meaning it is possible to programmatically set the 
implementation class bound to a Control.  This is used by Spring sample to 
support impl configuration as part of the bean definition.  Modified test 
beaninfo data files to reflect the presence of this new property setter.

Added:
    incubator/beehive/trunk/samples/controls-spring/
    incubator/beehive/trunk/samples/controls-spring/README.TXT
    incubator/beehive/trunk/samples/controls-spring/external/
    incubator/beehive/trunk/samples/controls-spring/external/spring-1.1.5.jar   
(with props)
    incubator/beehive/trunk/samples/controls-spring/integration/
    incubator/beehive/trunk/samples/controls-spring/integration/build.xml
    incubator/beehive/trunk/samples/controls-spring/integration/src/
    incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/org.apache.beehive.controls.spi.bean.ControlFactory
    incubator/beehive/trunk/samples/controls-spring/integration/src/org/
    incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/
    
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/SpringControlFactory.java
    incubator/beehive/trunk/samples/controls-spring/web/
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/applicationContext.xml
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/lib/
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/build.xml
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/AdultImpl.java
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/MinorImpl.java
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/Person.java
    
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/PersonImpl.java
    incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/web.xml
    incubator/beehive/trunk/samples/controls-spring/web/familyTree.jsp
Modified:
    
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseProperties.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.bat
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.sh
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo

Modified: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseProperties.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseProperties.java?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseProperties.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseProperties.java
 Thu May  5 13:57:01 2005
@@ -28,7 +28,7 @@
 /**
  * Base properties that are present intrinsically on all controls.
  */
[EMAIL PROTECTED]( hasSetters=false )
[EMAIL PROTECTED]
 @Target( {ElementType.TYPE, ElementType.FIELD} )
 @Retention( RetentionPolicy.RUNTIME )
 public @interface BaseProperties

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
 Thu May  5 13:57:01 2005
@@ -135,49 +135,6 @@
             _properties = new BeanPropertyMap(classMap);
         }
 
-        //
-        // See if the property map specifies an implementation class for the 
control; if not, use default binding.
-        //
-
-        String implBinding = null;
-        BaseProperties bp = _properties.getPropertySet( BaseProperties.class );
-        if ( bp != null )
-            implBinding = bp.controlImplementation();
-        else
-            implBinding = 
ControlBeanContext.getDefaultControlBinding(_controlIntf);
-
-        // REVIEW: consider surfacing ClassNotFoundException in the generated 
bean's ctors.  
-        // Is that a violation of JavaBean spec for the signature of bean 
ctors?
-
-        try
-        {
-            _implClass = _controlIntf.getClassLoader().loadClass(implBinding);
-
-            //
-            // Validate that the specified implementation class has an 
@ControlImplementation
-            // annotation, else downstream requirements (such as having a 
valid control init
-            // class) will not be met.
-            //
-            if (_implClass.getAnnotation(ControlImplementation.class) == null)
-            {
-                throw new 
ControlException("@org.apache.beehive.controls.api.bean.ControlImplementation 
annotation is missing from control implementation class: " + 
_implClass.getName());
-            }
-        }
-        catch (ClassNotFoundException cnfe)
-        {
-            throw new ControlException("Unable to load control implementation: 
"  + implBinding, cnfe);
-        }
-
-        //
-        // Cache the threading policy associated with the impl
-        //
-        Threading thr = (Threading)_implClass.getAnnotation(Threading.class);
-        if ( thr != null )
-            _threadingPolicy = thr.value();
-        else
-            _threadingPolicy = ThreadingPolicy.SINGLE_THREADED;    // default 
to single-threaded
-
-        ensureThreadingBehaviour();
     }
 
     /**
@@ -290,6 +247,48 @@
     {
         if (_control == null)
         {
+            //
+            // See if the property map specifies an implementation class for 
the control; 
+            // if not, use default binding.
+            //
+
+            String implBinding = null;
+            BaseProperties bp = _properties.getPropertySet( 
BaseProperties.class );
+            if ( bp != null )
+                implBinding = bp.controlImplementation();
+            else
+                implBinding = 
ControlBeanContext.getDefaultControlBinding(_controlIntf);
+
+            try
+            {
+                _implClass = 
_controlIntf.getClassLoader().loadClass(implBinding);
+
+                //
+                // Validate that the specified implementation class has an 
@ControlImplementation
+                // annotation, else downstream requirements (such as having a 
valid control init
+                // class) will not be met.
+                //
+                if (_implClass.getAnnotation(ControlImplementation.class) == 
null)
+                {
+                    throw new 
ControlException("@org.apache.beehive.controls.api.bean.ControlImplementation 
annotation is missing from control implementation class: " + 
_implClass.getName());
+                }
+            }
+            catch (ClassNotFoundException cnfe)
+            {
+                throw new ControlException("Unable to load control 
implementation: "  + implBinding, cnfe);
+            }
+
+            //
+            // Cache the threading policy associated with the impl
+            //
+            Threading thr = 
(Threading)_implClass.getAnnotation(Threading.class);
+            if ( thr != null )
+                _threadingPolicy = thr.value();
+            else
+                _threadingPolicy = ThreadingPolicy.SINGLE_THREADED;    // 
default to single-threaded
+
+            ensureThreadingBehaviour();
+
             try
             {
                 //
@@ -981,10 +980,10 @@
 
     /**
      * The threading policy associated with the control implementation wrapped 
by this
-     * ControlBean.  Initialized to null in order to avoid prematurely 
assuming single-threadedness
-     * during bean hookup.
+     * ControlBean.  Initialized to MULTI_THREADED in order to assume 
multi-threadedness
+     * until a bean is associated with a specific (potentially 
single-threaded) implementation.
      */
-    transient private ThreadingPolicy _threadingPolicy = null;
+    transient private ThreadingPolicy _threadingPolicy = 
ThreadingPolicy.MULTI_THREADED;
 
     /**
      *  Contains the per-instance properties set for this ControlBean.

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat
 Thu May  5 13:57:01 2005
@@ -2,5 +2,5 @@
 REM
 REM Usage: BeanInfo.bat <class>
 REM
-set CTRLROOT=%BEEHIVE_HOME%\controls
-java -classpath 
%CTRLROOT%\test\build\classes\beans;%CTRLROOT%\build\jars\controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean
+set CTRLROOT=..\..\..\..\..\..\..\..\..\..
+java -classpath 
%CTRLROOT%\test\build\classes\beans;%CTRLROOT%\build\jars\beehive-controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh
 Thu May  5 13:57:01 2005
@@ -1,3 +1,3 @@
 #!/bin/sh
-export CTRLROOT=$BEEHIVE_HOME/controls
-java -classpath 
$CTRLROOT/test/build/classes/beans:$CTRLROOT/build/jars/controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean
+export CTRLROOT=../../../../../../../../../..
+java -classpath 
$CTRLROOT/test/build/classes/beans:$CTRLROOT/build/jars/beehive-controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo
 Thu May  5 13:57:01 2005
@@ -86,6 +86,9 @@
             <read-method>
                 public java.lang.String 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean.getControlImplementation()
             </read-method>
+            <write-method>
+                public synchronized void 
org.apache.beehive.controls.test.controls.beaninfo.InfoTestBean.setControlImplementation(java.lang.String)
+            </write-method>
             <feature-descriptor name="controlImplementation"
                 full-name="controlImplementation"
                 is-expert=false

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.bat
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.bat?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.bat
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.bat
 Thu May  5 13:57:01 2005
@@ -2,5 +2,5 @@
 REM
 REM Usage: BeanInfo.bat <class>
 REM
-set CTRLROOT=%BEEHIVE_HOME%\controls
-java -classpath 
%CTRLROOT%\test\build\classes\beans;%CTRLROOT%\build\jars\controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.inherit.%1Bean
+set CTRLROOT=%BEEHIVE_SRC%\controls
+java -classpath 
%CTRLROOT%\test\build\classes\beans;%CTRLROOT%\build\jars\beehive-controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.inherit.%1Bean

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.sh
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.sh?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.sh
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/BeanInfo.sh
 Thu May  5 13:57:01 2005
@@ -1,3 +1,3 @@
 #!/bin/sh
-export CTRLROOT=$BEEHIVE_HOME/controls
-java -classpath 
$CTRLROOT/test/build/classes/beans:$CTRLROOT/build/jars/controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.inherit.$1Bean
+export CTRLROOT=$BEEHIVE_SRC/controls
+java -classpath 
$CTRLROOT/test/build/classes/beans:$CTRLROOT/build/jars/beehive-controls.jar 
org.apache.beehive.controls.test.controls.util.ControlIntrospector 
org.apache.beehive.controls.test.controls.inherit.$1Bean

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo
 Thu May  5 13:57:01 2005
@@ -177,6 +177,9 @@
             <read-method>
                 public java.lang.String 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.getControlImplementation()
             </read-method>
+            <write-method>
+                public synchronized void 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.setControlImplementation(java.lang.String)
+            </write-method>
             <feature-descriptor name="controlImplementation"
                 full-name="controlImplementation"
                 is-expert=false

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo
 Thu May  5 13:57:01 2005
@@ -207,6 +207,9 @@
             <read-method>
                 public java.lang.String 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.getControlImplementation()
             </read-method>
+            <write-method>
+                public synchronized void 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.setControlImplementation(java.lang.String)
+            </write-method>
             <feature-descriptor name="controlImplementation"
                 full-name="controlImplementation"
                 is-expert=false

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo
 Thu May  5 13:57:01 2005
@@ -87,6 +87,9 @@
             <read-method>
                 public java.lang.String 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.getControlImplementation()
             </read-method>
+            <write-method>
+                public synchronized void 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.setControlImplementation(java.lang.String)
+            </write-method>
             <feature-descriptor name="controlImplementation"
                 full-name="controlImplementation"
                 is-expert=false

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo?rev=168407&r1=168406&r2=168407&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo
 Thu May  5 13:57:01 2005
@@ -147,6 +147,9 @@
             <read-method>
                 public java.lang.String 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.getControlImplementation()
             </read-method>
+            <write-method>
+                public synchronized void 
org.apache.beehive.controls.test.controls.inherit.Intf1Bean.setControlImplementation(java.lang.String)
+            </write-method>
             <feature-descriptor name="controlImplementation"
                 full-name="controlImplementation"
                 is-expert=false

Added: incubator/beehive/trunk/samples/controls-spring/README.TXT
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/README.TXT?rev=168407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/controls-spring/README.TXT (added)
+++ incubator/beehive/trunk/samples/controls-spring/README.TXT Thu May  5 
13:57:01 2005
@@ -0,0 +1,26 @@
+This sample directory contains examples of integrating Beehive Controls with 
the Spring Framework.  It uses the bean definition, instantiation, and 
configuration services of Spring to use JavaBeans that have been authored as 
Controls.
+
+DIRECTORIES:
+
+* external - contains the Spring jar file used by the sample.  This is the 
full Spring jar from the 1.1.5 distribution.
+
+* integration - contains the implementation of the ControlFactory SPI 
interface for controls, that will use Spring to instantiate and configure 
Controls.
+
+* web - sample webapp that uses Spring and Controls together.  The sample 
includes a basic Control type with properties modeling a Person that can nested 
children, two corresponding implementations (AdultImpl/MinorImpl), and provides 
a sample Spring bean definition (application.xml) and web application (web.xml) 
configuration files that show how configure Spring/Controls to be used 
together.  A simple JSP page (familyTree.jsp) demonstrates how the defined 
beans can be instantiated and used.
+
+BUILDING:
+
+The Spring integration jar can be built using the following commands:
+
+    cd integration
+    ant build
+
+The sample webapp can be built and deployed to a running Tomcat instance using:
+
+    cd web/WEB-INF/src
+    ant build
+    ant deploy
+
+Once deployed, the demo JSP page can be accessed at:
+
+    /springControls/familyTree.jsp

Added: incubator/beehive/trunk/samples/controls-spring/external/spring-1.1.5.jar
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/external/spring-1.1.5.jar?rev=168407&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
incubator/beehive/trunk/samples/controls-spring/external/spring-1.1.5.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/beehive/trunk/samples/controls-spring/integration/build.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/integration/build.xml?rev=168407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/controls-spring/integration/build.xml 
(added)
+++ incubator/beehive/trunk/samples/controls-spring/integration/build.xml Thu 
May  5 13:57:01 2005
@@ -0,0 +1,72 @@
+<?xml version="1.0" ?>
+
+<project name="spring-integration" default="usage">
+
+    <property environment="os"/>
+    <property name="beehive.src" value="../../.." />
+
+    <import file="${beehive.src}/beehive-imports.xml" />
+    <property name="servlet.runtime" value="tomcat"/>
+    <import file="${beehive.src}/ant/${servlet.runtime}-imports.xml"/>
+
+    <property name="source.dir" value="${basedir}/src"/>
+    <property name="build.dir" value="${basedir}/build"/>
+    <property name="build.classes" value="${build.dir}/classes"/>
+    <property name="build.lib" value="${build.dir}/lib"/>
+    <property name="build.jar" value="${build.lib}/beehive-spring.jar"/>
+
+    <path id="tools.dependency.path">
+        <pathelement location="${os.JAVA_HOME}/lib/tools.jar"/>
+    </path>
+
+    <path id="spring.dependency.path">
+        <pathelement location="${basedir}/../external/spring-1.1.5.jar"/>
+    </path>
+
+    <!--path id="controls.dependency.path">
+        <pathelement 
location="${os.BEEHIVE_HOME}/lib/controls/beehive-controls.jar"/>
+    </path!-->
+
+    <path id="build.classpath">
+        <path refid="tools.dependency.path"/>
+        <path refid="controls.dependency.path"/>
+        <path refid="spring.dependency.path"/>
+        <path refid="appserver.build.classpath"/>
+        <pathelement path="${build.classes}"/>
+    </path>
+
+    <target name="usage">
+        <echo message=""/>
+        <echo message=""/>
+        <echo message="Spring Integration Build file"/>
+        <echo 
message="================================================================"/>
+        <echo message="|                          Usage                        
       |"/>
+        <echo 
message="================================================================"/>
+        <echo 
message="----------------------------------------------------------------"/>
+        <echo message="|                      Standard Targets                 
       |"/>
+        <echo 
message="----------------------------------------------------------------"/>
+        <echo message="clean               - Delete all generated files"/>
+        <echo message="build               - build integration jar"/>
+        <echo 
message="----------------------------------------------------------------"/>
+    </target>
+
+    <target name="clean" description="Deletes all generated files">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <target name="dirs">
+        <mkdir dir="${build.classes}" />
+        <mkdir dir="${build.lib}" />
+    </target>
+
+    <target name="build" depends="dirs" description="Build Spring integration 
jar">
+        <javac srcdir="${source.dir}" destdir="${build.classes}"
+               classpathref="build.classpath" debug="on" />
+        <copy todir="${build.classes}" overwrite="true" >
+            <fileset dir="${source.dir}" includes="META-INF/**" />
+        </copy>
+        
+        <jar destfile="${build.jar}"  basedir="${build.classes}" />
+    </target>
+
+</project>

Added: 
incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/org.apache.beehive.controls.spi.bean.ControlFactory
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/org.apache.beehive.controls.spi.bean.ControlFactory?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/org.apache.beehive.controls.spi.bean.ControlFactory
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/integration/src/META-INF/services/org.apache.beehive.controls.spi.bean.ControlFactory
 Thu May  5 13:57:01 2005
@@ -0,0 +1 @@
+org.apache.beehive.samples.spring.factory.SpringControlFactory

Added: 
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/SpringControlFactory.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/SpringControlFactory.java?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/SpringControlFactory.java
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/integration/src/org/apache/beehive/samples/spring/factory/SpringControlFactory.java
 Thu May  5 13:57:01 2005
@@ -0,0 +1,220 @@
+package org.apache.beehive.samples.spring.factory;
+
+/*
+ * Copyright 2005  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:$
+ */
+
+import java.beans.beancontext.BeanContext;
+import java.lang.ref.SoftReference;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.ServletContext;
+
+import org.apache.beehive.controls.api.properties.PropertyMap;
+import org.apache.beehive.controls.api.bean.ControlBean;
+import org.apache.beehive.controls.api.bean.ControlExtension;
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.controls.api.ControlException;
+
+import org.apache.beehive.controls.spi.bean.ControlFactory;
+import org.apache.beehive.controls.spi.bean.JavaControlFactory;
+
+import org.apache.beehive.controls.runtime.servlet.ServletBeanContext;
+
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * The SpringControlFactory class is an implementation of the 
+ * <code>org.apache.beehive.controls.api.bean.ControlFactory</code> interface, 
that
+ * enables to be created and initialized from a Spring application context.
+ * <p>
+ * The SpringControlFactory class extends the basic Java instantation control 
factory
+ * class.  If no Spring bean definition exists for the requested control 
id/class
+ * combination, then basic Java instantation will be used.
+ * <p>
+ *
+ * @see org.apache.beehive.controls.spi.ControlFactory
+ * @see org.apache.beehive.controls.spi.JavaControlFactory
+ */
+public class SpringControlFactory extends JavaControlFactory
+{
+    /**
+     * Instantiates a new ControlBean of the requested class, using mechanisms 
provided
+     * by the Spring bean container.
+     *
+     * @param beanClass the ControlBean class to instantiate
+     * @param props an initial set of client-specified properties to associate 
with the
+     *              bean instance.   May be null.
+     * @param context the containing ControlBeanContext for the bean, if 
nested inside of
+     *                a container or other control.  May be null to use the 
current active
+     *                execution context.
+     * @param id the bean control ID.  Must be unique within the containing 
context.  If
+     *           null, a unique identifier will be auto-generated.
+     * @returns a new ControlBean instance of the requested class.
+     */
+    public <T extends ControlBean> T instantiate(Class<T> beanClass,
+                                                 PropertyMap props,
+                                                 ControlBeanContext context,
+                                                 String id)
+    {
+        T bean = null;
+        try
+        {
+            BeanFactory beanFactory = getBeanFactory(context);
+
+            //
+            // Look for a match in the bean factory based upon id
+            //
+            if (id != null) 
+            {
+                String fullID = null;
+                if (context != null && context.getControlBean() != null)
+                {
+                    String parentID = context.getControlBean().getControlID();
+                    if (parentID != null)
+                        fullID = parentID + ControlBean.IDSeparator + id;
+                }
+
+                //
+                // Check absolute ID first, then relative ID for a match
+                //
+                if (fullID != null && beanFactory.containsBean(fullID))
+                    bean = (T)beanFactory.getBean(fullID, beanClass);
+                else if (beanFactory.containsBean(id))
+                    bean = (T)beanFactory.getBean(id, beanClass);
+            }
+
+            //
+            // Look for a match based upon bean class name
+            //
+            String beanClassName = beanClass.getName();
+            if (bean == null && beanFactory.containsBean(beanClassName))
+                bean = (T)beanFactory.getBean(beanClassName, beanClass);
+
+            if (bean != null)
+            {
+                //
+                // Add the bean to the context passed to the constructor
+                //
+                if (context != null)
+                    context.add(bean);
+
+                //
+                // Spring doesn't provide any mechanism to pass dynamic 
constructor args
+                // to Spring bean factory methods.
+                //
+                if (props != null)
+                    throw new ControlException("Providing a PropertyMap to the 
bean constructor is not supported by SpringControlFactory");
+            }
+            else
+            {
+                //
+                // Fall back to using standard Java instantation if no Spring 
configuration
+                // could be found.
+                // TODO: Have a configuration option where this results in a 
failure, to avoid
+                // masking misconfiguration issues if the expectation is that 
all usage of
+                // Controls is configured via Spring.
+                //
+                bean = super.instantiate(beanClass, props, context, id);
+            }
+        }
+        catch (Exception e)
+        {
+            throw new ControlException("Exception creating ControlBean", e);
+        }
+
+        return bean;
+    }
+
+    /**
+     * Returns the Spring BeanFactory instance that should be associated with 
the current
+     * ControlBeanContext.  Returns null if no context could be located.
+     *
+     * This is marked 'protected' to enable alternative implementations to 
overrride the
+     * behavior for how a factory will be obtained.
+     */
+    protected BeanFactory getBeanFactory(ControlBeanContext context)
+    {
+        BeanFactory beanFactory = null;
+
+        //
+        // Currently, the thread contex loader is used as the key for a class 
loader to
+        // bean factory cache.   This mirrors the behavior of 
ClassPathXmlApplicationContext
+        // below, which is used to load the BeanFactory.
+        //
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        SoftReference<BeanFactory> bfRef = _beanFactoryCache.get(cl);
+        if (bfRef != null)
+            beanFactory = bfRef.get();
+        if (beanFactory != null)
+            return beanFactory;
+
+        //
+        // If no context was provided to the constructor, associate with the 
local
+        // thread context
+        //
+        if (context == null)
+            context = ControlThreadContext.getContext();
+
+        //
+        // Use special handling of the webapp case, to enable the 'standard' 
Spring webapp
+        // config (WEB-INF/applicationContext.xml, or whatever has been 
configured in the
+        // loader servlet) to be used.
+        //
+        while (context != null && !(context instanceof ServletBeanContext))
+        {
+            BeanContext parentContext = context.getBeanContext();
+            if (parentContext instanceof ControlBeanContext)
+                context = (ControlBeanContext)parentContext;
+            else
+                context = null;
+        }
+        if (context != null)
+        {
+            ServletContext servletContext = 
((ServletBeanContext)context).getServletContext();
+            if (servletContext != null)
+                beanFactory = 
WebApplicationContextUtils.getWebApplicationContext(servletContext);
+        }
+    
+        //
+        // Otherwise, simply use a ClassLoader-based search for 
applicationContext.xml
+        //
+        if (beanFactory == null)
+        {
+            beanFactory = new ClassPathXmlApplicationContext(
+                                                        new String[] 
{"applicationContext.xml"});
+        }
+
+        //
+        // Write the resulting bean factory back (or null) into the bean 
factory cache
+        //
+        _beanFactoryCache.put(new SoftReference<ClassLoader>(cl), 
+                              new SoftReference<BeanFactory>(beanFactory));
+        return beanFactory;
+    }
+
+    //
+    // Cache the mapping from a given class loader to the associated 
BeanFactory to use
+    // when instantiating beans within it.
+    //
+    ConcurrentHashMap<SoftReference<ClassLoader>,SoftReference<BeanFactory>> 
_beanFactoryCache =
+        new 
ConcurrentHashMap<SoftReference<ClassLoader>,SoftReference<BeanFactory>>();
+}

Added: 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/applicationContext.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/applicationContext.xml?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/applicationContext.xml
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/applicationContext.xml
 Thu May  5 13:57:01 2005
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd";>
+<!-- This is the sample Spring definition file used by the Controls-Spring 
integration -->
+<!-- sample webapp. These bean definitions will be used for Controls that are 
created  -->
+<!-- either directly or indirectly by familyTree.jsp                           
        -->
+<beans>
+    <bean id="root" parent="AdultBean">
+        <constructor-arg index="1"><value>root</value></constructor-arg>
+        <property name="firstName"><value>Don</value></property>
+        <property name="lastName"><value>Marvin</value></property>
+        <property name="age"><value>70</value></property>
+        <property name="children">
+            <list>
+                <value>Kyle</value>
+                <value>Dean</value>
+            </list>
+        </property>
+    </bean>
+
+    <bean name="root/Kyle" parent="AdultBean">
+        <constructor-arg index="1"><value>Kyle</value></constructor-arg>
+        <property name="firstName"><value>Kyle</value></property>
+        <property name="lastName"><value>Marvin</value></property>
+        <property name="age"><value>40</value></property>
+        <property name="children">
+            <list>
+                <value>Kayla</value>
+                <value>Kate</value>
+            </list>
+        </property>
+    </bean>
+
+    <bean name="root/Dean" parent="AdultBean">
+        <constructor-arg index="1"><value>Dean</value></constructor-arg>
+        <property name="firstName"><value>Dean</value></property>
+        <property name="lastName"><value>Marvin</value></property>
+        <property name="age"><value>42</value></property>
+        <property name="children">
+            <list>
+                <value>Grant</value>
+                <value>Megan</value>
+            </list>
+        </property>
+    </bean>
+
+
+    <!-- This is an example of a match against an absolute control ID.  It 
will be -->
+    <!-- used for the control with an ID of "Kayla" nested inside of the 
control   -->
+    <!-- with an ID of "Kyle" nested inside of the control with the ID of 
"root"   -->
+    <bean name="root/Kyle/Kayla" parent="MinorBean">
+        <constructor-arg index="1"><value>Kayla</value></constructor-arg>
+        <property name="firstName"><value>Kayla</value></property>
+        <property name="lastName"><value>Marvin</value></property>
+        <property name="age"><value>13</value></property>
+        <property name="gender"><value>female</value></property>
+    </bean>
+
+    <!-- This is an example of a match against a relative name.   Any 
PersonBean    -->
+    <!-- named "Kate" will use this definition, unless an absolute ID match 
exists -->
+    <bean name="Kate" parent="MinorBean">
+        <constructor-arg index="1"><value>Kate</value></constructor-arg>
+        <property name="firstName"><value>Kate</value></property>
+        <property name="lastName"><value>Marvin</value></property>
+        <property name="age"><value>11</value></property>
+        <property name="gender"><value>female</value></property>
+    </bean>
+
+    <!-- This bean definition will be used when instantiating any Person bean 
that  -->
+    <!-- does not have a specific definition.  Note that the defnition name is 
the  -->
+    <!-- bean class name, meaning it will match all beans of this type where a 
more -->
+    <!-- exact id match fails.   This definition will be used when 
instantiating    -->
+    <!-- the beans for root/Dean/Grant and root/Dean/Megan, since no explicit 
defn  -->
+    <!-- exists with these names --> 
+    <bean id="org.apache.beehive.samples.spring.control.PersonBean" 
parent="AdultBean"
+          singleton="false">
+        <property name="firstName"><value>Unknown</value></property>
+        <property name="lastName"><value>Unknown</value></property>
+        <property name="gender"><value>unknown</value></property>
+        <property name="age"><value>0</value></property>
+    </bean>
+
+    <!-- This bean definition acts as an abstract template for constructing 
PersonBean -->
+    <!-- instances that are implemented as adults.                             
        -->
+    <!-- In the future, abstract templates such as this one could be 
auto-generated    -->
+    <bean id="AdultBean" 
class="org.apache.beehive.samples.spring.control.PersonBean"
+          abstract="true" singleton="false" >
+        <constructor-arg index="0"><null/></constructor-arg>
+        <constructor-arg index="1"><null/></constructor-arg> 
+        <constructor-arg index="2"><null/></constructor-arg>
+        <property name="controlImplementation">
+            <value>org.apache.beehive.samples.spring.control.AdultImpl</value>
+        </property>
+    </bean>
+
+    <!-- This bean definition acts as an abstract template for constructing 
PersonBean -->
+    <!-- instances that are implemented as minors                              
        -->
+    <bean id="MinorBean" 
class="org.apache.beehive.samples.spring.control.PersonBean"
+          abstract="true" singleton="false" >
+        <constructor-arg index="0"><null/></constructor-arg>
+        <constructor-arg index="1"><null/></constructor-arg>
+        <constructor-arg index="2"><null/></constructor-arg>
+        <property name="controlImplementation">
+            <value>org.apache.beehive.samples.spring.control.MinorImpl</value>
+        </property>
+    </bean>
+
+</beans>

Added: incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/build.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/build.xml?rev=168407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/build.xml 
(added)
+++ incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/build.xml 
Thu May  5 13:57:01 2005
@@ -0,0 +1,65 @@
+<?xml version="1.0" ?>
+
+<!--
+   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:$
+ -->
+
+<project name="Beehive Spring-Controls webapp sample" default="build" 
basedir="../..">
+
+  <import file="../../../../../beehive-imports.xml" />
+
+  <property name="context.path" value="springControls"/>
+
+  <!-- =========================================== -->
+  <!-- deploy targets - move the app to the server -->
+  <!-- =========================================== -->
+  
+  <target name="deploy" description="Deploy the webapp to a running server">
+    <deploy-webapp webappDir="${basedir}" contextPath="${context.path}"/>
+  </target>
+
+  <target name="undeploy" description="Undeploy the webapp from a running 
server">
+    <undeploy-webapp contextPath="${context.path}"/>
+  </target>
+
+  <target name="redeploy" description="Redeploy the webapp on a running 
server">
+    <redeploy-webapp contextPath="${context.path}"/>
+  </target>
+  
+  <!-- ========================================= -->
+  <!-- build - build the webapp                  -->
+  <!-- ========================================= -->
+
+  <target name="build" description="Build the webapp">
+    <deploy-controls webappDir="${basedir}"/>
+    <copy todir="${basedir}/WEB-INF/lib/" overwrite="true">
+        <fileset dir="${basedir}/../integration/build/lib" includes="**" />
+        <fileset dir="${basedir}/../external" includes="**" />
+    </copy>
+    <build-webapp webappDir="${basedir}"/>
+  </target>
+  
+  <!-- ========================================= -->
+  <!-- clean - clean the webapp                  -->
+  <!-- ========================================= -->
+
+  <target name="clean" description="Clean the webapp">
+    <clean-webapp webappDir="${basedir}"/>
+    <delete dir="WEB-INF" includes="lib/**,classes/**" />
+  </target>
+  
+</project>

Added: 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/AdultImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/AdultImpl.java?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/AdultImpl.java
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/AdultImpl.java
 Thu May  5 13:57:01 2005
@@ -0,0 +1,51 @@
+package org.apache.beehive.samples.spring.control;
+
+/*
+ * Copyright 2005  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:$
+ */
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.beehive.controls.api.bean.Controls;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.events.EventHandler;
+
[EMAIL PROTECTED]
+public class AdultImpl extends PersonImpl implements Person, 
java.io.Serializable
+{
+    @Context ControlBeanContext context;
+
+    @EventHandler(field="context", 
+                  eventSet=ControlBeanContext.LifeCycle.class, 
eventName="onCreate")
+    public void onCreate()
+    {
+        Attributes attributes = 
context.getControlPropertySet(Person.Attributes.class);
+        if (attributes.age() > 0 && attributes.age() <= 17)
+            throw new RuntimeException("Person is a minor, not an adult!");
+    }
+
+    public PersonBean getChild(String name) 
+    { 
+        PersonBean child = (PersonBean)context.getBean(name);
+        if (child == null)
+            child = Controls.instantiate(PersonBean.class, null, context, 
name);
+        return child;
+    }
+}
+

Added: 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/MinorImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/MinorImpl.java?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/MinorImpl.java
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/MinorImpl.java
 Thu May  5 13:57:01 2005
@@ -0,0 +1,44 @@
+package org.apache.beehive.samples.spring.control;
+
+/*
+ * Copyright 2005  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:$
+ */
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.events.EventHandler;
+
[EMAIL PROTECTED]
+public class MinorImpl extends PersonImpl implements Person, 
java.io.Serializable
+{
+    @Context ControlBeanContext context;
+
+    @EventHandler(field="context", 
+                  eventSet=ControlBeanContext.LifeCycle.class, 
eventName="onCreate")
+    public void onCreate()
+    {
+        Family family = context.getControlPropertySet(Person.Family.class);
+        if (family.children().length != 0)
+            throw new RuntimeException("Minors really shouldn't be having 
children");
+    }
+
+    public PersonBean getChild(String name) { return null; }
+}
+

Added: 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/Person.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/Person.java?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/Person.java
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/Person.java
 Thu May  5 13:57:01 2005
@@ -0,0 +1,62 @@
+package org.apache.beehive.samples.spring.control;
+
+/*
+ * Copyright 2005  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:$
+ */
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
+
[EMAIL PROTECTED]
+public interface Person
+{
+    @PropertySet
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface Name
+    {
+        String lastName();    
+        String firstName();
+    }
+
+    //
+    // Ideally, these would be an enumerated type; but Spring does not yet 
have a config model
+    // for bean properties that are JDK 1.5 enumerations
+    //
+    final public String MALE= "male";
+    final public String FEMALE= "female";
+
+    @PropertySet
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface Attributes
+    {
+        String gender() default MALE;
+        int age() default 0;
+    }
+
+    @PropertySet
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface Family
+    {
+        String [] children() default {};
+    }
+
+    public String getFullName();
+    public PersonBean getChild(String name);
+}
+

Added: 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/PersonImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/PersonImpl.java?rev=168407&view=auto
==============================================================================
--- 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/PersonImpl.java
 (added)
+++ 
incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/src/org/apache/beehive/samples/spring/control/PersonImpl.java
 Thu May  5 13:57:01 2005
@@ -0,0 +1,47 @@
+package org.apache.beehive.samples.spring.control;
+
+/*
+ * Copyright 2005  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:$
+ */
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.events.EventHandler;
+
[EMAIL PROTECTED]
+abstract public class PersonImpl implements Person, java.io.Serializable
+{
+    @Context ControlBeanContext context;
+
+    @EventHandler(field="context", 
+                  eventSet=ControlBeanContext.LifeCycle.class, 
eventName="onCreate")
+    public void onCreate()
+    {
+        Attributes attributes = 
context.getControlPropertySet(Person.Attributes.class);
+        if (!attributes.gender().equals(Person.MALE) && 
!attributes.gender().equals(Person.FEMALE))
+            throw new RuntimeException("Invalid gender:" + 
attributes.gender());
+    }
+
+    public String getFullName()
+    {
+        Name name = context.getControlPropertySet(Person.Name.class); 
+        return name.firstName() + " " + name.lastName();
+    }
+}

Added: incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/web.xml?rev=168407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/web.xml (added)
+++ incubator/beehive/trunk/samples/controls-spring/web/WEB-INF/web.xml Thu May 
 5 13:57:01 2005
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
+
+<web-app>
+
+  <display-name>Beehive Controls-Spring Integration Sample App</display-name>
+    
+  <filter>
+    <filter-name>ControlFilter</filter-name>
+    
<filter-class>org.apache.beehive.controls.runtime.servlet.ControlFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>ControlFilter</filter-name>
+    <url-pattern>*.jsp</url-pattern>
+  </filter-mapping>
+
+  <context-param>
+    <param-name>contextConfigLocation</param-name>
+    <param-value>/WEB-INF/applicationContext.xml</param-value>
+  </context-param>
+
+  <listener>
+    
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+  </listener>
+
+  <session-config>
+    <!-- Default to 5 minute session timeouts -->
+    <session-timeout>5</session-timeout>
+  </session-config>
+
+</web-app>

Added: incubator/beehive/trunk/samples/controls-spring/web/familyTree.jsp
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/controls-spring/web/familyTree.jsp?rev=168407&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/controls-spring/web/familyTree.jsp (added)
+++ incubator/beehive/trunk/samples/controls-spring/web/familyTree.jsp Thu May  
5 13:57:01 2005
@@ -0,0 +1,46 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8" session="true" 
+         import="org.apache.beehive.controls.api.bean.Controls,
+                 org.apache.beehive.controls.api.context.ControlThreadContext,
+                 org.apache.beehive.samples.spring.control.PersonBean,
+                 org.apache.beehive.samples.spring.control.AdultImpl" %>
+
+<% response.setHeader("Cache-Control","no-cache"); %>
+
+<%!
+    /**
+     * A simple util method that will take a PersonBean and generated 
formatted HTML output
+     * describing the person and any nested children
+     */
+    public void showPerson(JspWriter out,  PersonBean person) throws 
java.io.IOException
+    {
+        out.println("Name: " + person.getFullName() + "<br>");
+        out.println("Gender: " + person.getGender() + "<br>");
+        out.println("Age: " + person.getAge() + "<br>");
+        out.println("ID: "   + person.getControlID() + "<br>");
+        String [] children = person.getChildren();
+        if (children.length != 0)
+        {
+            out.println("Children: <br>");
+            out.println("<ul>");
+            for (int i = 0; i < children.length; i++)
+            {
+                PersonBean child = person.getChild(children[i]);
+                out.println("<li>" + children[i] + "<br>");
+                if (child != null)
+                    showPerson(out, child);
+            }
+            out.println("</ul>");
+        }
+    }
+%>
+
+<%
+    /**
+     * Use the Controls.instantiate API to create the root of the tree.  This 
corresponds
+     * the the "root" bean definition in application.xml.  The Spring 
BeanFactory APIs could
+     * also be used to instantiate this control.
+     */
+    PersonBean root = Controls.instantiate(PersonBean.class, null,
+                                           ControlThreadContext.getContext(), 
"root");
+    showPerson(out, root);
+%>


Reply via email to