src/share/classes/java/beans/PropertyDescriptor.java

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


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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 import java.lang.reflect.Constructor;
  31 
  32 /**
  33  * A PropertyDescriptor describes one property that a Java Bean
  34  * exports via a pair of accessor methods.

  35  */
  36 public class PropertyDescriptor extends FeatureDescriptor {
  37 
  38     private Reference<? extends Class<?>> propertyTypeRef;
  39     private final MethodRef readMethodRef = new MethodRef();
  40     private final MethodRef writeMethodRef = new MethodRef();
  41     private Reference<? extends Class<?>> propertyEditorClassRef;
  42 
  43     private boolean bound;
  44     private boolean constrained;
  45 
  46     // The base name of the method name which will be prefixed with the
  47     // read and write method. If name == "foo" then the baseName is "Foo"
  48     private String baseName;
  49 
  50     private String writeMethodName;
  51     private String readMethodName;
  52 
  53     /**
  54      * Constructs a PropertyDescriptor for a property that follows


 227             // reader method so look for this one first.
 228             readMethod = Introspector.findMethod(cls, readMethodName, 0);
 229             if ((readMethod == null) && !readMethodName.equals(nextMethodName)) {
 230                 readMethodName = nextMethodName;
 231                 readMethod = Introspector.findMethod(cls, readMethodName, 0);
 232             }
 233             try {
 234                 setReadMethod(readMethod);
 235             } catch (IntrospectionException ex) {
 236                 // fall
 237             }
 238         }
 239         return readMethod;
 240     }
 241 
 242     /**
 243      * Sets the method that should be used to read the property value.
 244      *
 245      * @param readMethod The new read method.
 246      * @throws IntrospectionException if the read method is invalid

 247      */
 248     public synchronized void setReadMethod(Method readMethod)
 249                                 throws IntrospectionException {
 250         this.readMethodRef.set(readMethod);
 251         if (readMethod == null) {
 252             readMethodName = null;
 253             return;
 254         }
 255         // The property type is determined by the read method.
 256         setPropertyType(findPropertyType(readMethod, this.writeMethodRef.get()));
 257         setClass0(readMethod.getDeclaringClass());
 258 
 259         readMethodName = readMethod.getName();
 260         setTransient(readMethod.getAnnotation(Transient.class));
 261     }
 262 
 263     /**
 264      * Gets the method that should be used to write the property value.
 265      *
 266      * @return The method that should be used to write the property value.


 297             writeMethod = Introspector.findMethod(cls, writeMethodName, 1, args);
 298             if (writeMethod != null) {
 299                 if (!writeMethod.getReturnType().equals(void.class)) {
 300                     writeMethod = null;
 301                 }
 302             }
 303             try {
 304                 setWriteMethod(writeMethod);
 305             } catch (IntrospectionException ex) {
 306                 // fall through
 307             }
 308         }
 309         return writeMethod;
 310     }
 311 
 312     /**
 313      * Sets the method that should be used to write the property value.
 314      *
 315      * @param writeMethod The new write method.
 316      * @throws IntrospectionException if the write method is invalid

 317      */
 318     public synchronized void setWriteMethod(Method writeMethod)
 319                                 throws IntrospectionException {
 320         this.writeMethodRef.set(writeMethod);
 321         if (writeMethod == null) {
 322             writeMethodName = null;
 323             return;
 324         }
 325         // Set the property type - which validates the method
 326         setPropertyType(findPropertyType(getReadMethod(), writeMethod));
 327         setClass0(writeMethod.getDeclaringClass());
 328 
 329         writeMethodName = writeMethod.getName();
 330         setTransient(writeMethod.getAnnotation(Transient.class));
 331     }
 332 
 333     /**
 334      * Overridden to ensure that a super class doesn't take precedent
 335      */
 336     void setClass0(Class<?> clz) {




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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 import java.lang.reflect.Constructor;
  31 
  32 /**
  33  * A PropertyDescriptor describes one property that a Java Bean
  34  * exports via a pair of accessor methods.
  35  * @since 1.1
  36  */
  37 public class PropertyDescriptor extends FeatureDescriptor {
  38 
  39     private Reference<? extends Class<?>> propertyTypeRef;
  40     private final MethodRef readMethodRef = new MethodRef();
  41     private final MethodRef writeMethodRef = new MethodRef();
  42     private Reference<? extends Class<?>> propertyEditorClassRef;
  43 
  44     private boolean bound;
  45     private boolean constrained;
  46 
  47     // The base name of the method name which will be prefixed with the
  48     // read and write method. If name == "foo" then the baseName is "Foo"
  49     private String baseName;
  50 
  51     private String writeMethodName;
  52     private String readMethodName;
  53 
  54     /**
  55      * Constructs a PropertyDescriptor for a property that follows


 228             // reader method so look for this one first.
 229             readMethod = Introspector.findMethod(cls, readMethodName, 0);
 230             if ((readMethod == null) && !readMethodName.equals(nextMethodName)) {
 231                 readMethodName = nextMethodName;
 232                 readMethod = Introspector.findMethod(cls, readMethodName, 0);
 233             }
 234             try {
 235                 setReadMethod(readMethod);
 236             } catch (IntrospectionException ex) {
 237                 // fall
 238             }
 239         }
 240         return readMethod;
 241     }
 242 
 243     /**
 244      * Sets the method that should be used to read the property value.
 245      *
 246      * @param readMethod The new read method.
 247      * @throws IntrospectionException if the read method is invalid
 248      * @since 1.2
 249      */
 250     public synchronized void setReadMethod(Method readMethod)
 251                                 throws IntrospectionException {
 252         this.readMethodRef.set(readMethod);
 253         if (readMethod == null) {
 254             readMethodName = null;
 255             return;
 256         }
 257         // The property type is determined by the read method.
 258         setPropertyType(findPropertyType(readMethod, this.writeMethodRef.get()));
 259         setClass0(readMethod.getDeclaringClass());
 260 
 261         readMethodName = readMethod.getName();
 262         setTransient(readMethod.getAnnotation(Transient.class));
 263     }
 264 
 265     /**
 266      * Gets the method that should be used to write the property value.
 267      *
 268      * @return The method that should be used to write the property value.


 299             writeMethod = Introspector.findMethod(cls, writeMethodName, 1, args);
 300             if (writeMethod != null) {
 301                 if (!writeMethod.getReturnType().equals(void.class)) {
 302                     writeMethod = null;
 303                 }
 304             }
 305             try {
 306                 setWriteMethod(writeMethod);
 307             } catch (IntrospectionException ex) {
 308                 // fall through
 309             }
 310         }
 311         return writeMethod;
 312     }
 313 
 314     /**
 315      * Sets the method that should be used to write the property value.
 316      *
 317      * @param writeMethod The new write method.
 318      * @throws IntrospectionException if the write method is invalid
 319      * @since 1.2
 320      */
 321     public synchronized void setWriteMethod(Method writeMethod)
 322                                 throws IntrospectionException {
 323         this.writeMethodRef.set(writeMethod);
 324         if (writeMethod == null) {
 325             writeMethodName = null;
 326             return;
 327         }
 328         // Set the property type - which validates the method
 329         setPropertyType(findPropertyType(getReadMethod(), writeMethod));
 330         setClass0(writeMethod.getDeclaringClass());
 331 
 332         writeMethodName = writeMethod.getName();
 333         setTransient(writeMethod.getAnnotation(Transient.class));
 334     }
 335 
 336     /**
 337      * Overridden to ensure that a super class doesn't take precedent
 338      */
 339     void setClass0(Class<?> clz) {