IndexedPropertyDescriptorpublic class IndexedPropertyDescriptor extends PropertyDescriptor
Fields Summary |
---|
private Method | indexedGetter | private Method | indexedSetter |
Constructors Summary |
---|
public IndexedPropertyDescriptor(String propertyName, Class beanClass, String getterName, String setterName, String indexedGetterName, String indexedSetterName)
super(propertyName, beanClass, getterName, setterName);
// RI behaves like this
if (indexedGetterName == null && indexedSetterName == null &&
(getterName != null || setterName != null)) {
throw new IntrospectionException(Messages.getString("beans.50"));
}
setIndexedReadMethod(beanClass, indexedGetterName);
setIndexedWriteMethod(beanClass, indexedSetterName);
| public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter, Method indexedGetter, Method indexedSetter)
super(propertyName, getter, setter);
// we need this in order to be compatible with RI
if (indexedGetter == null && indexedSetter == null &&
(getter != null || setter != null)) {
throw new IntrospectionException(Messages.getString("beans.50"));
}
setIndexedReadMethod(indexedGetter);
setIndexedWriteMethod(indexedSetter);
| public IndexedPropertyDescriptor(String propertyName, Class beanClass)
super(propertyName, beanClass, null, null);
String getterName;
String setterName;
String indexedGetterName;
String indexedSetterName;
// array getter
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
}
// array setter
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
}
// indexed getter
indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedGetterName)) {
setIndexedReadMethod(beanClass, indexedGetterName);
}
// indexed setter
indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedSetterName)) {
setIndexedWriteMethod(beanClass, indexedSetterName);
}
// RI seems to behave a bit differently
if (indexedGetter == null && indexedSetter == null &&
getReadMethod() == null && getWriteMethod() == null) {
throw new IntrospectionException(
Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
}
if (indexedGetter == null && indexedSetter == null) {
// not an indexed property indeed
throw new IntrospectionException(Messages.getString("beans.50"));
}
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)
boolean result = super.equals(obj);
if (result) {
IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) obj;
if (indexedGetter != null) {
result = indexedGetter.equals(pd.getIndexedReadMethod());
} else if (result && indexedGetter == null) {
result = pd.getIndexedReadMethod() == null;
}
if (result) {
if (indexedSetter != null) {
result = indexedSetter.equals(pd.getIndexedWriteMethod());
} else if (indexedSetter == null) {
result = pd.getIndexedWriteMethod() == null;
}
}
}
return result;
| public java.lang.Class | getIndexedPropertyType()
Class<?> result = null;
if (indexedGetter != null) {
result = indexedGetter.getReturnType();
} else if (indexedSetter != null) {
Class<?>[] parameterTypes = indexedSetter.getParameterTypes();
result = parameterTypes[1];
}
return result;
| public java.lang.reflect.Method | getIndexedReadMethod()
return indexedGetter;
| public java.lang.reflect.Method | getIndexedWriteMethod()
return indexedSetter;
| private void | setIndexedReadMethod(java.lang.Class beanClass, java.lang.String indexedGetterName)
Method[] getters = findMethods(beanClass, indexedGetterName);
boolean result = false;
for (Method element : getters) {
try {
setIndexedReadMethod(element);
result = true;
} catch (IntrospectionException ie) {}
if (result) {
break;
}
}
| public void | setIndexedReadMethod(java.lang.reflect.Method indexedGetter)
if (indexedGetter != null) {
int modifiers = indexedGetter.getModifiers();
Class<?>[] parameterTypes;
Class<?> returnType;
Class<?> indexedPropertyType;
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
}
parameterTypes = indexedGetter.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
}
if (!parameterTypes[0].equals(int.class)) {
throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
}
returnType = indexedGetter.getReturnType();
indexedPropertyType = getIndexedPropertyType();
if ((indexedPropertyType != null) && !returnType.equals(indexedPropertyType)) {
throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
}
}
this.indexedGetter = indexedGetter;
| private void | setIndexedWriteMethod(java.lang.Class beanClass, java.lang.String indexedSetterName)
Method[] setters = findMethods(beanClass, indexedSetterName);
boolean result = false;
for (Method element : setters) {
try {
setIndexedWriteMethod(element);
result = true;
} catch (IntrospectionException ie) {}
if (result) {
break;
}
}
| public void | setIndexedWriteMethod(java.lang.reflect.Method indexedSetter)
if (indexedSetter != null) {
int modifiers = indexedSetter.getModifiers();
Class<?>[] parameterTypes;
Class<?> firstParameterType;
Class<?> secondParameterType;
Class<?> propType;
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
}
parameterTypes = indexedSetter.getParameterTypes();
if (parameterTypes.length != 2) {
throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
}
firstParameterType = parameterTypes[0];
if (!firstParameterType.equals(int.class)) {
throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
}
secondParameterType = parameterTypes[1];
propType = getIndexedPropertyType();
if (propType != null && !secondParameterType.equals(propType)) {
throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
}
}
this.indexedSetter = indexedSetter;
|
|