Java Code Examples for java.beans.IndexedPropertyDescriptor#getIndexedPropertyType()

The following examples show how to use java.beans.IndexedPropertyDescriptor#getIndexedPropertyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedBeanInfo.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
	for (PropertyDescriptor pd : this.propertyDescriptors) {
		final Class<?> candidateType;
		final String candidateName = pd.getName();
		if (pd instanceof IndexedPropertyDescriptor) {
			IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
			candidateType = ipd.getIndexedPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
				return pd;
			}
		}
		else {
			candidateType = pd.getPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
				return pd;
			}
		}
	}
	return null;
}
 
Example 2
Source File: ExtendedBeanInfo.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
	for (PropertyDescriptor pd : this.propertyDescriptors) {
		final Class<?> candidateType;
		final String candidateName = pd.getName();
		if (pd instanceof IndexedPropertyDescriptor) {
			IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
			candidateType = ipd.getIndexedPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
				return pd;
			}
		}
		else {
			candidateType = pd.getPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
				return pd;
			}
		}
	}
	return null;
}
 
Example 3
Source File: ExtendedBeanInfo.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Nullable
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
	for (PropertyDescriptor pd : this.propertyDescriptors) {
		final Class<?> candidateType;
		final String candidateName = pd.getName();
		if (pd instanceof IndexedPropertyDescriptor) {
			IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
			candidateType = ipd.getIndexedPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
				return pd;
			}
		}
		else {
			candidateType = pd.getPropertyType();
			if (candidateName.equals(propertyName) &&
					(candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
				return pd;
			}
		}
	}
	return null;
}
 
Example 4
Source File: Test8027648.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 5
Source File: Test8027648.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 6
Source File: Test4619536.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 7
Source File: Test4619536.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 8
Source File: BeanBuilder.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setProperty(Object instance, String property, int index, Object value)
            throws IllegalAccessException, InvocationTargetException {
        IndexedPropertyDescriptor desc = (IndexedPropertyDescriptor) propertyMap.get(property);
        if (desc == null) {
            throw new IllegalArgumentException("Invalid property '" + property + "'");
        }
        Method meth = desc.getIndexedWriteMethod();
        Class propertyType = desc.getIndexedPropertyType();
        Object arg = getPropertyTypeValue(propertyType, value);
//        System.out.println("Invoking: " + meth.getName() + " Index = " + index + " arg = " + arg);
        meth.invoke(instance, new Object[]{new Integer(index), arg});
    }
 
Example 9
Source File: Test4619536.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 10
Source File: Test4619536.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 11
Source File: Test8027648.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 12
Source File: BeanUtility.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Class getPropertyType( final PropertyDescriptor pd ) throws BeanException {
  final Class typeFromDescriptor = pd.getPropertyType();
  if ( typeFromDescriptor != null ) {
    return typeFromDescriptor;
  }
  if ( pd instanceof IndexedPropertyDescriptor ) {
    final IndexedPropertyDescriptor idx = (IndexedPropertyDescriptor) pd;
    return idx.getIndexedPropertyType();
  }
  throw new BeanException( "Unable to determine the property type." );
}
 
Example 13
Source File: Test8027648.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 14
Source File: Test4619536.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 15
Source File: Test4619536.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 16
Source File: Test8027648.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 17
Source File: Test4619536.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
    if (null == ipd.getIndexedPropertyType()) {
        return false;
    }
    return (null != ipd.getIndexedReadMethod())
        || (null != ipd.getIndexedWriteMethod());
}
 
Example 18
Source File: Test8027648.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
    PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        return ipd.getIndexedPropertyType();
    }
    return pd.getPropertyType();
}
 
Example 19
Source File: ReflectionUtils.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
 * Set a property of a bean to a given value.
 *
 * @param target    the object whose prop is to be set
 * @param propName  name of the property to set
 * @param index     index to set (if property is indexed)
 * @param value     the property value
 * @param valueType the type of the above (needed when its null)
 * @param tcr       type convertor registry to use to convert value type to
 *                  property type if necessary
 *
 * @exception IntrospectionException if unable to introspect
 * @exception IllegalArgumentException if problems with args: if the
 *            property is unknown, or if the property is given an index
 *            when its not, or if the property is not writeable, or if
 *            the given value cannot be assigned to the it (type mismatch).
 * @exception IllegalAccessException if write method is not accessible
 * @exception InvocationTargetException if write method excepts
 */
