commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io BeanCreateRule.java
Date Wed, 05 Jun 2002 10:30:51 GMT
jstrachan    2002/06/05 03:30:51

  Modified:    betwixt/src/test/org/apache/commons/betwixt/scarab
                        ScarabSettings.java GlobalAttribute.java
               betwixt/src/java/org/apache/commons/betwixt/io
                        BeanCreateRule.java
  Log:
  Patched the parsing code (BeanCreateRule) so that beans are fully populated before they
are added to their parent bean via the parent's adder or setter method.
  
  So in pseudo code the following now happens...
  
  ParentBean parent = ...;
  ChildBean bean = new ChildBean();
  bean.setPropertyA(something);
  bean.setPropertyB(somethingElse);
  
  // now the child bean is fully initialized, add it to the parent
  parent.setChildBean(bean);
  // or
  parent.addChildBean(bean);
  
  
  This allows the parent's setter or adder method to access the properties of the new bean,
such as to make indices, adding it to a Map or whatever
  
  Revision  Changes    Path
  1.4       +9 -1      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/ScarabSettings.java
  
  Index: ScarabSettings.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/ScarabSettings.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ScarabSettings.java	1 Jun 2002 18:28:06 -0000	1.3
  +++ ScarabSettings.java	5 Jun 2002 10:30:50 -0000	1.4
  @@ -69,11 +69,13 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import junit.framework.AssertionFailedError;
  +
   /**
    * <p><code>ScarabSettings</code> is a sample bean for use by the test
cases.</p>
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - * @version $Id: ScarabSettings.java,v 1.3 2002/06/01 18:28:06 jon Exp $
  + * @version $Id: ScarabSettings.java,v 1.4 2002/06/05 10:30:50 jstrachan Exp $
    */
   public class ScarabSettings implements Serializable
   {
  @@ -106,6 +108,12 @@
       
       public void addGlobalAttribute(GlobalAttribute globalAttribute)
       {
  +        // adds an assertion that the name must be populated first
  +        // as an extra test case
  +        if (globalAttribute.getName() == null) 
  +        {
  +            throw new AssertionFailedError("Cannot add a new GlobalAttribute that has no
name: " + globalAttribute);            
  +        }
           globalAttributes.add(globalAttribute);
       }        
   
  
  
  
  1.5       +2 -2      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttribute.java
  
  Index: GlobalAttribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttribute.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GlobalAttribute.java	5 Jun 2002 07:57:07 -0000	1.4
  +++ GlobalAttribute.java	5 Jun 2002 10:30:50 -0000	1.5
  @@ -72,7 +72,7 @@
    * <p><code>GlobalAttribute</code> is a sample bean for use by the test
cases.</p>
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - * @version $Id: GlobalAttribute.java,v 1.4 2002/06/05 07:57:07 jstrachan Exp $
  + * @version $Id: GlobalAttribute.java,v 1.5 2002/06/05 10:30:50 jstrachan Exp $
    */
   public class GlobalAttribute implements Serializable
   {
  @@ -95,7 +95,7 @@
       }
   
       public String toString() {
  -        return super.toString() + "[options=" + globalAttributeOptions + "]";
  +        return super.toString() + "[name=" + name + ";options=" + globalAttributeOptions
+ "]";
       }
   
       public void addGlobalAttributeOption(GlobalAttributeOption globalAttributeOption)
  
  
  
  1.17      +16 -11    jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java
  
  Index: BeanCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- BeanCreateRule.java	5 Jun 2002 07:57:07 -0000	1.16
  +++ BeanCreateRule.java	5 Jun 2002 10:30:51 -0000	1.17
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: BeanCreateRule.java,v 1.16 2002/06/05 07:57:07 jstrachan Exp $
  + * $Id: BeanCreateRule.java,v 1.17 2002/06/05 10:30:51 jstrachan Exp $
    */
   package org.apache.commons.betwixt.io;
   
  @@ -35,7 +35,7 @@
     * from the betwixt XML metadata.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.16 $
  +  * @version $Revision: 1.17 $
     */
   public class BeanCreateRule extends Rule {
   
  @@ -108,14 +108,6 @@
               if ( instance != null ) {
                   createdBean = true;
   
  -                // force any setters of the parent bean to be called for this new (property
value) object
  -                Updater updater = descriptor.getUpdater();
  -                if ( updater != null ) {
  -                    if ( log.isDebugEnabled() ) {
  -                        log.debug( "Calling updater for: " + descriptor + " with: " + instance
+ " on bean: " + context.getBean() );
  -                    }
  -                    updater.update( context, instance );
  -                }
                   context.setBean( instance );
                   digester.push(instance);
                   
  @@ -151,7 +143,7 @@
                               log.trace(value);
                           }
                           
  -                        updater = attributeDescriptor.getUpdater();
  +                        Updater updater = attributeDescriptor.getUpdater();
                           log.trace(updater);
                           if ( updater != null && value != null ) {
                               updater.update( context, value );
  @@ -170,8 +162,21 @@
        */
       public void end() throws Exception {
           if ( createdBean ) {
  +            
  +            // force any setters of the parent bean to be called for this new bean instance
  +            Updater updater = descriptor.getUpdater();
  +            Object instance = context.getBean();
  +
               Object top = digester.pop();
               context.setBean( digester.peek() );
  +
  +            if ( updater != null ) {
  +                if ( log.isDebugEnabled() ) {
  +                    log.debug( "Calling updater for: " + descriptor + " with: " + instance
+ " on bean: " + context.getBean() );
  +                }
  +                updater.update( context, instance );
  +            }
  +            
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message