@@ -0,0 +1,2152 @@
+package com.peterphi.std.guice.hibernate.webquery.impl;%0A%0Aimport org.apache.commons.lang.StringUtils;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0A%0Apublic class PropertyWrapper%0A%7B%0A%09public final Class%3C?%3E clazz;%0A%0A%09public final String name;%0A%0A%09public Field field;%0A%0A%09public Method getter;%0A%09public Method setter;%0A%0A%0A%09public PropertyWrapper(final Class%3C?%3E clazz, final String name)%0A%09%7B%0A%09%09this.clazz = clazz;%0A%09%09this.name = name;%0A%0A%09%09%7B%0A%09%09%09final String getterName = %22get%22 + name;%0A%09%09%09final String setterName = %22set%22 + name;%0A%0A%09%09%09for (Method method : clazz.getMethods())%0A%09%09%09%7B%0A%09%09%09%09if (getter == null && StringUtils.equalsIgnoreCase(method.getName(), getterName))%0A%09%09%09%09%09getter = method;%0A%09%09%09%09else if (setter == null && StringUtils.equalsIgnoreCase(method.getName(), setterName))%0A%09%09%09%09%09setter = method;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09if (getter == null && setter == null)%0A%09%09%7B%0A%09%09%09try%0A%09%09%09%7B%0A%09%09%09%09field = clazz.getField(name);%0A%09%09%09%7D%0A%09%09%09catch (NoSuchFieldException e)%0A%09%09%09%7B%0A%09%09%09%09throw new RuntimeException(%22Unable to find field/getter for %22 + clazz + %22 property %22 + name, e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%0A%09public void set(final Object object, Object value)%0A%09%7B%0A%09%09try%0A%09%09%7B%0A%09%09%09if (field != null)%0A%09%09%09%09field.set(object, value);%0A%09%09%09else if (setter != null)%0A%09%09%09%09setter.invoke(object, value);%0A%09%09%09else%0A%09%09%09%09throw new IllegalArgumentException(%22No Field or Setter stored!%22);%0A%09%09%7D%0A%09%09catch (IllegalAccessException %7C InvocationTargetException e)%0A%09%09%7B%0A%09%09%09throw new RuntimeException(%22Error calling field.set or setter.invoke%22, e);%0A%09%09%7D%0A%09%7D%0A%0A%0A%09public Object get(final Object object)%0A%09%7B%0A%09%09try%0A%09%09%7B%0A%09%09%09if (field != null)%0A%09%09%09%09return field.get(object);%0A%09%09%09else if (setter != null)%0A%09%09%09%09return getter.invoke(object);%0A%09%09%09else%0A%09%09%09%09throw new IllegalArgumentException(%22No Field or Getter stored!%22);%0A%09%09%7D%0A%09%09catch (IllegalAccessException %7C InvocationTargetException e)%0A%09%09%7B%0A%09%09%09throw new RuntimeException(%22Error calling field.get or getter.invoke%22, e);%0A%09%09%7D%0A%09%7D%0A%0A%0A%09public Class getReturnType()%0A%09%7B%0A%09%09if (field != null)%0A%09%09%09return field.getType();%0A%09%09else if (setter != null)%0A%09%09%09return getter.getReturnType();%0A%09%09else%0A%09%09%09throw new IllegalArgumentException(%22No Field or Getter stored!%22);%0A%09%7D%0A%7D%0A

Add helper class that calls a getter/setter on a java field