1 16 package com.ibatis.sqlmap.engine.accessplan; 17 18 import java.util.Map ; 19 20 23 public class AccessPlanFactory { 24 25 private static boolean bytecodeEnhancementEnabled = false; 26 27 private AccessPlanFactory() { 28 } 29 30 37 public static AccessPlan getAccessPlan(Class clazz, String [] propertyNames) { 38 AccessPlan plan; 39 40 boolean complex = false; 41 42 if (clazz == null || propertyNames == null) { 43 complex = true; 44 } else { 45 for (int i = 0; i < propertyNames.length; i++) { 46 if (propertyNames[i].indexOf('[') > -1 47 || propertyNames[i].indexOf('.') > -1) { 48 complex = true; 49 break; 50 } 51 } 52 } 53 54 if (complex) { 55 plan = new ComplexAccessPlan(clazz, propertyNames); 56 } else if (Map .class.isAssignableFrom(clazz)) { 57 plan = new MapAccessPlan(clazz, propertyNames); 58 } else { 59 if (bytecodeEnhancementEnabled) { 61 try { 62 plan = new EnhancedPropertyAccessPlan(clazz, propertyNames); 63 } catch (Throwable t) { 64 try { 65 plan = new PropertyAccessPlan(clazz, propertyNames); 66 } catch (Throwable t2) { 67 plan = new ComplexAccessPlan(clazz, propertyNames); 68 } 69 } 70 } else { 71 try { 72 plan = new PropertyAccessPlan(clazz, propertyNames); 73 } catch (Throwable t) { 74 plan = new ComplexAccessPlan(clazz, propertyNames); 75 } 76 } 77 } 78 return plan; 79 } 80 81 86 public static boolean isBytecodeEnhancementEnabled() { 87 return bytecodeEnhancementEnabled; 88 } 89 90 95 public static void setBytecodeEnhancementEnabled(boolean bytecodeEnhancementEnabled) { 96 AccessPlanFactory.bytecodeEnhancementEnabled = bytecodeEnhancementEnabled; 97 } 98 99 } 100 | Popular Tags |