1 28 package net.sf.jasperreports.engine.design; 29 30 import java.io.IOException ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.List ; 34 import java.util.Map ; 35 36 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 37 import net.sf.jasperreports.engine.JRChild; 38 import net.sf.jasperreports.engine.JRConstants; 39 import net.sf.jasperreports.engine.JRDefaultStyleProvider; 40 import net.sf.jasperreports.engine.JRException; 41 import net.sf.jasperreports.engine.JRExpression; 42 import net.sf.jasperreports.engine.JRExpressionCollector; 43 import net.sf.jasperreports.engine.JRSubreport; 44 import net.sf.jasperreports.engine.JRSubreportParameter; 45 import net.sf.jasperreports.engine.JRSubreportReturnValue; 46 import net.sf.jasperreports.engine.util.JRStyleResolver; 47 import net.sf.jasperreports.engine.xml.JRXmlWriter; 48 49 50 54 public class JRDesignSubreport extends JRDesignElement implements JRSubreport 55 { 56 57 58 61 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 62 63 66 protected Boolean isUsingCache = null; 67 68 71 protected Map parametersMap = new HashMap (); 72 73 76 protected List returnValues = new ArrayList (); 77 78 81 protected JRExpression parametersMapExpression = null; 82 protected JRExpression connectionExpression = null; 83 protected JRExpression dataSourceExpression = null; 84 protected JRExpression expression = null; 85 86 87 90 public JRDesignSubreport(JRDefaultStyleProvider defaultStyleProvider) 91 { 92 super(defaultStyleProvider); 93 } 94 95 96 99 public byte getMode() 100 { 101 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 102 } 103 104 105 108 public boolean isUsingCache() 109 { 110 if (isUsingCache == null) 111 { 112 JRExpression subreportExpression = getExpression(); 113 if (subreportExpression != null) 114 { 115 return String .class.getName().equals(subreportExpression.getValueClassName()); 116 } 117 return true; 118 } 119 return isUsingCache.booleanValue(); 120 } 121 122 125 public void setUsingCache(boolean isUsingCache) 126 { 127 setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE); 128 } 129 130 133 public JRExpression getParametersMapExpression() 134 { 135 return this.parametersMapExpression; 136 } 137 138 141 public void setParametersMapExpression(JRExpression parametersMapExpression) 142 { 143 this.parametersMapExpression = parametersMapExpression; 144 } 145 146 149 public JRSubreportParameter[] getParameters() 150 { 151 JRSubreportParameter[] parametersArray = new JRSubreportParameter[parametersMap.size()]; 152 153 parametersMap.values().toArray(parametersArray); 154 155 return parametersArray; 156 } 157 158 161 public Map getParametersMap() 162 { 163 return this.parametersMap; 164 } 165 166 169 public void addParameter(JRSubreportParameter subreportParameter) throws JRException 170 { 171 if (this.parametersMap.containsKey(subreportParameter.getName())) 172 { 173 throw new JRException("Duplicate declaration of subreport parameter : " + subreportParameter.getName()); 174 } 175 176 this.parametersMap.put(subreportParameter.getName(), subreportParameter); 177 } 178 179 182 public JRSubreportParameter removeParameter(String name) 183 { 184 return (JRSubreportParameter)this.parametersMap.remove(name); 185 } 186 187 190 public JRExpression getConnectionExpression() 191 { 192 return this.connectionExpression; 193 } 194 195 198 public void setConnectionExpression(JRExpression connectionExpression) 199 { 200 this.connectionExpression = connectionExpression; 201 this.dataSourceExpression = null; 202 } 203 204 207 public JRExpression getDataSourceExpression() 208 { 209 return this.dataSourceExpression; 210 } 211 212 215 public void setDataSourceExpression(JRExpression dataSourceExpression) 216 { 217 this.dataSourceExpression = dataSourceExpression; 218 } 219 220 223 public JRExpression getExpression() 224 { 225 return this.expression; 226 } 227 228 231 public void setExpression(JRExpression expression) 232 { 233 this.expression = expression; 234 } 235 236 239 public JRChild getCopy(JRAbstractObjectFactory factory) 240 { 241 return factory.getSubreport(this); 242 } 243 244 247 public void collectExpressions(JRExpressionCollector collector) 248 { 249 collector.collect(this); 250 } 251 252 255 public void writeXml(JRXmlWriter xmlWriter) throws IOException 256 { 257 xmlWriter.writeSubreport(this); 258 } 259 260 261 266 public void addReturnValue(JRSubreportReturnValue returnValue) 267 { 268 this.returnValues.add(returnValue); 269 } 270 271 272 277 public JRSubreportReturnValue[] getReturnValues() 278 { 279 JRSubreportReturnValue[] returnValuesArray = new JRSubreportReturnValue[returnValues.size()]; 280 281 returnValues.toArray(returnValuesArray); 282 283 return returnValuesArray; 284 } 285 286 287 292 public List getReturnValuesList() 293 { 294 return returnValues; 295 } 296 297 298 304 public boolean removeReturnValue(JRSubreportReturnValue returnValue) 305 { 306 return this.returnValues.remove(returnValue); 307 } 308 309 310 public Boolean isOwnUsingCache() 311 { 312 return isUsingCache; 313 } 314 315 316 public void setUsingCache(Boolean isUsingCache) 317 { 318 this.isUsingCache = isUsingCache; 319 } 320 } 321 | Popular Tags |