rdonkin     2004/01/08 14:38:11

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        WrapDynaBean.java
               beanutils/src/test/org/apache/commons/beanutils
                        WrapDynaBeanTestCase.java
  Log:
  Added ability to get wrapped instance to WrapDynaBean's. Submitted by Niall 
Pemberton.
  
  Revision  Changes    Path
  1.8       +31 -5     
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/WrapDynaBean.java
  
  Index: WrapDynaBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/WrapDynaBean.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WrapDynaBean.java 9 Oct 2003 20:43:15 -0000       1.7
  +++ WrapDynaBean.java 8 Jan 2004 22:38:11 -0000       1.8
  @@ -7,7 +7,7 @@
    * 
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -70,6 +70,18 @@
    * <p>Implementation of <code>DynaBean</code> that wraps a standard JavaBean
    * instance, so that DynaBean APIs can be used to access its properties.</p>
    *
  + * <p>
  + * The most common use cases for this class involve wrapping an existing java bean.
  + * (This makes it different from the typical use cases for other 
<code>DynaBean</code>'s.) 
  + * For example:
  + * </p>
  + * <code><pre>
  + *  Object aJavaBean = ...;
  + *  ...
  + *  DynaBean db = new WrapDynaBean(aJavaBean);
  + *  ...
  + * </pre></code>
  + *
    * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation does not
    * support the <code>contains()</code> and <code>remove()</code> methods.</p>
    *
  @@ -323,6 +335,20 @@
                       ("Property '" + name + "' has no mapped write method");
           }
   
  +    }
  +
  +    /** 
  +     * Gets the bean instance wrapped by this DynaBean.
  +     * For most common use cases, 
  +     * this object should already be known 
  +     * and this method safely be ignored.
  +     * But some creators of frameworks using <code>DynaBean</code>'s may 
  +     * find this useful.
  +     *
  +     * @return the java bean Object wrapped by this <code>DynaBean</code>
  +     */
  +    public Object getInstance() {
  +        return instance;
       }
   
   
  
  
  
  1.7       +15 -5     
jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/WrapDynaBeanTestCase.java
  
  Index: WrapDynaBeanTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/WrapDynaBeanTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WrapDynaBeanTestCase.java 9 Oct 2003 20:40:07 -0000       1.6
  +++ WrapDynaBeanTestCase.java 8 Jan 2004 22:38:11 -0000       1.7
  @@ -7,7 +7,7 @@
    * 
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -204,5 +204,15 @@
        * is not serializable.
        */
       public void testSerialization() { }
  +    
  +    /** Tests getInstance method */
  +    public void testGetInstance() {
  +        AlphaBean alphaBean = new AlphaBean("Now On Air... John Peel");
  +        WrapDynaBean dynaBean = new WrapDynaBean(alphaBean);
  +        Object wrappedInstance = dynaBean.getInstance();
  +        assertTrue("Object type is AlphaBean", wrappedInstance instanceof 
AlphaBean);
  +        AlphaBean wrappedAlphaBean = (AlphaBean) wrappedInstance;
  +        assertTrue("Same Object", wrappedAlphaBean == alphaBean);
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to