`
sunxboy
  • 浏览: 2840336 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Jakarta-Common-BeanUtils研究心得(二)

阅读更多
java 代码
 
  1. // Convert this list into the internal data structures we need  
  2. properties =  
  3. (DynaProperty[]) list.toArray(new DynaProperty[list.size()]);  
  4. for (int i = 0; i < properties.length; i++) {  
  5. propertiesMap.put(properties[i].getName(), properties[i]);  
  6. }  
  7.   
  8. }  
  9.   
  10. /** 
  11. * <p>Factory method to create a new DynaProperty for the given index 
  12. * into the result set metadata.</p> 
  13. * 
  14. * @param metadata is the result set metadata 
  15. * @param i is the column index in the metadata 
  16. * @return the newly created DynaProperty instance 
  17. */  
  18. protected DynaProperty createDynaProperty(  
  19. ResultSetMetaData metadata,  
  20. int i)  
  21. throws SQLException {  
  22.   
  23. String name = null;  
  24. if (lowerCase) {  
  25. name = metadata.getColumnName(i).toLowerCase();  
  26. else {  
  27. name = metadata.getColumnName(i);  
  28. }  
  29. String className = null;  
  30. try {  
  31. className = metadata.getColumnClassName(i);  
  32. catch (SQLException e) {  
  33. // this is a patch for HsqlDb to ignore exceptions  
  34. // thrown by its metadata implementation  
  35. }  
  36.   
  37. // Default to Object type if no class name could be retrieved  
  38. // from the metadata  
  39. Class clazz = Object.class;  
  40. if (className != null) {  
  41. clazz = loadClass(className);  
  42. }  
  43. return new DynaProperty(name, clazz);  
  44.   
  45. }  
  46.   
  47. /** 
  48. * <p>Loads and returns the <code>Class</code> of the given name. 
  49. * By default, a load from the thread context class loader is attempted. 
  50. * If there is no such class loader, the class loader used to load this 
  51. * class will be utilized.</p> 
  52. * 
  53. * @exception SQLException if an exception was thrown trying to load 
  54. *  the specified class 
  55. */  
  56. protected Class loadClass(String className) throws SQLException {  
  57.   
  58. try {  
  59. ClassLoader cl = Thread.currentThread().getContextClassLoader();  
  60. if (cl == null) {  
  61. cl = this.getClass().getClassLoader();  
  62. }  
  63. return (cl.loadClass(className));  
  64. catch (Exception e) {  
  65. throw new SQLException(  
  66. "Cannot load column class '" + className + "': " + e);  
  67. }  
  68.   
  69. }  
  70.   
  71. }  
  72.   
  73. 大部分代码从BeanUtils的源码中取得,只做了简单的修改,没有加多余的注释。如果要正式使用,  
  74. 需要再做精加工。  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics