Author: kylem
Date: Fri Jan 14 08:48:32 2005
New Revision: 125183

URL: http://svn.apache.org/viewcvs?view=rev&rev=125183
Log:
Added support for persisting listener relationships, and persistence delegate 
classes for generated adaptors.   There is now a checkin test that encodes to 
XML, then decodes from XML a control containing two nested controls, some 
non-default state, and several listener relationships.   After decode, some 
basic tests are made to see if state/relationships have been preserved.

Added:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AdaptorPersistenceDelegate.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotatedElementMapPersistenceDelegate.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/BeanPersistenceDelegate.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/EventAdaptor.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/encoding/
   
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/encoding/EncodingTest.java
Removed:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlPersistenceDelegate.java
Modified:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
   
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/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

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AdaptorPersistenceDelegate.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AdaptorPersistenceDelegate.java?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AdaptorPersistenceDelegate.java
       Fri Jan 14 08:48:32 2005
@@ -0,0 +1,73 @@
+package org.apache.beehive.controls.runtime.bean;
+/*
+ * 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:$
+ */
+
+import java.beans.BeanInfo;
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.Expression;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PersistenceDelegate;
+import java.beans.PropertyDescriptor;
+import java.beans.Statement;
+import java.beans.XMLEncoder;
+import java.util.Set;
+
+import org.apache.beehive.controls.api.ControlException;
+
+/**
+ * The AdaptorPersistenceDelegate class supports the XML persistance of 
Control Client Event 
+ * Adaptor instances by implementing the 
<code>java.beans.PersistenceDelegate</b> API, and 
+ * overriding the default persistance algorithm based upon the runtime 
structure for Controls.
+ */
+public class AdaptorPersistenceDelegate extends DefaultPersistenceDelegate
+{
+    /**
+     * PersistenceDelegate.instantiate()
+     */
+    protected Expression instantiate(Object oldInstance, Encoder out)
+    {
+        if (! (oldInstance instanceof EventAdaptor))
+            return super.instantiate(oldInstance, out);
+
+        //
+        // An implementation instance is actually constructed at decode time 
by calling
+        // ControlBean.ensureControl on the parent bean.  This will create a 
new impl
+        // instance and run the impl initializer on it.
+        //
+        return new Expression(oldInstance, oldInstance.getClass(), "new", 
+                              new Object[] { 
((EventAdaptor)oldInstance).getClient() });
+    }
+
+    /**
+     * PersistenceDelegate.initialize()
+     */
+    protected void initialize(Class<?> type, Object oldInstance, Object 
newInstance, Encoder out)
+    {
+        super.initialize(type, oldInstance, newInstance, out);
+    }
+
+    /**
+     * PersistenceDelegate.writeObject()
+     */
+    public void writeObject(Object oldInstance, Encoder out)
+    {
+        super.writeObject(oldInstance, out);
+    }
+}

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotatedElementMapPersistenceDelegate.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotatedElementMapPersistenceDelegate.java?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotatedElementMapPersistenceDelegate.java
   Fri Jan 14 08:48:32 2005
@@ -0,0 +1,42 @@
+package org.apache.beehive.controls.runtime.bean;
+/*
+ * 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:$
+ */
+
+import java.beans.PersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.Expression;
+
+import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
+
+/**
+ * The AnnotatedElementMapPersistenceDelegate is an XMLEncoder 
PersistenceDelegate for
+ * the 
<code>org.apache.beehive.controls.api.properties.AnnotatedElementMap</code>
+ * class.
+ */
+public class AnnotatedElementMapPersistenceDelegate extends PersistenceDelegate
+{
+    protected Expression instantiate(Object oldInstance, Encoder out)
+    {
+        //
+        // Modify the default constructor to pass in the AnnotatedElement 
wrapped by the map
+        //
+        AnnotatedElementMap aem = (AnnotatedElementMap)oldInstance;
+        return new Expression(aem, aem.getClass(), "new",
+                              new Object [] { aem.getAnnotatedElement() });
+    }
+}

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/BeanPersistenceDelegate.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/BeanPersistenceDelegate.java?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/BeanPersistenceDelegate.java
  Fri Jan 14 08:48:32 2005
@@ -0,0 +1,312 @@
+package org.apache.beehive.controls.runtime.bean;
+/*
+ * 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:$
+ */
+
+import java.beans.BeanInfo;
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.EventSetDescriptor;
+import java.beans.Expression;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PersistenceDelegate;
+import java.beans.PropertyDescriptor;
+import java.beans.Statement;
+import java.beans.XMLEncoder;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.beehive.controls.api.ControlException;
+import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
+import org.apache.beehive.controls.api.properties.BeanPropertyMap;
+import org.apache.beehive.controls.api.properties.PropertyKey;
+import org.apache.beehive.controls.api.properties.PropertyMap;
+
+/**
+ * The BeanPersistenceDelegate class supports the XML persistence of Control 
JavaBeans by
+ * implementing the <code>java.beans.PersistenceDelegate</b> API, and 
overriding the default
+ * persistence algorithm based upon the runtime structure for Controls.  It 
selectively registers
+ * other PersistenceDelegate instances for other nested entities, as required, 
to ensure that
+ * runtime-defined state and object relationships are properly maintained.
+ * <p>
+ * For the BeanInfo of all generated ControlJavaBeans, a 
BeanPersistenceDelegate instance will
+ * be registered as the "persistenceDelegate" attribute in the BeanDescriptor. 
 The standard
+ * <code>java.beans.Encoder</code> persistence delegate lookup mechanism 
recognizes this attribute
+ * and will use the instance to persist an ControlBeans written to the 
encoding stream.
+ * <p>
+ * The BeanPersistence class implements optimized property persistence based 
upon the
+ * fact that the ControlBean already has a map containing all non-default 
property state.  Rather
+ * than using the standard (and slower) algorithm of comparing the encoding 
instance against a
+ * 'clean' instance, the delegate can simply retrieve the map and persist the 
values contained
+ * within it.
+ *
+ * @see java.beans.XMLEncoder
+ * @see java.beans.PersistenceDelegate 
+ */
+public class BeanPersistenceDelegate extends DefaultPersistenceDelegate
+{
+    /**
+     * The FieldPersistencersistence is an XMLEncoder PersistenceDelegate for 
the
+     * <code>java.lang.reflect.Field</code> claass.  It is similar to the one 
that comes
+     * bundled with the JDK with one key exception:  it works for non-public 
fields as
+     * well.
+     */
+    class FieldPersistenceDelegate extends PersistenceDelegate 
+    {
+        protected Expression instantiate(Object oldInstance, Encoder out) 
+        {
+            Field f = (Field)oldInstance;
+            return new Expression(oldInstance, f.getDeclaringClass(), 
"getDeclaredField",
+                                    new Object[]{f.getName()});
+        }
+    }
+
+    /**
+     * PersistenceDelegate.instantiate()
+     */
+    protected Expression instantiate(Object oldInstance, Encoder out)
+    {
+        XMLEncoder xmlOut = (XMLEncoder)out;
+        ControlBean control = (ControlBean)oldInstance;
+
+        //
+        // If processing a nested control, then use the parent bean's context 
as the
+        // constructor context
+        //
+        ControlBeanContext cbc = null;
+        if (xmlOut.getOwner() != null)
+            cbc = ((ControlBean)xmlOut.getOwner()).getControlBeanContext();
+
+        //
+        // See if the ControlBean has any associated PropertyMap in its 
delegation chain
+        // that was derived from an AnnotatedElement so this relationship (and 
any associated 
+        // external config delegates) will be restored as part of the decoding 
process.
+        //
+        // BUGBUG: What about a user-created PropertyMap that was passed into 
the constructor?
+        //
+        AnnotatedElementMap aem = null;
+        PropertyMap pMap = control.getPropertyMap();
+        while (pMap != null)
+        {
+            if (pMap instanceof AnnotatedElementMap)
+            {
+                aem = (AnnotatedElementMap)pMap;
+
+                //
+                // Ignore a class-valued AnnotationElementMap.. this just 
refers to the
+                // Control type, and will be automatically reassociated at 
construction
+                // time
+                //
+                if (aem.getAnnotatedElement() instanceof Class)
+                    aem = null;
+
+                xmlOut.setPersistenceDelegate(AnnotatedElementMap.class,
+                                              new 
AnnotatedElementMapPersistenceDelegate());
+
+                break;
+            }
+
+            pMap = pMap.getDelegateMap();
+        }
+
+
+        //
+        // Create a constructor that that uses the following form:
+        //      new <BeanClass>(ControlBeanContext cbc, String id, PropertyMap 
map)
+        // The context is set to null, so the current active container context 
will be
+        // used, the id will be the ID of the original control and the map 
will be
+        // any AnnotatedElementMap that was passed into the original 
constructor.
+        //
+        return new Expression(control, control.getClass(), "new", 
+                              new Object [] {cbc, control.getLocalID(), aem});
+    }
+
+    /**
+     * PersistenceDelegate.initialize()
+     */
+    protected void initialize(Class<?> type, Object oldInstance, Object 
newInstance, Encoder out)
+    {
+        //
+        // Get the bean and associated beanInfo for the source instance
+        //
+        ControlBean control = (ControlBean)oldInstance;
+        BeanInfo beanInfo;
+        try
+        {
+            beanInfo = Introspector.getBeanInfo(control.getClass());
+        }
+        catch (IntrospectionException ie)
+        {
+            throw new ControlException("Unable to locate BeanInfo", ie);
+        }
+
+        //
+        // Cast the encoding stream to an XMLEncoder (only encoding supported) 
and then set
+        // the stream owner to the bean being persisted
+        //
+        XMLEncoder xmlOut = (XMLEncoder)out;
+        Object owner = xmlOut.getOwner();
+        xmlOut.setOwner(control);
+        try
+        {
+
+            //
+            // The default implementation of property persistence will use 
BeanInfo to 
+            // incrementally compare oldInstance property values to 
newInstance property values.   
+            // Because the bean instance PropertyMap holds only the values 
that have been 
+            // modified, this process can be optimized by directly writing out 
only the properties 
+            // found in the map.
+            //
+            BeanPropertyMap beanMap = control.getPropertyMap();
+            PropertyDescriptor [] propDescriptors = 
beanInfo.getPropertyDescriptors();
+            for (PropertyKey pk : beanMap.getPropertyKeys())
+            {
+                //
+                // Locate the PropertyDescriptor for the modified property, 
and use it to write
+                // the property value to the encoder stream
+                //
+                String propName = pk.getPropertyName();
+                boolean found = false;
+                for (int i = 0; i < propDescriptors.length; i++)
+                {
+                    if (propName.equals(propDescriptors[i].getName()))
+                    {
+                        found = true;
+
+                        // Only write the property if it is not flagged as 
transient
+                        Object transientVal = 
propDescriptors[i].getValue("transient");
+                        if (transientVal == null || 
transientVal.equals(Boolean.FALSE))
+                        {
+                            xmlOut.writeStatement(
+                                new Statement(oldInstance, 
+                                      
propDescriptors[i].getWriteMethod().getName(),
+                                      new Object [] 
{beanMap.getProperty(pk)}));
+                        }
+                    }
+                }
+                if (found == false)
+                {
+                    throw new ControlException("Unknown property in bean 
PropertyMap: " + pk);
+                }
+            }
+
+            //
+            // Get the bean context associated with the bean, and persist any 
nested controls
+            //
+            ControlBeanContext cbc = control.getControlBeanContext();
+            if (cbc.size() != 0)
+            {
+                xmlOut.setPersistenceDelegate(ControlBeanContext.class, 
+                                              new 
ContextPersistenceDelegate());
+
+                Iterator nestedIter = cbc.iterator();
+                while (nestedIter.hasNext())
+                {
+                    Object bean = nestedIter.next();
+                    if (bean instanceof ControlBean)
+                    {
+                        xmlOut.writeStatement(
+                            new Statement(cbc, "add", new Object [] { bean } 
));
+                    }
+                }
+            }
+
+            //
+            // Restore any listeners associated with the control
+            //
+            EventSetDescriptor [] eventSetDescriptors = 
beanInfo.getEventSetDescriptors();
+            for (int i = 0; i < eventSetDescriptors.length; i++)
+            {
+                EventSetDescriptor esd = eventSetDescriptors[i];
+                Method listenersMethod = esd.getGetListenerMethod();
+                String addListenerName = esd.getAddListenerMethod().getName();
+                if (listenersMethod != null)
+                {
+                    //
+                    // Get the list of listeners, and then add statements to 
incrementally
+                    // add them in the same order
+                    //
+                    try
+                    {
+                        Object [] lstnrs = (Object 
[])listenersMethod.invoke(control, 
+                                                                             
new Object []{});
+                        for (int j = 0; j < lstnrs.length; j++)
+                        {
+                            //
+                            // If this is a generated EventAdaptor class, then 
set the delegate
+                            // explicitly
+                            //
+                            if (lstnrs[j] instanceof EventAdaptor)
+                                
xmlOut.setPersistenceDelegate(lstnrs[j].getClass(), 
+                                                              new 
AdaptorPersistenceDelegate());
+                            xmlOut.writeStatement(
+                                new Statement(control, addListenerName, new 
Object [] {lstnrs[j]}));
+                        }
+                    }
+                    catch (Exception iae)
+                    {
+                        throw new ControlException("Unable to initialize 
listeners", iae);
+                    } 
+                }
+            }
+
+            //
+            // See if the control holds an implementation instance, if so, we 
need to include
+            // it (and any nested controls or state) in the encoding stream
+            //
+            Object impl = control.getImplementation();
+            if (impl != null)
+            {
+
+                //
+                // Set the persistence delegate for the impl class to the Impl 
delegate,
+                // set the current stream owner to the bean, and then write 
the implementation
+                //
+                Class implClass = impl.getClass(); 
+                if (xmlOut.getPersistenceDelegate(implClass) instanceof 
DefaultPersistenceDelegate) 
+                    xmlOut.setPersistenceDelegate(implClass, new 
ImplPersistenceDelegate());
+
+                //
+                // HACK: This bit of hackery pushes the impl into the 
persistence stream
+                // w/out actually requiring it be used as an argument 
elsewhere, since there
+                // is no public API on the bean that takes an impl instance as 
an argument.
+                //
+                xmlOut.writeStatement(
+                    new Statement(impl, "toString", null));
+            }
+        }
+        finally
+        {
+            // Restore the previous encoding stream owner
+            xmlOut.setOwner(owner);
+        }
+    }
+
+    /**
+     * PersistenceDelegate.writeObject()
+     */
+    public void writeObject(Object oldInstance, Encoder out)
+    {
+        // Override the default FieldPersistence algorithm for the encoder, so 
private fields
+        // can also be encoded
+        out.setPersistenceDelegate(Field.class, new 
FieldPersistenceDelegate());
+        super.writeObject(oldInstance, out);
+    }
+}

Deleted: 
/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlPersistenceDelegate.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlPersistenceDelegate.java?view=auto&rev=125182
==============================================================================

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/EventAdaptor.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/EventAdaptor.java?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/EventAdaptor.java
     Fri Jan 14 08:48:32 2005
@@ -0,0 +1,30 @@
+package org.apache.beehive.controls.runtime.bean;
+/*
+ * 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:$
+ */
+
+/**
+ * The EventAdaptor interface will be implemented by all code-generated event 
adaptor classes
+ * used to deliver control events to clients.
+ */
+public interface EventAdaptor
+{
+    /**
+     * Returns the client instance that will be the target of the event.
+     */ 
+    Object getClient();
+}

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm&r1=125182&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm&r2=125183
==============================================================================
--- 
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 Jan 14 08:48:32 2005
@@ -57,12 +57,15 @@
 #macro (declareEventAdaptor $adaptor)
     #set ($eventSet = $adaptor.eventSet)
     #set ($binding = $adaptor.eventField.typeBindingMap)
-    protected static class $adaptor.className 
-                     implements 
${eventSet.className}${adaptor.eventSetBinding}, java.io.Serializable
+    public static class $adaptor.className 
+              implements ${eventSet.className}${adaptor.eventSetBinding}, 
+                         EventAdaptor, java.io.Serializable
     {
         $client.className _client;
 
-        ${adaptor.className}($client.className client) { _client = client; }
+        public ${adaptor.className}($client.className client) { _client = 
client; }
+
+        public Object getClient() { return _client; }
 
         #foreach ($event in $eventSet.events)
             public ${event.getReturnType($binding)} 
${event.name}(${event.getArgDecl($binding)}) $event.throwsClause
@@ -151,6 +154,8 @@
 import org.apache.beehive.controls.api.ControlException;
 import org.apache.beehive.controls.api.context.ControlBeanContext;
 import org.apache.beehive.controls.runtime.bean.ControlBean;
+import org.apache.beehive.controls.runtime.bean.EventAdaptor;
+import org.apache.beehive.controls.runtime.bean.AdaptorPersistenceDelegate;
 
 public class $init.shortName
              extends org.apache.beehive.controls.runtime.bean.ClientInitializer

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm&r1=125182&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm&r2=125183
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
       (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
       Fri Jan 14 08:48:32 2005
@@ -63,7 +63,7 @@
 import java.util.HashMap;
 
 import org.apache.beehive.controls.api.ControlException;
-import org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate;
+import org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate;
 import org.apache.beehive.controls.runtime.packaging.ControlEventSetDescriptor;
 
 public class ${bean.shortName}BeanInfo 
@@ -94,13 +94,13 @@
         #end
         
         //
-        // The 
org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate class
+        // The 
org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate class
         // implements the XMLDecode delegation model for all Control JavaBean 
types. It
         // provides optimized XML persistance based upon the Control runtime 
architecture.
         // The 'persistenceDelegate' attribute of a BeanDescriptor is used by 
XMLEncoder to 
         // locate a delegate for a particular JavaBean type.
         //
-        bd.setValue("persistenceDelegate", new ControlPersistenceDelegate());
+        bd.setValue("persistenceDelegate", new BeanPersistenceDelegate());
 
         return bd;
     }

Added: 
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?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.bat
 Fri Jan 14 08:48:32 2005
@@ -0,0 +1,6 @@
[EMAIL PROTECTED] off
+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

Added: 
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?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/BeanInfo.sh
  Fri Jan 14 08:48:32 2005
@@ -0,0 +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

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo&r1=125182&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/beaninfo/InfoTestBean.beaninfo&r2=125183
==============================================================================
--- 
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
        Fri Jan 14 08:48:32 2005
@@ -9,7 +9,7 @@
                 
             </short-description>
             <attributes>
-                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate@">
+                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate@">
             </attributes>
         </feature-descriptor>
         <bean-class>

Added: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/encoding/EncodingTest.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/encoding/EncodingTest.java?view=auto&rev=125183
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/encoding/EncodingTest.java
    Fri Jan 14 08:48:32 2005
@@ -0,0 +1,94 @@
+package org.apache.beehive.controls.test.java.encoding;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.beehive.test.tools.mantis.annotations.tch.Freq;
+
+import java.beans.*;
+import java.io.*;
+
+import org.apache.beehive.controls.test.controls.basic.HelloBean;
+import org.apache.beehive.controls.test.controls.property.Props;
+import org.apache.beehive.controls.test.controls.property.PropsBean;
+import org.apache.beehive.controls.test.controls.property.NestPropsBean;
+
+
+/**
+ * A TestCase that tests encoding/decoding control state to/from XML.
+ */
[EMAIL PROTECTED]("checkin")
+public class EncodingTest extends TestCase
+{
+    // Set this to true, and the encoding stream will be dumped to System.out 
as the test
+    // is run.
+
+    public EncodingTest(String s) { super(s); }
+
+    public void setUp() { }
+
+    /**
+     * An Exception listener class that will catch encoding/decoding 
exceptions, dump the
+     * failure stack, and then flag a test failure.
+     */
+    private class ExceptionDump implements java.beans.ExceptionListener
+    {
+        public void exceptionThrown(Exception e)
+        {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+    /**
+     *  Helper method that will take a given object, encode it using 
XMLEncoder, then decode
+     *  it using XmLMDecoder.
+     */
+    private <T> T encodeDecode(T obj) throws Exception
+    {
+        //
+        // Validate decode ability by running through a decoder
+        //
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder(baos);
+        encoder.setExceptionListener(new ExceptionDump());
+        encoder.writeObject(obj);
+        encoder.close();
+        baos.flush();
+
+        ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
+        XMLDecoder decoder = new XMLDecoder(bais);
+        decoder.setExceptionListener(new ExceptionDump());
+        T returnObj = (T)decoder.readObject();
+        bais.close();
+        return returnObj;
+    }
+
+    /**
+     * Tests encoding a NestPropsBean instance for validating of property 
state, nesting,
+     * and listener registration. 
+     */
+    public void testNestPropsBean() throws Exception
+    {
+        NestPropsBean propsBean = new NestPropsBean(null, "myID", null);
+        propsBean.setSimpleInt(3);
+        propsBean.getControlPropertySet(Props.SimpleProps.class);
+
+        PropsBean nestedBean = new NestPropsBean(null, "nested", null);
+        propsBean.getControlBeanContext().add(nestedBean);
+        nestedBean.setSimpleInt(4);
+
+        // Run the bean through the encoder/decoder, then test equivalence
+        NestPropsBean newPropsBean = encodeDecode(propsBean);
+
+        if (newPropsBean.getSimpleInt() != propsBean.getSimpleInt())
+            fail("getSimpleInt: " + newPropsBean.getSimpleInt());
+
+        PropsBean newNestedBean = 
+                  
(NestPropsBean)(newPropsBean.getControlBeanContext().getBean("nested"));
+        if (newNestedBean == null)
+            fail("No nested bean!");
+        else if (newNestedBean.getSimpleInt() != nestedBean.getSimpleInt())
+            fail("Nested getSimpleInt: " + newNestedBean.getSimpleInt());
+    }
+}

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo&r1=125182&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext1Bean.beaninfo&r2=125183
==============================================================================
--- 
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
     Fri Jan 14 08:48:32 2005
@@ -9,7 +9,7 @@
                 Ext1Bean
             </short-description>
             <attributes>
-                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate@">
+                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate@">
             </attributes>
         </feature-descriptor>
         <bean-class>

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo&r1=125182&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Ext2Bean.beaninfo&r2=125183
==============================================================================
--- 
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
     Fri Jan 14 08:48:32 2005
@@ -9,7 +9,7 @@
                 Ext2Bean
             </short-description>
             <attributes>
-                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate@">
+                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate@">
             </attributes>
         </feature-descriptor>
         <bean-class>

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo&r1=125182&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf1Bean.beaninfo&r2=125183
==============================================================================
--- 
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
    Fri Jan 14 08:48:32 2005
@@ -9,7 +9,7 @@
                 Intf1Bean
             </short-description>
             <attributes>
-                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate@">
+                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate@">
             </attributes>
         </feature-descriptor>
         <bean-class>

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?view=diff&rev=125183&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo&r1=125182&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/inherit/Intf2Bean.beaninfo&r2=125183
==============================================================================
--- 
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
    Fri Jan 14 08:48:32 2005
@@ -9,7 +9,7 @@
                 Intf2Bean
             </short-description>
             <attributes>
-                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.ControlPersistenceDelegate@">
+                <attribute name="persistenceDelegate" 
value="org.apache.beehive.controls.runtime.bean.BeanPersistenceDelegate@">
             </attributes>
         </feature-descriptor>
         <bean-class>

Reply via email to