下面列出了java.beans.IndexedPropertyDescriptor#getIndexedReadMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* If there is a regular non-indexed read method for this property,
* uses this method to obtain the collection and then returns its
* length.
* Otherwise, attempts to guess the length of the collection by
* calling the indexed get method repeatedly. The method is supposed
* to throw an exception if the index is out of bounds.
* @param object collection
* @param pd IndexedPropertyDescriptor
* @return int
*/
public static int getIndexedPropertyLength(Object object,
IndexedPropertyDescriptor pd) {
if (pd.getReadMethod() != null) {
return getLength(getValue(object, pd));
}
Method readMethod = pd.getIndexedReadMethod();
if (readMethod == null) {
throw new JXPathException(
"No indexed read method for property " + pd.getName());
}
for (int i = 0; i < UNKNOWN_LENGTH_MAX_COUNT; i++) {
try {
readMethod.invoke(object, new Integer(i));
}
catch (Throwable t) {
return i;
}
}
throw new JXPathException(
"Cannot determine the length of the indexed property "
+ pd.getName());
}
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());
}
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());
}
}
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());
}
}
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());
}
}
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 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);
}
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);
}