BrightSide Workbench Full Report + Source Code
OnDemandBeanCollection.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zkoss.print;
19 
20 import java.util.Collection;
21 import net.sf.jasperreports.engine.JRException;
22 import net.sf.jasperreports.engine.JRField;
23 import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
24 import org.zkoss.lang.Objects;
25 
30 public abstract class OnDemandBeanCollection extends JRBeanCollectionDataSource {
31 
32  private Object realBean, previousBean;
33 
34  public OnDemandBeanCollection(Collection beanCollection, boolean isUseFieldDescription) {
35  super(beanCollection, isUseFieldDescription);
36  }
37 
38  public OnDemandBeanCollection(Collection beanCollection) {
39  super(beanCollection);
40  }
41 
42  @Override
43  protected Object getFieldValue(Object bean, JRField field) throws JRException {
44  if(!Objects.equals(bean, previousBean)) {
45  previousBean = bean;
46  realBean = getRealBean(bean);
47  }
48  return super.getFieldValue(realBean, field);
49  }
50 
51  protected abstract Object getRealBean(Object bean);
52 
53 }
OnDemandBeanCollection(Collection beanCollection, boolean isUseFieldDescription)
abstract Object getRealBean(Object bean)
Object getFieldValue(Object bean, JRField field)