You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/01/25 13:06:55 UTC

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections BeanMap.java

scolebourne    2003/01/25 04:06:55

  Modified:    collections/src/test/org/apache/commons/collections
                        TestBeanMap.java
               collections/src/java/org/apache/commons/collections
                        BeanMap.java
  Log:
  Make getReadMethod and getWriteMethod public
  Solves bug 15897
  
  Revision  Changes    Path
  1.9       +16 -3     jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java
  
  Index: TestBeanMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestBeanMap.java	7 Jan 2003 23:44:19 -0000	1.8
  +++ TestBeanMap.java	25 Jan 2003 12:06:55 -0000	1.9
  @@ -61,6 +61,7 @@
   package org.apache.commons.collections;
   
   import java.io.Serializable;
  +import java.lang.reflect.Method;
   import java.util.Map;
   
   import junit.framework.Test;
  @@ -344,4 +345,16 @@
           assertEquals(map1.get("someIntValue"), new Integer(0));
       }
   
  +    public void testMethodAccessor() throws Exception {
  +        BeanMap map = (BeanMap) makeFullMap();
  +        Method method = BeanWithProperties.class.getDeclaredMethod("getSomeIntegerValue", null);
  +        assertEquals(method, map.getReadMethod("someIntegerValue"));
  +    }
  +    
  +    public void testMethodMutator() throws Exception {
  +        BeanMap map = (BeanMap) makeFullMap();
  +        Method method = BeanWithProperties.class.getDeclaredMethod("setSomeIntegerValue", new Class[] {Integer.class});
  +        assertEquals(method, map.getWriteMethod("someIntegerValue"));
  +    }
  +    
   }
  
  
  
  1.15      +39 -19    jakarta-commons/collections/src/java/org/apache/commons/collections/BeanMap.java
  
  Index: BeanMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BeanMap.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BeanMap.java	12 Oct 2002 22:15:19 -0000	1.14
  +++ BeanMap.java	25 Jan 2003 12:06:55 -0000	1.15
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -23,11 +20,11 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:
  + *    any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
    *
    * 4. The names "The Jakarta Project", "Commons", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  @@ -36,7 +33,7 @@
    *
    * 5. Products derived from this software may not be called "Apache"
    *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  + *    permission of the Apache Software Foundation.
    *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  @@ -77,16 +74,19 @@
   import java.util.Set;
   
   
  -/** An implementation of Map for JavaBeans which uses introspection to
  -  * get and put properties in the bean.
  -  *
  -  * If an exception occurs during attempts to get or set a property then the
  -  * property is considered non existent in the Map
  -  *
  -  * @since 1.0
  -  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  */
  -
  +/** 
  + * An implementation of Map for JavaBeans which uses introspection to
  + * get and put properties in the bean.
  + * <p>
  + * If an exception occurs during attempts to get or set a property then the
  + * property is considered non existent in the Map
  + *
  + * @since Commons Collections 1.0
  + * @version $Revision$ $Date$
  + * 
  + * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  + * @author Stephen Colebourne
  + */
   public class BeanMap extends AbstractMap implements Cloneable {
   
       private transient Object bean;
  @@ -571,6 +571,26 @@
       public void setBean( Object newBean ) {
           bean = newBean;
           reinitialise();
  +    }
  +
  +    /**
  +     * Returns the accessor for the property with the given name.
  +     *
  +     * @param name  the name of the property 
  +     * @return the accessor method for the property, or null
  +     */
  +    public Method getReadMethod(String name) {
  +        return (Method) readMethods.get(name);
  +    }
  +
  +    /**
  +     * Returns the mutator for the property with the given name.
  +     *
  +     * @param name  the name of the property
  +     * @return the mutator method for the property, or null
  +     */
  +    public Method getWriteMethod(String name) {
  +        return (Method) writeMethods.get(name);
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>