public static void setProperty (Object target, String propName,
                Integer index, Object value,
                Class valueType, TypeConvertorRegistry tcr)
     throws IntrospectionException, IllegalArgumentException,
            IllegalAccessException, InvocationTargetException {
  // find the property descriptor
  BeanInfo bi = Introspector.getBeanInfo (target.getClass ());
  PropertyDescriptor pd = (PropertyDescriptor)
    findFeatureByName ("property", propName, bi.getPropertyDescriptors ());
  if (pd == null) {
    throw new IllegalArgumentException ("property '" + propName + "' is " +
                        "unknown for '" + target + "'");
  }

  // get write method and type of property
  Method wm;
  Class propType;
  if (index != null) {
    // if index != null, then property is indexed - pd better be so too
    if (!(pd instanceof IndexedPropertyDescriptor)) {
      throw new IllegalArgumentException ("attempt to set non-indexed " +
                          "property '" + propName +
                                          "' as being indexed");
    }
    IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
    wm = ipd.getIndexedWriteMethod ();
    propType = ipd.getIndexedPropertyType ();
  } else {
    wm = pd.getWriteMethod ();
    propType = pd.getPropertyType ();
  }

  if (wm == null) {
    throw new IllegalArgumentException ("property '" + propName +
                        "' is not writeable");
  }

  // type convert the value if necessary
  Object propVal = null;
  boolean okeydokey = true;
  if (propType.isAssignableFrom (valueType)) {
    propVal = value;
  } else if (tcr != null) {
    TypeConvertor cvtor = tcr.lookup (valueType, propType);
    if (cvtor != null) {
      propVal = cvtor.convert (valueType, propType, value);
    } else {
      okeydokey = false;
    }
  } else {
    okeydokey = false;
  }
  if (!okeydokey) {
    throw new IllegalArgumentException ("unable to assign '" + value +
                        "' to property '" + propName + "'");
  }

  // now set the value
  if (index != null) {
    wm.invoke (target, new Object[] {index, propVal});
  } else {
    wm.invoke (target, new Object[] {propVal});
  }
}
 
Example 20
Source File: ReflectionUtils.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
 * Get a property of a bean.
 *
 * @param target    the object whose prop is to be gotten
 * @param propName  name of the property to set
 * @param index     index to get (if property is indexed)
 *
 * @exception IntrospectionException if unable to introspect
 * @exception IllegalArgumentException if problems with args: if the
 *            property is unknown, or if the property is given an index
 *            when its not, or if the property is not writeable, or if
 *            the given value cannot be assigned to the it (type mismatch).
 * @exception IllegalAccessException if read method is not accessible
 * @exception InvocationTargetException if read method excepts
 */
public static Bean getProperty (Object target, String propName,
                Integer index)
     throws IntrospectionException, IllegalArgumentException,
            IllegalAccessException, InvocationTargetException {
  // find the property descriptor
  BeanInfo bi = Introspector.getBeanInfo (target.getClass ());
  PropertyDescriptor pd = (PropertyDescriptor)
    findFeatureByName ("property", propName, bi.getPropertyDescriptors ());
  if (pd == null) {
    throw new IllegalArgumentException ("property '" + propName + "' is " +
                        "unknown for '" + target + "'");
  }

  // get read method and type of property
  Method rm;
  Class propType;
  if (index != null) {
    // if index != null, then property is indexed - pd better be so too
    if (!(pd instanceof IndexedPropertyDescriptor)) {
      throw new IllegalArgumentException ("attempt to get non-indexed " +
                          "property '" + propName +
                          "' as being indexed");
    }
    IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
    rm = ipd.getIndexedReadMethod ();
    propType = ipd.getIndexedPropertyType ();
  } else {
    rm = pd.getReadMethod ();
    propType = pd.getPropertyType ();
  }

  if (rm == null) {
    throw new IllegalArgumentException ("property '" + propName +
                        "' is not readable");
  }

  // now get the value
  Object propVal = null;
  if (index != null) {
    propVal = rm.invoke (target, new Object[] {index});
  } else {
    propVal = rm.invoke (target, null);
  }
  return new Bean (propType, propVal);
}