Here a simple JRDataSource  template:

/*
* Created on 12.05.2006
*/
package org.jsaar.report;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.jxpath.JXPathContext;
import org.objectstyle.cayenne.DataObject;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class JsDataSource extends Object implements JRDataSource {
 private List data = null;
 private Iterator iterator = null;
 private DataObject dataObject = null;

 /**
  * Constructor with List usually from SelectQuery
  *
  * @param businessObjects
  */
 public JsDataSource(List businessObjects) {
   super();
   setData(businessObjects);
 }

 /**
  * setter for List
  *
  * @param list
  */
 public void setData(List list) {
   data = list;
   iterator = data.iterator();
 }

 /* (non-Javadoc)
  * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(
net.sf.jasperreports.engine.JRField)
  */
 public Object getFieldValue(JRField field) throws JRException {
   String name = field.getName();
   JXPathContext context = JXPathContext.newContext(dataObject);
   Object obj = context.getValue(name);
   return (obj == null) ? null : obj.toString();
 }

 /* (non-Javadoc)
  * @see net.sf.jasperreports.engine.JRDataSource#next()
  */
 public boolean next() throws JRException {
   boolean result = iterator.hasNext();
   if (result) {
     dataObject = (DataObject) iterator.next();
   }
   return result;
 }

}


2006/5/12, Alan Baltazar <[EMAIL PROTECTED]>:


DataRows seem to be the only solution i could think of to wrap the
JRDataSource
implementation, which is required by jasperreports to read the datasource
data.
JRDataSource is a wrapper hashmap for reading the rows from a datasource.
i don't know
much about dataobjects to implement this .... if you do, please let me
know how.

--- Juergen Saar <[EMAIL PROTECTED]> wrote:

> Why do you work on DataRows ... DataObjects are much more like
> BusinessObjects.
>
> If you work on DataObjects and there are some getters for
> transient informations coming from business-logic
> it can help a lot.
>
> Just one more hint:
> reading content of DataObjects with jxpath is really cool.
>

Reply via email to