下面列出了java.beans.IndexedPropertyDescriptor#getIndexedWriteMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
private static PropertyDescriptor create(PropertyDescriptor pd) {
try {
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return new IndexedPropertyDescriptor(
ipd.getName(),
ipd.getReadMethod(),
ipd.getWriteMethod(),
ipd.getIndexedReadMethod(),
ipd.getIndexedWriteMethod());
} else {
return new PropertyDescriptor(
pd.getName(),
pd.getReadMethod(),
pd.getWriteMethod());
}
}
catch (IntrospectionException exception) {
exception.printStackTrace();
return null;
}
}
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
if (null == ipd.getIndexedPropertyType()) {
return false;
}
return (null != ipd.getIndexedReadMethod())
|| (null != ipd.getIndexedWriteMethod());
}
/**
* Modifies the index'th element of the bean's property represented by
* the supplied property descriptor. Converts the value to the required
* type if necessary.
* @param bean to edit
* @param propertyDescriptor indicating what to set
* @param index int
* @param value to set
*/
public static void setValue(Object bean,
PropertyDescriptor propertyDescriptor, int index, Object value) {
if (propertyDescriptor instanceof IndexedPropertyDescriptor) {
try {
IndexedPropertyDescriptor ipd =
(IndexedPropertyDescriptor) propertyDescriptor;
Method method = ipd.getIndexedWriteMethod();
if (method != null) {
method.invoke(
bean,
new Integer(index),
convert(value, ipd.getIndexedPropertyType()));
return;
}
}
catch (Exception ex) {
throw new RuntimeException(
"Cannot access property: "
+ propertyDescriptor.getName()
+ ", "
+ ex.getMessage());
}
}
// We will fall through if there is no indexed read
Object collection = getValue(bean, propertyDescriptor);
if (isCollection(collection)) {
setValue(collection, index, value);
}
else if (index == 0) {
setValue(bean, propertyDescriptor, value);
}
else {
throw new RuntimeException(
"Not a collection: " + propertyDescriptor.getName());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
if (null == ipd.getIndexedPropertyType()) {
return false;
}
return (null != ipd.getIndexedReadMethod())
|| (null != ipd.getIndexedWriteMethod());
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
private static void testIndexedPropertyDescriptor(Class type, Class read, Class write) {
IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(type, "foo");
if (!read.equals(ipd.getIndexedReadMethod().getDeclaringClass())) {
throw new Error("unexpected read method: " + ipd.getIndexedReadMethod());
}
if (!write.equals(ipd.getIndexedWriteMethod().getDeclaringClass())) {
throw new Error("unexpected write method: " + ipd.getIndexedWriteMethod());
}
}
public static boolean hasIPD(IndexedPropertyDescriptor ipd) {
if (null == ipd.getIndexedPropertyType()) {
return false;
}
return (null != ipd.getIndexedReadMethod())
|| (null != ipd.getIndexedWriteMethod());
}
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
original.getIndexedReadMethod(), original.getIndexedWriteMethod());
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
}
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
original.getIndexedReadMethod(), original.getIndexedWriteMethod());
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
}
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
original.getIndexedReadMethod(), original.getIndexedWriteMethod());
copyNonMethodProperties(original, this);
}