commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1241046 - /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/
Date Mon, 06 Feb 2012 15:36:19 GMT
Author: simonetripodi
Date: Mon Feb  6 15:36:18 2012
New Revision: 1241046

URL: http://svn.apache.org/viewvc?rev=1241046&view=rev
Log:
added the "get indexed property" feature
TODO set indexed property

Added:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
  (with props)
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
  (with props)
Modified:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanAccessor.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/IndexedPropertyGetterAccessor.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertySetterAccessor.java

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanAccessor.java?rev=1241046&r1=1241045&r2=1241046&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanAccessor.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanAccessor.java
Mon Feb  6 15:36:18 2012
@@ -32,10 +32,10 @@ public interface BeanAccessor<B>
         throws IllegalAccessException, IntrospectionException, InvocationTargetException,
NoSuchMethodException;
 
     IndexedPropertyGetterAccessor getIndexed( String propertyName )
-        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
+        throws IntrospectionException, NoSuchMethodException;
 
     MappedPropertyGetterAccessor getMapped( String propertyName )
-        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
+        throws InvocationTargetException, NoSuchMethodException;
 
     B get();
 

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=1241046&r1=1241045&r2=1241046&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
Mon Feb  6 15:36:18 2012
@@ -20,8 +20,10 @@ package org.apache.commons.beanutils2;
  */
 
 import static java.lang.String.format;
+import static org.apache.commons.beanutils2.Assertions.checkArgument;
 import static org.apache.commons.beanutils2.Assertions.checkNotNull;
 
+import java.beans.IndexedPropertyDescriptor;
 import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.InvocationTargetException;
@@ -68,17 +70,31 @@ final class DefaultBeanAccessor<B>
      * {@inheritDoc}
      */
     public IndexedPropertyGetterAccessor getIndexed( String propertyName )
-        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
+        throws IntrospectionException, NoSuchMethodException
     {
-        // TODO
-        return null;
+        PropertyDescriptor propertyDescriptor = registry.getPropertyDescriptor( bean.getClass(),
propertyName );
+        propertyDescriptor = checkNotNull( propertyDescriptor, "Property '%s' does not exist
in bean of type %s",
+                                           propertyName, bean.getClass().getName() );
+        checkArgument( IndexedPropertyDescriptor.class.isInstance( propertyDescriptor ),
+                       "Property '%s' in bean of type %s is not an indexed property",
+                       propertyName, bean.getClass().getName() );
+
+        IndexedPropertyDescriptor indexedPropertyDescriptor = (IndexedPropertyDescriptor)
propertyDescriptor;
+
+        if ( indexedPropertyDescriptor.getIndexedReadMethod() == null )
+        {
+            throw new NoSuchMethodException( format( "Bean of type %s does not provide a
getter for indexed property '%s'!",
+                                                     bean.getClass().getName(), propertyName
) );
+        }
+
+        return new DefaultIndexedPropertyGetterAccessor( bean, propertyName, indexedPropertyDescriptor.getIndexedReadMethod()
);
     }
 
     /**
      * {@inheritDoc}
      */
     public MappedPropertyGetterAccessor getMapped( String propertyName )
-        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
+        throws InvocationTargetException, NoSuchMethodException
     {
         // TODO
         return null;

Added: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java?rev=1241046&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
Mon Feb  6 15:36:18 2012
@@ -0,0 +1,56 @@
+package org.apache.commons.beanutils2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.apache.commons.beanutils2.Assertions.checkArgument;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+final class DefaultIndexedPropertyGetterAccessor
+    implements IndexedPropertyGetterAccessor
+{
+
+    private final Object bean;
+
+    private final String propertyName;
+
+    private final Method indexedReadMethod;
+
+    public DefaultIndexedPropertyGetterAccessor( Object bean, String propertyName, Method
indexedReadMethod )
+    {
+        this.bean = bean;
+        this.propertyName = propertyName;
+        this.indexedReadMethod = indexedReadMethod;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BeanAccessor<?> at( int index )
+        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
+    {
+        checkArgument( index >= 0, "Indexed property '%s' in bean of type %s cannot be
get from a negative index %s",
+                       propertyName, bean.getClass().getName(), index );
+        Object indexedValue = indexedReadMethod.invoke( bean, index );
+        return new DefaultBeanAccessor<Object>( indexedValue );
+    }
+
+}

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertyGetterAccessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java?rev=1241046&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
Mon Feb  6 15:36:18 2012
@@ -0,0 +1,56 @@
+package org.apache.commons.beanutils2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.apache.commons.beanutils2.Assertions.checkArgument;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+final class DefaultIndexedPropertySetterAccessor
+    implements IndexedPropertyGetterAccessor
+{
+
+    private final Object bean;
+
+    private final String propertyName;
+
+    private final Method indexedReadMethod;
+
+    public DefaultIndexedPropertySetterAccessor( Object bean, String propertyName, Method
indexedReadMethod )
+    {
+        this.bean = bean;
+        this.propertyName = propertyName;
+        this.indexedReadMethod = indexedReadMethod;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BeanAccessor<?> at( int index )
+        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
+    {
+        checkArgument( index >= 0, "Indexed property '%s' in bean of type %s cannot be
get from a negative index %s",
+                       propertyName, bean.getClass().getName(), index );
+        Object indexedValue = indexedReadMethod.invoke( bean, index );
+        return new DefaultBeanAccessor<Object>( indexedValue );
+    }
+
+}

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultIndexedPropertySetterAccessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertyGetterAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertyGetterAccessor.java?rev=1241046&r1=1241045&r2=1241046&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertyGetterAccessor.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertyGetterAccessor.java
Mon Feb  6 15:36:18 2012
@@ -1,5 +1,7 @@
 package org.apache.commons.beanutils2;
 
+import java.lang.reflect.InvocationTargetException;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,6 +24,7 @@ package org.apache.commons.beanutils2;
 public interface IndexedPropertyGetterAccessor
 {
 
-    BeanAccessor<?> at( int index );
+    BeanAccessor<?> at( int index )
+        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;
 
 }

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertySetterAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertySetterAccessor.java?rev=1241046&r1=1241045&r2=1241046&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertySetterAccessor.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/IndexedPropertySetterAccessor.java
Mon Feb  6 15:36:18 2012
@@ -1,5 +1,7 @@
 package org.apache.commons.beanutils2;
 
+import java.lang.reflect.InvocationTargetException;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,6 +24,7 @@ package org.apache.commons.beanutils2;
 public interface IndexedPropertySetterAccessor<B>
 {
 
-    BeanPropertySetter<B> at( int index );
+    BeanPropertySetter<B> at( int index )
+        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;
 
 }



Mime
View raw message