예제 #1
0
  /**
   * Sets the method that should be used to read the property value.
   *
   * @param readMethod The new read method.
   */
  public synchronized void setReadMethod(Method readMethod) throws IntrospectionException {
    if (readMethod == null) {
      readMethodName = null;
      readMethodRef = null;
      return;
    }
    // The property type is determined by the read method.
    setPropertyType(findPropertyType(readMethod, getWriteMethod0()));
    setClass0(readMethod.getDeclaringClass());

    readMethodName = readMethod.getName();
    readMethodRef = createReference(readMethod, true);
  }
예제 #2
0
  /**
   * Sets the method that should be used to write the property value.
   *
   * @param writeMethod The new write method.
   */
  public synchronized void setWriteMethod(Method writeMethod) throws IntrospectionException {
    if (writeMethod == null) {
      writeMethodName = null;
      writeMethodRef = null;
      return;
    }
    // Set the property type - which validates the method
    setPropertyType(findPropertyType(getReadMethod(), writeMethod));
    setClass0(writeMethod.getDeclaringClass());

    writeMethodName = writeMethod.getName();
    writeMethodRef = createReference(writeMethod, true);
  }
예제 #3
0
  /**
   * This constructor takes the name of a simple property, and method names for reading and writing
   * the property.
   *
   * @param propertyName The programmatic name of the property.
   * @param beanClass The Class object for the target bean. For example sun.beans.OurButton.class.
   * @param readMethodName The name of the method used for reading the property value. May be null
   *     if the property is write-only.
   * @param writeMethodName The name of the method used for writing the property value. May be null
   *     if the property is read-only.
   * @exception IntrospectionException if an exception occurs during introspection.
   */
  public PropertyDescriptor(
      String propertyName, Class<?> beanClass, String readMethodName, String writeMethodName)
      throws IntrospectionException {
    if (beanClass == null) {
      throw new IntrospectionException("Target Bean class is null");
    }
    if (propertyName == null || propertyName.length() == 0) {
      throw new IntrospectionException("bad property name");
    }
    if ("".equals(readMethodName) || "".equals(writeMethodName)) {
      throw new IntrospectionException("read or write method name should not be the empty string");
    }
    setName(propertyName);
    setClass0(beanClass);

    this.readMethodName = readMethodName;
    if (readMethodName != null && getReadMethod() == null) {
      throw new IntrospectionException("Method not found: " + readMethodName);
    }
    this.writeMethodName = writeMethodName;
    if (writeMethodName != null && getWriteMethod() == null) {
      throw new IntrospectionException("Method not found: " + writeMethodName);
    }
  }