|
From: <one...@us...> - 2003-01-12 07:07:52
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/util
In directory sc8-pr-cvs1:/tmp/cvs-serv5675/src/net/sf/hibernate/util
Modified Files:
ReflectHelper.java
Log Message:
added isFirst(), isLast() to ScrollableResults
fixed problem finding properties inherited by interfaces and abstract classes
support for elements(), indices(), max(), min(), count() functions
Index: ReflectHelper.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/util/ReflectHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ReflectHelper.java 5 Jan 2003 02:11:25 -0000 1.3
--- ReflectHelper.java 12 Jan 2003 07:07:49 -0000 1.4
***************
*** 115,166 ****
return !OBJECT_EQUALS.equals(equals);
}
-
-
- public static Method getMethod(Class theClass, String methodName) throws PropertyNotFoundException {
-
- if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed
-
- Method result;
- try {
- result = theClass.getDeclaredMethod(methodName, null);
- }
- catch (Exception e) {
- try {
- return getMethod( theClass.getSuperclass(), methodName );
- }
- catch (PropertyNotFoundException me) {
- throw new PropertyNotFoundException( "Could not find method " + methodName + " in class " + theClass.getName() );
- }
- }
! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true);
return result;
-
}
! public static Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException {
! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed
! Method result = setter(theClass, propertyName);
! if(result==null) {
! try {
! return getSetter( theClass.getSuperclass(), propertyName );
! }
! catch (PropertyNotFoundException me) {
! throw new PropertyNotFoundException( "Could not find a setter for " + propertyName + " in class " + theClass.getName() );
! }
}
else {
! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true);
! return new Setter(theClass, result, propertyName);
}
}
! private static Method setter(Class theClass, String propertyName) throws PropertyNotFoundException {
! Class returnType = getGetter(theClass, propertyName).getReturnType();
Method[] methods = theClass.getDeclaredMethods();
--- 115,151 ----
return !OBJECT_EQUALS.equals(equals);
}
! public static Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException {
! Setter result = getSetterOrNull(theClass, propertyName);
! if (result==null) throw new PropertyNotFoundException( "Could not find a setter for property " + propertyName + " in class " + theClass.getName() );
return result;
}
! private static Setter getSetterOrNull(Class theClass, String propertyName) {
! if (theClass==Object.class || theClass==null) return null;
! Method method = setterMethod(theClass, propertyName);
! if(method!=null) {
! if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
! return new Setter(theClass, method, propertyName);
}
else {
! Setter setter = getSetterOrNull( theClass.getSuperclass(), propertyName );
! if (setter==null) {
! Class[] interfaces = theClass.getInterfaces();
! for ( int i=0; setter==null && i<interfaces.length; i++ ) {
! setter=getSetterOrNull( interfaces[i], propertyName );
! }
! }
! return setter;
}
}
! private static Method setterMethod(Class theClass, String propertyName) {
! Class returnType = getGetterOrNull(theClass, propertyName).getReturnType();
Method[] methods = theClass.getDeclaredMethods();
***************
*** 178,182 ****
) {
potentialSetter = methods[i];
! if ( methods[i].getParameterTypes()[0].equals(returnType) ) return potentialSetter;
}
}
--- 163,167 ----
) {
potentialSetter = methods[i];
! if ( returnType==null || methods[i].getParameterTypes()[0].equals(returnType) ) return potentialSetter;
}
}
***************
*** 186,209 ****
public static Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a getter" ); // will be swallowed
! Method result = getter(theClass, propertyName);
! if(result==null) {
! try {
! return getGetter( theClass.getSuperclass(), propertyName );
! }
! catch (PropertyNotFoundException me) {
! throw new PropertyNotFoundException( "Could not find a getter for " + propertyName + " in class " + theClass.getName() );
! }
}
else {
! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true);
! return new Getter(theClass, result, propertyName);
}
}
! private static Method getter(Class theClass, String propertyName) {
Method[] methods = theClass.getDeclaredMethods();
--- 171,203 ----
public static Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
+ Getter result = getGetterOrNull(theClass, propertyName);
+ if (result==null) throw new PropertyNotFoundException( "Could not find a getter for " + propertyName + " in class " + theClass.getName() );
+ return result;
! }
!
! private static Getter getGetterOrNull(Class theClass, String propertyName) {
! if (theClass==Object.class || theClass==null) return null;
! Method method = getterMethod(theClass, propertyName);
!
! if(method!=null) {
! if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
! return new Getter(theClass, method, propertyName);
}
else {
! Getter getter = getGetterOrNull( theClass.getSuperclass(), propertyName );
! if (getter==null) {
! Class[] interfaces = theClass.getInterfaces();
! for ( int i=0; getter==null && i<interfaces.length; i++ ) {
! getter=getGetterOrNull( interfaces[i], propertyName );
! }
! }
! return getter;
}
}
! private static Method getterMethod(Class theClass, String propertyName) {
Method[] methods = theClass.getDeclaredMethods();
|