You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2006/11/10 22:24:29 UTC
svn commit: r473499 -
/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java
Author: jcompagner
Date: Fri Nov 10 13:24:28 2006
New Revision: 473499
URL: http://svn.apache.org/viewvc?view=rev&rev=473499
Log:
PropertyResolver private fields reflection
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java?view=diff&rev=473499&r1=473498&r2=473499
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/PropertyResolver.java Fri Nov 10 13:24:28 2006
@@ -231,13 +231,8 @@
else
{
method = findGetter(clz, exp);
- if (method == null)
- {
- // find field.
- field = findField(clz, exp);
- }
}
- if (method == null && field == null)
+ if (method == null)
{
if (List.class.isAssignableFrom(clz))
{
@@ -288,53 +283,57 @@
}
else
{
- method = findMethod(clz, exp);
- if (method == null)
+ field = findField(clz, exp);
+ if(field == null)
{
- int index = exp.indexOf('.');
- if (index != -1)
+ method = findMethod(clz, exp);
+ if (method == null)
{
- String propertyName = exp.substring(0, index);
- String propertyIndex = exp.substring(index + 1);
- try
+ int index = exp.indexOf('.');
+ if (index != -1)
{
-
- int parsedIndex = Integer.parseInt(propertyIndex);
- // if so then it could be a
- // getPropertyIndex(int)
- // and setPropertyIndex(int, object)
- String name = Character.toUpperCase(propertyName.charAt(0))
- + propertyName.substring(1);
- method = clz.getMethod("get" + name, new Class[] { int.class });
- getAndSetter = new ArrayPropertyGetSet(method, parsedIndex);
-
+ String propertyName = exp.substring(0, index);
+ String propertyIndex = exp.substring(index + 1);
+ try
+ {
+
+ int parsedIndex = Integer.parseInt(propertyIndex);
+ // if so then it could be a
+ // getPropertyIndex(int)
+ // and setPropertyIndex(int, object)
+ String name = Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
+ method = clz.getMethod("get" + name, new Class[] { int.class });
+ getAndSetter = new ArrayPropertyGetSet(method, parsedIndex);
+
+ }
+ catch (Exception e)
+ {
+ throw new WicketRuntimeException(
+ "no get method defined for class: " + clz + " expression: "
+ + propertyName);
+ }
}
- catch (Exception e)
+ else
{
- throw new WicketRuntimeException(
- "no get method defined for class: " + clz + " expression: "
- + propertyName);
+ // We do not look for a public FIELD because that is
+ // not good
+ // programming with beans patterns
+ throw new WicketRuntimeException("No get method defined for class: "
+ + clz + " expression: " + exp);
}
}
else
{
- // We do not look for a public FIELD because that is
- // not good
- // programming with beans patterns
- throw new WicketRuntimeException("No get method defined for class: "
- + clz + " expression: " + exp);
+ getAndSetter = new MethodGetAndSet(method);
}
}
else
{
- getAndSetter = new MethodGetAndSet(method);
+ getAndSetter = new FieldGetAndSetter(field);
}
}
}
- else if (field != null)
- {
- getAndSetter = new FieldGetAndSetter(field);
- }
else
{
getAndSetter = new MethodGetAndSet(method);
@@ -359,6 +358,20 @@
}
catch (Exception e)
{
+ Class tmp = clz;
+ while(tmp != null && tmp != Object.class)
+ {
+ Field[] fields = tmp.getDeclaredFields();
+ for (int i = 0; i < fields.length; i++)
+ {
+ if(fields[i].getName().equals(expression))
+ {
+ fields[i].setAccessible(true);
+ return fields[i];
+ }
+ }
+ tmp = tmp.getSuperclass();
+ }
log.debug("Cannot find field " + clz + "." + expression, e);
}
return field;