Author: kylem
Date: Fri Apr 29 15:02:32 2005
New Revision: 165348

URL: http://svn.apache.org/viewcvs?rev=165348&view=rev
Log:
Converted the pageflow runtime over to using Controls.initializeClient() [ the 
standard codegen init model ] instead of direct initialization.  This resolved 
issues with event handling on pageflows.  Required some minor tweaks to the 
client codegen templates based upon unique requirements for pageflows.

Modified:
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlClient.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm
    
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlClient.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlClient.java?rev=165348&r1=165347&r2=165348&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlClient.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlClient.java
 Fri Apr 29 15:02:32 2005
@@ -65,6 +65,40 @@
     }
 
     /**
+     * Returns true if this type of client requires that nested controls have 
unique identifiers
+     */
+    protected boolean needsUniqueID()
+    {
+        //
+        // BUGBUG:
+        // Pageflows need to have a more unique ID generated for fields, 
because multiple pageflows
+        // may be shared within a single ControlContainerContext, and just 
using the field name could
+        // result in collisions.  A better (and less hard-wired) approach is 
needed than searching for
+        // specific annotations.   Perhaps a model that enables particular 
client types to subclass
+        // AptControlClient and override getID() would be much better.
+        //
+        for (AnnotationMirror annotMirror : _clientDecl.getAnnotationMirrors())
+        {
+            String annotType = annotMirror.getAnnotationType().toString();
+            if 
(annotType.equals("org.apache.beehive.netui.pageflow.annotations.Jpf.Controller")
 ||
+                
annotType.equals("org.apache.beehive.netui.pageflow.annotations.Jpf.Backing"))
+                return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns a unique ID for a control field
+     */
+    public String getID(AptControlField control)
+    {
+        if (!needsUniqueID())
+            return "\"" + control.getName() + "\""; 
+
+        return "client.getClass() + \"@\" + client.hashCode() + \"." + 
control.getName() + "\"";
+    }
+
+    /**
      * Returns the list of ControlFields declared directly by this ControlImpl
      */
     public ArrayList<AptControlField> getControls() { return _controls; }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm?rev=165348&r1=165347&r2=165348&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm
 Fri Apr 29 15:02:32 2005
@@ -105,10 +105,11 @@
 ## if an external initializer (like java.beans.XMLDecoder) has already 
instantiated a configured
 ## bean into the context.
 ##
-#macro (initControl $control)
-    $control.controlBean.className $control.localName = (cbc == null ? null : 
($control.controlBean.className)cbc.getBean("$control.name"));
+#macro (initControl $client $control)
+    id = ${client.getID($control)};
+    $control.controlBean.className $control.localName = (cbc == null ? null : 
($control.controlBean.className)cbc.getBean(id));
     if ($control.localName == null)
-        $control.localName = (${control.controlBean.className}) 
Controls.instantiate(${control.controlBean.className}.class, 
getAnnotationMap(cbc, ${control.reflectField}), cbc, "$control.name" );
+        $control.localName = (${control.controlBean.className}) 
Controls.instantiate(${control.controlBean.className}.class, 
getAnnotationMap(cbc, ${control.reflectField}), cbc, id );
     #initEventAdaptors($control)
 
     #if ($control.hasVersionRequired())
@@ -131,18 +132,20 @@
     {
         try
         {
+            String id;
             #foreach ($control in $client.Controls)
             #if ($velocityCount == 1)
             //
             // Initialize any nested controls used by the client
             //
             #end 
-            #initControl($control) 
+            #initControl($client $control) 
             #end
         }
         catch (RuntimeException re) { throw re; }
         catch (Exception e)
         {
+e.printStackTrace();
             throw new ControlException("Initializer failure", e);
         }
     }

Modified: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java?rev=165348&r1=165347&r2=165348&view=diff
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
 Fri Apr 29 15:02:32 2005
@@ -3,7 +3,8 @@
 /**
  * A listener class for event raised by InnerControl
  */
-public class InnerControlEventListener implements 
InnerControl.Activity,InnerControl.Action
+public class InnerControlEventListener implements 
InnerControl.Activity,InnerControl.Action,
+             java.io.Serializable
 {
 
        private boolean wakeupReceived=false;

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java?rev=165348&r1=165347&r2=165348&view=diff
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java
 Fri Apr 29 15:02:32 2005
@@ -139,27 +139,6 @@
         return beanContext;
     }
     
-    /**
-     * @param controlClassName
-     * @param isBeanClass If <code>true</code>, <code>controlClassName</code> 
refers to a concrete (generated) control
-     *            bean class; if <code>false</code>, it refers to a control 
interface, and "Bean" will be appended to
-     *            get the bean class name.
-     * @param controlID
-     * @param properties
-     * @return ControlBean
-     */ 
-    private static ControlBean createControl( String controlClassName, boolean 
isBeanClass, String controlID,
-                                              PropertyMap properties, 
ControlBeanContext beanContext )
-        throws ClassNotFoundException
-    {
-        if ( ! isBeanClass ) controlClassName += "Bean";
-        
-        Object instance = Controls.instantiate( 
Thread.currentThread().getContextClassLoader(), controlClassName, 
-                                                properties, beanContext, 
controlID );
-        assert instance instanceof ControlBean : instance.getClass().getName();
-        return ( ControlBean ) instance;
-    }
-    
     public static void destroyControl( Object controlInstance )
     {
         assert controlInstance instanceof ControlBean : 
controlInstance.getClass().getName();
@@ -238,43 +217,14 @@
         request = PageFlowUtils.unwrapMultipart( request );
         ControlBeanContext beanContext = getControlBeanContext( request, 
response, servletContext, false );
         assert beanContext != null : "ControlBeanContext was not initialized 
by PageFlowRequestProcessor";
-        String classID = controlClientClass.getName();
-        
-        for ( Iterator i = controlFields.entrySet().iterator(); i.hasNext(); )
+        try
         {
-            Map.Entry entry = ( Map.Entry ) i.next();
-            Field field = ( Field ) entry.getKey();
-
-            //
-            // We don't want the field to be transient -- the reference should 
not go away when this
-            // object is serialized/deserialized.  The checker should enforce 
this.
-            //
-            assert ! Modifier.isTransient( field.getModifiers() ) : 
field.getName();
-            
-            try
-            {
-                if ( field.get( controlClient ) == null )      // make sure 
it's not already initialized
-                {
-                    if ( _log.isTraceEnabled() )
-                    {
-                        _log.trace( "Initializing field " + field.getName() + 
" (" + field.getType().getName()
-                                    + ") with a Java Control..." );
-                    }
-                    
-                    PropertyMap propertyMap = ( PropertyMap ) entry.getValue();
-                    Class fieldType = field.getType();
-                    String controlID = getControlID( field, classID, 
controlClient.hashCode() );
-                    boolean isControlBeanClass = ! fieldType.isInterface();
-                    ControlBean bean =
-                        createControl( fieldType.getName(), 
isControlBeanClass, controlID, propertyMap, beanContext );
-                    field.set( controlClient, bean );
-                }
-            }
-            catch ( Exception e )
-            {
-                _log.error( "Exception occurred while initializing control 
field " + field.getName(), e );
-                throw new ControlFieldInitializationException( 
field.getName(), controlClient, e );
-            }
+            Controls.initializeClient(null, controlClient, beanContext);
+        }
+        catch ( Exception e )
+        {
+            _log.error( "Exception occurred while initializing controls", e);
+            throw new ControlFieldInitializationException( 
controlClientClass.getName(), controlClient, e );
         }
     }
     
@@ -304,17 +254,5 @@
                 _log.error( "Exception while uninitializing Java Control " + 
controlField.getName(), e );
             }            
         }
-    }
-    
-    /**
-     * Create a unique ID for a given Java Control field.
-     */ 
-    private static String getControlID( Field controlField, String classID, 
int instanceID )
-    {
-        InternalStringBuilder controlID = new InternalStringBuilder();
-        controlID.append( classID );                                  // 
classname
-        controlID.append( '@' ).append( instanceID );                 // 
instance ID
-        controlID.append( '.' ).append( controlField.getName() );     // name 
of the control field
-        return controlID.toString();
     }
 }


Reply via email to