You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/06/08 21:33:32 UTC
svn commit: r1348202 - in /commons/sandbox/beanutils2/trunk/src:
main/java/org/apache/commons/beanutils2/
test/java/org/apache/commons/beanutils2/
Author: simonetripodi
Date: Fri Jun 8 19:33:32 2012
New Revision: 1348202
URL: http://svn.apache.org/viewvc?rev=1348202&view=rev
Log:
throws NoSuchMethodException only when analyzing methods and not properties
s/get(Indexed)(Read|Write)PropertyDescriptor()/get(Indexed)(Read|Write)Method()
Modified:
commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java
commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/SetPropertyTestCase.java
Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java Fri Jun 8 19:33:32 2012
@@ -22,6 +22,7 @@ package org.apache.commons.beanutils2;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
import java.util.Map;
public interface BeanProperties<B>
@@ -36,7 +37,7 @@ public interface BeanProperties<B>
* @throws NoSuchMethodException TODO
*/
boolean isReadable( String propertyName )
- throws IntrospectionException, NoSuchMethodException;
+ throws IntrospectionException;
/**
* Checks if the specified property name identifies a writable property.
@@ -47,7 +48,7 @@ public interface BeanProperties<B>
* @throws NoSuchMethodException TODO
*/
boolean isWritable( String propertyName )
- throws IntrospectionException, NoSuchMethodException;
+ throws IntrospectionException;
/**
*
@@ -57,7 +58,7 @@ public interface BeanProperties<B>
* @throws NoSuchMethodException
*/
public abstract PropertyDescriptor getPropertyDescriptor( String propertyName )
- throws IntrospectionException, NoSuchMethodException;
+ throws IntrospectionException;
/**
*
@@ -66,17 +67,17 @@ public interface BeanProperties<B>
* @throws IntrospectionException
* @throws NoSuchMethodException
*/
- public abstract PropertyDescriptor getReadPropertyDescriptor( String propertyName )
+ public abstract Method getReadPropertyMethod( String propertyName )
throws IntrospectionException, NoSuchMethodException;
/**
*
- * @param propertyName
+ * @param name
* @return
* @throws NoSuchMethodException
* @throws IntrospectionException
*/
- public abstract IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
+ public abstract Method getWriteMethod( String name )
throws NoSuchMethodException, IntrospectionException;
/**
@@ -86,17 +87,17 @@ public interface BeanProperties<B>
* @throws NoSuchMethodException
* @throws IntrospectionException
*/
- public abstract IndexedPropertyDescriptor getIndexedReadPropertyDescriptor( String propertyName )
+ public abstract IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
throws NoSuchMethodException, IntrospectionException;
/**
*
- * @param name
+ * @param propertyName
* @return
* @throws NoSuchMethodException
* @throws IntrospectionException
*/
- public abstract PropertyDescriptor getWritePropertyDescriptor( String name )
+ public abstract Method getIndexedReadMethod( String propertyName )
throws NoSuchMethodException, IntrospectionException;
/**
Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java Fri Jun 8 19:33:32 2012
@@ -22,7 +22,6 @@ package org.apache.commons.beanutils2;
import static org.apache.commons.beanutils2.BeanUtils.on;
import static org.apache.commons.beanutils2.internal.Assertions.checkNotNull;
-import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
@@ -55,8 +54,7 @@ final class DefaultBeanAccessor<B>
throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException
{
checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
- PropertyDescriptor propertyDescriptor = properties.getReadPropertyDescriptor( propertyName );
- Object newBean = propertyDescriptor.getReadMethod().invoke( bean );
+ Object newBean = properties.getReadPropertyMethod( propertyName ).invoke( bean );
return new DefaultBeanAccessor<Object>( newBean );
}
@@ -67,9 +65,8 @@ final class DefaultBeanAccessor<B>
throws IntrospectionException, NoSuchMethodException
{
checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
- IndexedPropertyDescriptor indexedPropertyDescriptor = properties.getIndexedReadPropertyDescriptor( propertyName );
return new DefaultIndexedPropertyGetterAccessor( bean, propertyName,
- indexedPropertyDescriptor.getIndexedReadMethod() );
+ properties.getIndexedReadMethod( propertyName ) );
}
/**
@@ -109,8 +106,7 @@ final class DefaultBeanAccessor<B>
throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException
{
checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
- PropertyDescriptor propertyDescriptor = properties.getWritePropertyDescriptor( propertyName );
- return new DefaultBeanPropertySetter<B>( bean, propertyDescriptor.getWriteMethod() );
+ return new DefaultBeanPropertySetter<B>( bean, properties.getWriteMethod( propertyName ) );
}
/**
@@ -205,15 +201,15 @@ final class DefaultBeanAccessor<B>
{
try
{
- properties.getWritePropertyDescriptor( propertyName );
+ if ( properties.isWritable( propertyName ) )
+ {
+ set( propertyName ).with( propertyValue );
+ }
}
- catch ( NoSuchMethodException e )
+ catch ( IntrospectionException e )
{
// either the property there is no property with the given name or it is not writable so we skip it.
- return;
}
-
- set( propertyName ).with( propertyValue );
}
/**
Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java Fri Jun 8 19:33:32 2012
@@ -24,6 +24,7 @@ import static org.apache.commons.beanuti
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
import java.util.Map;
final class DefaultBeanProperties<B>
@@ -45,7 +46,7 @@ final class DefaultBeanProperties<B>
* {@inheritDoc}
*/
public boolean isReadable( String propertyName )
- throws IntrospectionException, NoSuchMethodException
+ throws IntrospectionException
{
checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
@@ -64,7 +65,7 @@ final class DefaultBeanProperties<B>
* {@inheritDoc}
*/
public boolean isWritable( String propertyName )
- throws IntrospectionException, NoSuchMethodException
+ throws IntrospectionException
{
checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
@@ -83,12 +84,15 @@ final class DefaultBeanProperties<B>
* {@inheritDoc}
*/
public PropertyDescriptor getPropertyDescriptor( String propertyName )
- throws IntrospectionException, NoSuchMethodException
+ throws IntrospectionException
{
PropertyDescriptor propertyDescriptor = registry.getPropertyDescriptor( beanClass, propertyName );
- checkMethod( propertyDescriptor, "Property '%s' does not exist in bean of type %s",
- propertyName, beanClass.getName() );
+ if ( propertyDescriptor == null )
+ {
+ throw new IntrospectionException( format( "Property '%s' does not exist in bean of type %s",
+ propertyName, beanClass.getName() ) );
+ }
return propertyDescriptor;
}
@@ -96,67 +100,63 @@ final class DefaultBeanProperties<B>
/**
* {@inheritDoc}
*/
- public PropertyDescriptor getReadPropertyDescriptor( String propertyName )
+ public Method getReadPropertyMethod( String propertyName )
throws IntrospectionException, NoSuchMethodException
{
PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
- checkMethod( propertyDescriptor.getReadMethod(),
- "Bean of type %s does not provide a getter for property '%s'!",
- beanClass.getName(), propertyName );
-
- return propertyDescriptor;
+ return checkMethod( propertyDescriptor.getReadMethod(),
+ "Bean of type %s does not provide a getter for property '%s'!",
+ beanClass.getName(), propertyName );
}
/**
* {@inheritDoc}
*/
- public IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
+ public Method getWriteMethod( String name )
throws NoSuchMethodException, IntrospectionException
{
- PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
- checkArgument( propertyDescriptor instanceof IndexedPropertyDescriptor,
- "Property '%s' in bean of type %s is not an indexed property", propertyName, beanClass.getName() );
- return (IndexedPropertyDescriptor) propertyDescriptor;
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor( name );
+
+ return checkMethod( propertyDescriptor.getWriteMethod(),
+ "Bean of type %s does not provide a setter for property '%s'!",
+ beanClass.getName(), name );
}
/**
* {@inheritDoc}
*/
- public IndexedPropertyDescriptor getIndexedReadPropertyDescriptor( String propertyName )
+ public IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
throws NoSuchMethodException, IntrospectionException
{
- IndexedPropertyDescriptor indexedPropertyDescriptor = getIndexedPropertyDescriptor( propertyName );
-
- checkMethod( indexedPropertyDescriptor.getIndexedReadMethod(),
- "Bean of type %s does not provide a getter for indexed property '%s'!",
- beanClass.getName(), propertyName );
-
- return indexedPropertyDescriptor;
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
+ checkArgument( propertyDescriptor instanceof IndexedPropertyDescriptor,
+ "Property '%s' in bean of type %s is not an indexed property", propertyName, beanClass.getName() );
+ return (IndexedPropertyDescriptor) propertyDescriptor;
}
/**
* {@inheritDoc}
*/
- public PropertyDescriptor getWritePropertyDescriptor( String name )
+ public Method getIndexedReadMethod( String propertyName )
throws NoSuchMethodException, IntrospectionException
{
- PropertyDescriptor propertyDescriptor = getPropertyDescriptor( name );
-
- checkMethod( propertyDescriptor.getWriteMethod(),
- "Bean of type %s does not provide a setter for property '%s'!",
- beanClass.getName(), name );
+ IndexedPropertyDescriptor indexedPropertyDescriptor = getIndexedPropertyDescriptor( propertyName );
- return propertyDescriptor;
+ return checkMethod( indexedPropertyDescriptor.getIndexedReadMethod(),
+ "Bean of type %s does not provide a getter for indexed property '%s'!",
+ beanClass.getName(), propertyName );
}
- private static <T> void checkMethod( T method, String errorMessageTemplate, Object...arsg )
+ private static Method checkMethod( Method method, String errorMessageTemplate, Object...arsg )
throws NoSuchMethodException
{
if ( method == null )
{
throw new NoSuchMethodException( format( errorMessageTemplate, arsg ) );
}
+
+ return method;
}
/**
Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java Fri Jun 8 19:33:32 2012
@@ -23,6 +23,8 @@ import static org.apache.commons.beanuti
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.beans.IntrospectionException;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -64,7 +66,7 @@ public final class GetPropertyTestCase
on( bean ).get( "writeOnlyProperty" ).get();
}
- @Test( expected = NoSuchMethodException.class )
+ @Test( expected = IntrospectionException.class )
public void getUnknownProperty()
throws Exception
{
Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java Fri Jun 8 19:33:32 2012
@@ -21,6 +21,8 @@ import static org.apache.commons.beanuti
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.beans.IntrospectionException;
+
import org.junit.Test;
public class IsReadableTestCase
@@ -33,7 +35,7 @@ public class IsReadableTestCase
on( TestBean.class ).getProperties().isReadable( null );
}
- @Test( expected = NoSuchMethodException.class )
+ @Test( expected = IntrospectionException.class )
public void isReadbleUnknown()
throws Exception
{
Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java Fri Jun 8 19:33:32 2012
@@ -21,6 +21,8 @@ import static org.apache.commons.beanuti
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.beans.IntrospectionException;
+
import org.junit.Test;
public class IsWritableTestCase
@@ -33,7 +35,7 @@ public class IsWritableTestCase
on( TestBean.class ).getProperties().isWritable( null );
}
- @Test( expected = NoSuchMethodException.class )
+ @Test( expected = IntrospectionException.class )
public void isWritbleUnknown()
throws Exception
{
Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/SetPropertyTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/SetPropertyTestCase.java?rev=1348202&r1=1348201&r2=1348202&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/SetPropertyTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/SetPropertyTestCase.java Fri Jun 8 19:33:32 2012
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import java.beans.IntrospectionException;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -77,7 +79,7 @@ public class SetPropertyTestCase
/**
* Tests if trying to set a nonexistent property causes an NPE.
*/
- @Test( expected = NoSuchMethodException.class )
+ @Test( expected = IntrospectionException.class )
public void setNonExistentProperty()
throws Exception
{