java 代码
- // Convert this list into the internal data structures we need
- properties =
- (DynaProperty[]) list.toArray(new DynaProperty[list.size()]);
- for (int i = 0; i < properties.length; i++) {
- propertiesMap.put(properties[i].getName(), properties[i]);
- }
- }
- /**
- * <p>Factory method to create a new DynaProperty for the given index
- * into the result set metadata.</p>
- *
- * @param metadata is the result set metadata
- * @param i is the column index in the metadata
- * @return the newly created DynaProperty instance
- */
- protected DynaProperty createDynaProperty(
- ResultSetMetaData metadata,
- int i)
- throws SQLException {
- String name = null;
- if (lowerCase) {
- name = metadata.getColumnName(i).toLowerCase();
- } else {
- name = metadata.getColumnName(i);
- }
- String className = null;
- try {
- className = metadata.getColumnClassName(i);
- } catch (SQLException e) {
- // this is a patch for HsqlDb to ignore exceptions
- // thrown by its metadata implementation
- }
- // Default to Object type if no class name could be retrieved
- // from the metadata
- Class clazz = Object.class;
- if (className != null) {
- clazz = loadClass(className);
- }
- return new DynaProperty(name, clazz);
- }
- /**
- * <p>Loads and returns the <code>Class</code> of the given name.
- * By default, a load from the thread context class loader is attempted.
- * If there is no such class loader, the class loader used to load this
- * class will be utilized.</p>
- *
- * @exception SQLException if an exception was thrown trying to load
- * the specified class
- */
- protected Class loadClass(String className) throws SQLException {
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- cl = this.getClass().getClassLoader();
- }
- return (cl.loadClass(className));
- } catch (Exception e) {
- throw new SQLException(
- "Cannot load column class '" + className + "': " + e);
- }
- }
- }
- 大部分代码从BeanUtils的源码中取得,只做了简单的修改,没有加多余的注释。如果要正式使用,
- 需要再做精加工。