1 32 33 package it.businesslogic.ireport.connection; 34 import it.businesslogic.ireport.*; 35 import it.businesslogic.ireport.util.*; 36 import java.sql.*; 37 import javax.swing.*; 38 import net.sf.jasperreports.engine.data.JRAbstractBeanDataSource; 39 43 public class JavaBeanDataSourceConnection extends it.businesslogic.ireport.IReportConnection { 44 45 public static String BEAN_ARRAY = "BEAN_ARRAY"; 46 public static String BEAN_COLLECTION = "BEAN_COLLECTION"; 47 48 private String name; 49 50 private String factoryClass; 51 52 private String methodToCall; 53 54 private boolean useFieldDescription; 55 56 private String type = "BEAN_COLLECTION"; 57 58 59 60 61 public JavaBeanDataSourceConnection() { 62 } 63 64 68 public java.sql.Connection getConnection() { 69 return null; 70 } 71 72 public boolean isJDBCConnection() { 73 return false; 74 } 75 76 79 public java.util.HashMap getProperties() 80 { 81 java.util.HashMap map = new java.util.HashMap (); 82 map.put("FactoryClass", Misc.nvl(this.getFactoryClass() ,"") ); 83 map.put("MethodToCall", Misc.nvl(this.getMethodToCall(),"")); 84 map.put("Type", Misc.nvl(this.getType(),"")); 85 map.put("UseFieldDescription", ""+this.isUseFieldDescription()); 86 87 return map; 88 } 89 90 public void loadProperties(java.util.HashMap map) 91 { 92 this.setFactoryClass( (String )map.get("FactoryClass")); 93 this.setMethodToCall( (String )map.get("MethodToCall")); 94 if (map.containsKey("UseFieldDescription")) 95 { 96 this.setUseFieldDescription( ((String )map.get("UseFieldDescription")).equals("true") ); 97 } 98 if (map.containsKey("Type")) 99 { 100 this.setType( (String )map.get("Type")); 101 } 102 } 103 104 public String getDescription(){ return "JavaBean set datasource"; } 105 106 110 public java.lang.String getMethodToCall() { 111 return methodToCall; 112 } 113 114 118 public void setMethodToCall(java.lang.String methodToCall) { 119 this.methodToCall = methodToCall; 120 } 121 122 126 public java.lang.String getFactoryClass() { 127 return factoryClass; 128 } 129 130 134 public void setFactoryClass(java.lang.String factoryClass) { 135 this.factoryClass = factoryClass; 136 } 137 138 142 public java.lang.String getType() { 143 return type; 144 } 145 146 150 public void setType(java.lang.String type) { 151 this.type = type; 152 } 153 154 158 public net.sf.jasperreports.engine.JRDataSource getJRDataSource() 159 { 160 try { 161 162 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryClass); 163 Object obj = clazz.newInstance(); 164 Object return_obj = obj.getClass().getMethod( methodToCall, new Class [0]).invoke(null,new Object [0]); 165 166 if (return_obj != null) 167 { 168 if (Misc.nvl(this.getType(),"").equals(BEAN_ARRAY) ) 169 { 170 return new net.sf.jasperreports.engine.data.JRBeanArrayDataSource((Object []) return_obj, isUseFieldDescription()); 171 } 172 else if (Misc.nvl(this.getType(),"").equals(BEAN_COLLECTION) ) 173 { 174 return new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource((java.util.Collection ) return_obj, isUseFieldDescription()); 175 } 176 } 177 return new net.sf.jasperreports.engine.JREmptyDataSource(); 178 179 } catch (Exception ex) 180 { 181 ex.printStackTrace(); 182 return super.getJRDataSource(); 183 } 184 } 185 186 public boolean isUseFieldDescription() { 187 return useFieldDescription; 188 } 189 190 public void setUseFieldDescription(boolean useFieldDescription) { 191 this.useFieldDescription = useFieldDescription; 192 } 193 } 194 | Popular Tags |