src/share/classes/java/beans/IndexedPropertyDescriptor.java

Print this page
rev 10053 : 8044855: Add missing @since tag under java.beans.*
Reviewed-by:


  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.beans;
  27 
  28 import java.lang.ref.Reference;
  29 import java.lang.reflect.Method;
  30 
  31 /**
  32  * An IndexedPropertyDescriptor describes a property that acts like an
  33  * array and has an indexed read and/or indexed write method to access
  34  * specific elements of the array.
  35  * <p>
  36  * An indexed property may also provide simple non-indexed read and write
  37  * methods.  If these are present, they read and write arrays of the type
  38  * returned by the indexed read method.


  39  */
  40 
  41 public class IndexedPropertyDescriptor extends PropertyDescriptor {
  42 
  43     private Reference<? extends Class<?>> indexedPropertyTypeRef;
  44     private final MethodRef indexedReadMethodRef = new MethodRef();
  45     private final MethodRef indexedWriteMethodRef = new MethodRef();
  46 
  47     private String indexedReadMethodName;
  48     private String indexedWriteMethodName;
  49 
  50     /**
  51      * This constructor constructs an IndexedPropertyDescriptor for a property
  52      * that follows the standard Java conventions by having getFoo and setFoo
  53      * accessor methods, for both indexed access and array access.
  54      * <p>
  55      * Thus if the argument name is "fred", it will assume that there
  56      * is an indexed reader method "getFred", a non-indexed (array) reader
  57      * method also called "getFred", an indexed writer method "setFred",
  58      * and finally a non-indexed writer method "setFred".


 192             }
 193 
 194             Class<?>[] args = { int.class };
 195             indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
 196             if ((indexedReadMethod == null) && !indexedReadMethodName.equals(nextMethodName)) {
 197                 // no "is" method, so look for a "get" method.
 198                 indexedReadMethodName = nextMethodName;
 199                 indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
 200             }
 201             setIndexedReadMethod0(indexedReadMethod);
 202         }
 203         return indexedReadMethod;
 204     }
 205 
 206     /**
 207      * Sets the method that should be used to read an indexed property value.
 208      *
 209      * @param readMethod The new indexed read method.
 210      * @throws IntrospectionException if an exception occurs during
 211      * introspection.


 212      */
 213     public synchronized void setIndexedReadMethod(Method readMethod)
 214         throws IntrospectionException {
 215 
 216         // the indexed property type is set by the reader.
 217         setIndexedPropertyType(findIndexedPropertyType(readMethod,
 218                                                        this.indexedWriteMethodRef.get()));
 219         setIndexedReadMethod0(readMethod);
 220     }
 221 
 222     private void setIndexedReadMethod0(Method readMethod) {
 223         this.indexedReadMethodRef.set(readMethod);
 224         if (readMethod == null) {
 225             indexedReadMethodName = null;
 226             return;
 227         }
 228         setClass0(readMethod.getDeclaringClass());
 229 
 230         indexedReadMethodName = readMethod.getName();
 231         setTransient(readMethod.getAnnotation(Transient.class));


 271             }
 272 
 273             Class<?>[] args = (type == null) ? null : new Class<?>[] { int.class, type };
 274             indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName, 2, args);
 275             if (indexedWriteMethod != null) {
 276                 if (!indexedWriteMethod.getReturnType().equals(void.class)) {
 277                     indexedWriteMethod = null;
 278                 }
 279             }
 280             setIndexedWriteMethod0(indexedWriteMethod);
 281         }
 282         return indexedWriteMethod;
 283     }
 284 
 285     /**
 286      * Sets the method that should be used to write an indexed property value.
 287      *
 288      * @param writeMethod The new indexed write method.
 289      * @throws IntrospectionException if an exception occurs during
 290      * introspection.


 291      */
 292     public synchronized void setIndexedWriteMethod(Method writeMethod)
 293         throws IntrospectionException {
 294 
 295         // If the indexed property type has not been set, then set it.
 296         Class<?> type = findIndexedPropertyType(getIndexedReadMethod(),
 297                                              writeMethod);
 298         setIndexedPropertyType(type);
 299         setIndexedWriteMethod0(writeMethod);
 300     }
 301 
 302     private void setIndexedWriteMethod0(Method writeMethod) {
 303         this.indexedWriteMethodRef.set(writeMethod);
 304         if (writeMethod == null) {
 305             indexedWriteMethodName = null;
 306             return;
 307         }
 308         setClass0(writeMethod.getDeclaringClass());
 309 
 310         indexedWriteMethodName = writeMethod.getName();




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.beans;
  27 
  28 import java.lang.ref.Reference;
  29 import java.lang.reflect.Method;
  30 
  31 /**
  32  * An IndexedPropertyDescriptor describes a property that acts like an
  33  * array and has an indexed read and/or indexed write method to access
  34  * specific elements of the array.
  35  * <p>
  36  * An indexed property may also provide simple non-indexed read and write
  37  * methods.  If these are present, they read and write arrays of the type
  38  * returned by the indexed read method.
  39  *
  40  * @since 1.1
  41  */
  42 
  43 public class IndexedPropertyDescriptor extends PropertyDescriptor {
  44 
  45     private Reference<? extends Class<?>> indexedPropertyTypeRef;
  46     private final MethodRef indexedReadMethodRef = new MethodRef();
  47     private final MethodRef indexedWriteMethodRef = new MethodRef();
  48 
  49     private String indexedReadMethodName;
  50     private String indexedWriteMethodName;
  51 
  52     /**
  53      * This constructor constructs an IndexedPropertyDescriptor for a property
  54      * that follows the standard Java conventions by having getFoo and setFoo
  55      * accessor methods, for both indexed access and array access.
  56      * <p>
  57      * Thus if the argument name is "fred", it will assume that there
  58      * is an indexed reader method "getFred", a non-indexed (array) reader
  59      * method also called "getFred", an indexed writer method "setFred",
  60      * and finally a non-indexed writer method "setFred".


 194             }
 195 
 196             Class<?>[] args = { int.class };
 197             indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
 198             if ((indexedReadMethod == null) && !indexedReadMethodName.equals(nextMethodName)) {
 199                 // no "is" method, so look for a "get" method.
 200                 indexedReadMethodName = nextMethodName;
 201                 indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
 202             }
 203             setIndexedReadMethod0(indexedReadMethod);
 204         }
 205         return indexedReadMethod;
 206     }
 207 
 208     /**
 209      * Sets the method that should be used to read an indexed property value.
 210      *
 211      * @param readMethod The new indexed read method.
 212      * @throws IntrospectionException if an exception occurs during
 213      * introspection.
 214      *
 215      * @since 1.2
 216      */
 217     public synchronized void setIndexedReadMethod(Method readMethod)
 218         throws IntrospectionException {
 219 
 220         // the indexed property type is set by the reader.
 221         setIndexedPropertyType(findIndexedPropertyType(readMethod,
 222                                                        this.indexedWriteMethodRef.get()));
 223         setIndexedReadMethod0(readMethod);
 224     }
 225 
 226     private void setIndexedReadMethod0(Method readMethod) {
 227         this.indexedReadMethodRef.set(readMethod);
 228         if (readMethod == null) {
 229             indexedReadMethodName = null;
 230             return;
 231         }
 232         setClass0(readMethod.getDeclaringClass());
 233 
 234         indexedReadMethodName = readMethod.getName();
 235         setTransient(readMethod.getAnnotation(Transient.class));


 275             }
 276 
 277             Class<?>[] args = (type == null) ? null : new Class<?>[] { int.class, type };
 278             indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName, 2, args);
 279             if (indexedWriteMethod != null) {
 280                 if (!indexedWriteMethod.getReturnType().equals(void.class)) {
 281                     indexedWriteMethod = null;
 282                 }
 283             }
 284             setIndexedWriteMethod0(indexedWriteMethod);
 285         }
 286         return indexedWriteMethod;
 287     }
 288 
 289     /**
 290      * Sets the method that should be used to write an indexed property value.
 291      *
 292      * @param writeMethod The new indexed write method.
 293      * @throws IntrospectionException if an exception occurs during
 294      * introspection.
 295      *
 296      * @since 1.2
 297      */
 298     public synchronized void setIndexedWriteMethod(Method writeMethod)
 299         throws IntrospectionException {
 300 
 301         // If the indexed property type has not been set, then set it.
 302         Class<?> type = findIndexedPropertyType(getIndexedReadMethod(),
 303                                              writeMethod);
 304         setIndexedPropertyType(type);
 305         setIndexedWriteMethod0(writeMethod);
 306     }
 307 
 308     private void setIndexedWriteMethod0(Method writeMethod) {
 309         this.indexedWriteMethodRef.set(writeMethod);
 310         if (writeMethod == null) {
 311             indexedWriteMethodName = null;
 312             return;
 313         }
 314         setClass0(writeMethod.getDeclaringClass());
 315 
 316         indexedWriteMethodName = writeMethod.getName();