001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * EventMonitorFunction.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.function;
030:
031: import org.jfree.report.event.PageEventListener;
032: import org.jfree.report.event.ReportEvent;
033: import org.jfree.util.Log;
034:
035: /**
036: * A function that logs each event that it receives. This function can be used for debugging purposes.
037: *
038: * @author Thomas Morgner
039: */
040: public class EventMonitorFunction extends AbstractFunction implements
041: PageEventListener {
042: /**
043: * Counts the number of times the reportStarted(...) method is called.
044: */
045: private transient int reportStartCount = 0;
046: /**
047: * A flag indicating whether this expression will receive events from subreports.
048: */
049: private boolean deepTraversing;
050:
051: /**
052: * Creates a new function.
053: */
054: public EventMonitorFunction() {
055: }
056:
057: /**
058: * Creates a new function.
059: *
060: * @param name the name of the function
061: */
062: public EventMonitorFunction(final String name) {
063: setName(name);
064: }
065:
066: /**
067: * Receives notification that the report has started.
068: *
069: * @param event the event.
070: */
071: public void reportStarted(final ReportEvent event) {
072: Log
073: .info("Report Started: Level = "
074: + event.getState().getLevel()
075: + " ItemCount: "
076: + event.getState().getCurrentDataItem()
077: + " Prepare Run: "
078: + event.getState().isPrepareRun()
079: + " Deep-Event "
080: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
081: reportStartCount++;
082: Log.info("Report Started Count: " + reportStartCount);
083: }
084:
085: /**
086: * Receives notification that the report has finished.
087: *
088: * @param event the event.
089: */
090: public void reportFinished(final ReportEvent event) {
091: Log
092: .info("Report Finished: Level = "
093: + event.getState().getLevel()
094: + " ItemCount: "
095: + event.getState().getCurrentDataItem()
096: + " Prepare Run: "
097: + event.getState().isPrepareRun()
098: + " Deep-Event "
099: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
100: }
101:
102: /**
103: * Receives notification that report generation has completed, the report footer was printed, no more output is done.
104: * This is a helper event to shut down the output service.
105: *
106: * @param event The event.
107: */
108: public void reportDone(final ReportEvent event) {
109: Log
110: .info("Report Done: Level = "
111: + event.getState().getLevel()
112: + " ItemCount: "
113: + event.getState().getCurrentDataItem()
114: + " Prepare Run: "
115: + event.getState().isPrepareRun()
116: + " Deep-Event "
117: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
118:
119: }
120:
121: /**
122: * Receives notification that a page has started.
123: *
124: * @param event the event.
125: */
126: public void pageStarted(final ReportEvent event) {
127: Log
128: .info("Page Started: Level = "
129: + event.getState().getLevel()
130: + " ItemCount: "
131: + event.getState().getCurrentDataItem()
132: + " Prepare Run: "
133: + event.getState().isPrepareRun()
134: + " Deep-Event "
135: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
136: Log.info("Page Started: " + event.getState().getCurrentPage());
137: }
138:
139: /**
140: * Receives notification that a page has ended.
141: *
142: * @param event the event.
143: */
144: public void pageFinished(final ReportEvent event) {
145: Log
146: .info("Page Finished: Level = "
147: + event.getState().getLevel()
148: + " ItemCount: "
149: + event.getState().getCurrentDataItem()
150: + " Prepare Run: "
151: + event.getState().isPrepareRun()
152: + " Deep-Event "
153: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
154: Log.info("Page Finished: " + event.getState().getCurrentPage());
155: }
156:
157: /**
158: * Receives notification that a group has started.
159: *
160: * @param event the event.
161: */
162: public void groupStarted(final ReportEvent event) {
163: Log
164: .info("Group Started: Level = "
165: + event.getState().getLevel()
166: + " ItemCount: "
167: + event.getState().getCurrentDataItem()
168: + " Prepare Run: "
169: + event.getState().isPrepareRun()
170: + " Deep-Event "
171: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
172: Log.info("Group Started: "
173: + event.getState().getCurrentGroupIndex());
174: }
175:
176: /**
177: * Receives notification that a group has finished.
178: *
179: * @param event the event.
180: */
181: public void groupFinished(final ReportEvent event) {
182: Log
183: .info("Group Finished: Level = "
184: + event.getState().getLevel()
185: + " ItemCount: "
186: + event.getState().getCurrentDataItem()
187: + " Prepare Run: "
188: + event.getState().isPrepareRun()
189: + " Deep-Event "
190: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
191: Log.info("Group Finished: "
192: + event.getState().getCurrentGroupIndex());
193: }
194:
195: /**
196: * Receives notification that a row of data is being processed.
197: *
198: * @param event the event.
199: */
200: public void itemsAdvanced(final ReportEvent event) {
201: Log
202: .info("Items Advanced: Level = "
203: + event.getState().getLevel()
204: + " ItemCount: "
205: + event.getState().getCurrentDataItem()
206: + " Prepare Run: "
207: + event.getState().isPrepareRun()
208: + " Deep-Event "
209: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
210: }
211:
212: /**
213: * Receives notification that a group of item bands is about to be processed.
214: *
215: * @param event the event.
216: */
217: public void itemsStarted(final ReportEvent event) {
218: Log
219: .info("Items Started: Level = "
220: + event.getState().getLevel()
221: + " ItemCount: "
222: + event.getState().getCurrentDataItem()
223: + " Prepare Run: "
224: + event.getState().isPrepareRun()
225: + " Deep-Event "
226: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
227: }
228:
229: /**
230: * Receives notification that a group of item bands has been completed.
231: *
232: * @param event the event.
233: */
234: public void itemsFinished(final ReportEvent event) {
235: Log
236: .info("Items Finished: Level = "
237: + event.getState().getLevel()
238: + " ItemCount: "
239: + event.getState().getCurrentDataItem()
240: + " Prepare Run: "
241: + event.getState().isPrepareRun()
242: + " Deep-Event "
243: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
244: }
245:
246: /**
247: * Receives notification that report generation initializes the current run. <P> The event carries a
248: * ReportState.Started state. Use this to initialize the report.
249: *
250: * @param event The event.
251: */
252: public void reportInitialized(final ReportEvent event) {
253: Log
254: .info("Report Initialized: Level = "
255: + event.getState().getLevel()
256: + " ItemCount: "
257: + event.getState().getCurrentDataItem()
258: + " Prepare Run: "
259: + event.getState().isPrepareRun()
260: + " Deep-Event "
261: + ((event.getType() & ReportEvent.DEEP_TRAVERSING_EVENT) != 0));
262: }
263:
264: /**
265: * Returns <code>null</code> since this function is for generating log messages only.
266: *
267: * @return the value of the function (<code>null</code>).
268: */
269: public Object getValue() {
270: return null;
271: }
272:
273: /**
274: * Returns whether this expression will receive events from subreports.
275: *
276: * @return true, if the function is deep-traversing, false otherwise.
277: */
278: public boolean isDeepTraversing() {
279: return deepTraversing;
280: }
281:
282: /**
283: * Defines, whether this expression will receive events from subreports.
284: *
285: * @param deepTraversing true, if the function is deep-traversing, false otherwise.
286: */
287: public void setDeepTraversing(final boolean deepTraversing) {
288: this.deepTraversing = deepTraversing;
289: }
290: }
|