From: <one...@us...> - 2003-03-29 07:36:28
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/util In directory sc8-pr-cvs1:/tmp/cvs-serv3374/hibernate/util Modified Files: ReflectHelper.java Log Message: re-reworked import functionality Index: ReflectHelper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/util/ReflectHelper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ReflectHelper.java 26 Feb 2003 13:27:25 -0000 1.8 --- ReflectHelper.java 29 Mar 2003 07:36:23 -0000 1.9 *************** *** 9,12 **** --- 9,16 ---- import java.lang.reflect.Modifier; + import org.apache.commons.logging.Log; + import org.apache.commons.logging.LogFactory; + + import net.sf.cglib.MetaClass; import net.sf.hibernate.AssertionFailure; import net.sf.hibernate.HibernateException; *************** *** 20,23 **** --- 24,29 ---- public final class ReflectHelper { + private static final Log log = LogFactory.getLog(ReflectHelper.class); + private static final Class[] NO_CLASSES = new Class[0]; private static final Class[] OBJECT = new Class[] { Object.class }; *************** *** 55,58 **** --- 61,66 ---- } catch (IllegalArgumentException iae) { + log.error("IllegalArgumentException in class: " + clazz.getName() + ", setter method: " + method + ", propertyName: " + propertyName); + log.error("target: " + target + " value: " + value); throw new PropertyAccessException(iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName); } *************** *** 88,91 **** --- 96,101 ---- } catch (IllegalArgumentException iae) { + log.error("IllegalArgumentException in class: " + clazz.getName() + ", getter method: " + method + ", propertyName: " + propertyName); + log.error("target: " + target); throw new PropertyAccessException(iae, "IllegalArgumentException occurred calling", false, clazz, propertyName); } *************** *** 290,293 **** --- 300,324 ---- int modifier = clazz.getModifiers(); return (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)); + } + + public static MetaClass getMetaClass(Class clazz, String[] getterNames, String[] setterNames, Class[] types) { + try { + MetaClass optimizer = MetaClass.getInstance( clazz.getClassLoader(), clazz, getterNames, setterNames, types ); + //test out the optimizer: + optimizer.setPropertyValues( optimizer.newInstance(), optimizer.getPropertyValues( optimizer.newInstance() ) ); + //if working: + return optimizer; + } + catch (Throwable t) { + log.info( + "reflection optimizer disabled for: " + + clazz.getName() + + ", " + + StringHelper.unqualify( t.getClass().getName() ) + + ": " + + t.getMessage() + ); + return null; + } } |