001: /*
002: * $Id: JREntityListIteratorDataSource.java,v 1.2 2003/09/14 05:36:47 jonesde Exp $
003: *
004: * Copyright (c) 2002-2003 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024:
025: package org.ofbiz.content.report;
026:
027: import org.ofbiz.base.util.Debug;
028: import org.ofbiz.entity.GenericEntity;
029: import org.ofbiz.entity.GenericEntityException;
030: import org.ofbiz.entity.util.EntityListIterator;
031:
032: import dori.jasper.engine.JRDataSource;
033: import dori.jasper.engine.JRException;
034: import dori.jasper.engine.JRField;
035:
036: /**
037: * <code>JREntityListIteratorDataSource</code>
038: *
039: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
040: * @author <a href="mailto:gielen@aixcept.de">Rene Gielen</a>
041: * @version $Revision: 1.2 $
042: */
043: public class JREntityListIteratorDataSource implements JRDataSource {
044:
045: public static final String module = JREntityListIteratorDataSource.class
046: .getName();
047:
048: private EntityListIterator entityListIterator = null;
049: private GenericEntity currentEntity = null;
050:
051: public JREntityListIteratorDataSource(
052: EntityListIterator entityListIterator) {
053: this .entityListIterator = entityListIterator;
054: }
055:
056: public boolean next() throws JRException {
057: if (this .entityListIterator == null) {
058: return false;
059: }
060: Object nextObj = this .entityListIterator.next();
061: if (nextObj != null) {
062: if (nextObj instanceof GenericEntity) {
063: this .currentEntity = (GenericEntity) nextObj;
064: } else {
065: throw new JRException(
066: "Current collection object does not seem to be a GenericEntity (or GenericValue or GenericPK).");
067: }
068: return true;
069: } else {
070: // nothing left, close here...
071: try {
072: this .entityListIterator.close();
073: } catch (GenericEntityException e) {
074: Debug
075: .logError(
076: e,
077: "Error closing EntityListIterator in Jasper Reports DataSource",
078: module);
079: throw new JRException(e);
080: }
081: this .entityListIterator = null;
082: return false;
083: }
084: }
085:
086: public Object getFieldValue(JRField jrField) throws JRException {
087: Object value = null;
088: if (this .currentEntity != null) {
089: try {
090: value = this .currentEntity.get(jrField.getName());
091: } catch (IllegalArgumentException e) {
092: throw new JRException(
093: "The specified field name ["
094: + jrField.getName()
095: + "] is not a valid field-name for the entity: "
096: + this.currentEntity.getEntityName(), e);
097: }
098: }
099: return value;
100: }
101: }
|