1 28 package net.sf.jasperreports.engine.base; 29 30 import java.io.IOException ; 31 32 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 33 import net.sf.jasperreports.engine.JRChild; 34 import net.sf.jasperreports.engine.JRConstants; 35 import net.sf.jasperreports.engine.JRExpression; 36 import net.sf.jasperreports.engine.JRExpressionCollector; 37 import net.sf.jasperreports.engine.JRSubreport; 38 import net.sf.jasperreports.engine.JRSubreportParameter; 39 import net.sf.jasperreports.engine.JRSubreportReturnValue; 40 import net.sf.jasperreports.engine.util.JRStyleResolver; 41 import net.sf.jasperreports.engine.xml.JRXmlWriter; 42 43 44 48 public class JRBaseSubreport extends JRBaseElement implements JRSubreport 49 { 50 51 52 55 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 56 57 60 protected Boolean isUsingCache = null; 61 62 65 protected JRExpression parametersMapExpression = null; 66 protected JRSubreportParameter[] parameters = null; 67 protected JRExpression connectionExpression = null; 68 protected JRExpression dataSourceExpression = null; 69 protected JRExpression expression = null; 70 71 74 protected JRSubreportReturnValue[] returnValues = null; 75 76 77 80 public byte getMode() 81 { 82 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 83 } 84 85 86 89 protected JRBaseSubreport(JRSubreport subreport, JRBaseObjectFactory factory) 90 { 91 super(subreport, factory); 92 93 isUsingCache = subreport.isOwnUsingCache(); 94 95 parametersMapExpression = factory.getExpression(subreport.getParametersMapExpression()); 96 97 98 JRSubreportParameter[] jrSubreportParameters = subreport.getParameters(); 99 if (jrSubreportParameters != null && jrSubreportParameters.length > 0) 100 { 101 parameters = new JRSubreportParameter[jrSubreportParameters.length]; 102 for(int i = 0; i < parameters.length; i++) 103 { 104 parameters[i] = factory.getSubreportParameter(jrSubreportParameters[i]); 105 } 106 } 107 108 connectionExpression = factory.getExpression(subreport.getConnectionExpression()); 109 dataSourceExpression = factory.getExpression(subreport.getDataSourceExpression()); 110 111 JRSubreportReturnValue[] subrepReturnValues = subreport.getReturnValues(); 112 if (subrepReturnValues != null && subrepReturnValues.length > 0) 113 { 114 this.returnValues = new JRSubreportReturnValue[subrepReturnValues.length]; 115 for (int i = 0; i < subrepReturnValues.length; i++) 116 { 117 this.returnValues[i] = factory.getSubreportReturnValue(subrepReturnValues[i]); 118 } 119 } 120 121 expression = factory.getExpression(subreport.getExpression()); 122 } 123 124 125 128 public boolean isUsingCache() 129 { 130 if (isUsingCache == null) 131 { 132 JRExpression subreportExpression = getExpression(); 133 if (subreportExpression != null) 134 { 135 return String .class.getName().equals(subreportExpression.getValueClassName()); 136 } 137 return true; 138 } 139 return isUsingCache.booleanValue(); 140 } 141 142 143 146 public void setUsingCache(boolean isUsingCache) 147 { 148 setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE); 149 } 150 151 152 155 public JRExpression getParametersMapExpression() 156 { 157 return this.parametersMapExpression; 158 } 159 160 161 164 public JRSubreportParameter[] getParameters() 165 { 166 return this.parameters; 167 } 168 169 170 173 public JRExpression getConnectionExpression() 174 { 175 return this.connectionExpression; 176 } 177 178 179 182 public JRExpression getDataSourceExpression() 183 { 184 return this.dataSourceExpression; 185 } 186 187 188 191 public JRExpression getExpression() 192 { 193 return this.expression; 194 } 195 196 199 public JRChild getCopy(JRAbstractObjectFactory factory) 200 { 201 return factory.getSubreport(this); 202 } 203 204 207 public void collectExpressions(JRExpressionCollector collector) 208 { 209 collector.collect(this); 210 } 211 212 215 public void writeXml(JRXmlWriter xmlWriter) throws IOException 216 { 217 xmlWriter.writeSubreport(this); 218 } 219 220 221 226 public JRSubreportReturnValue[] getReturnValues() 227 { 228 return this.returnValues; 229 } 230 231 232 public Boolean isOwnUsingCache() 233 { 234 return isUsingCache; 235 } 236 237 238 public void setUsingCache(Boolean isUsingCache) 239 { 240 this.isUsingCache = isUsingCache; 241 } 242 243 244 } 245 | Popular Tags |