001 /** 002 * ======================================== 003 * JFreeReport : a free Java report library 004 * ======================================== 005 * 006 * Project Info: http://reporting.pentaho.org/ 007 * 008 * (C) Copyright 2000-2007, by Object Refinery Limited, 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 * $Id: StaticDataSourceReadHandler.java 3525 2007-10-16 11:43:48Z tmorgner $ 027 * ------------ 028 * (C) Copyright 2000-2005, by Object Refinery Limited. 029 * (C) Copyright 2005-2007, by Pentaho Corporation. 030 */ 031 032 package org.jfree.report.modules.factories.data.beans; 033 034 import java.util.ArrayList; 035 036 import org.jfree.xmlns.parser.AbstractXmlReadHandler; 037 import org.jfree.xmlns.parser.PropertyReadHandler; 038 import org.jfree.xmlns.parser.XmlReadHandler; 039 import org.jfree.report.modules.factories.data.base.DataFactoryReadHandler; 040 import org.jfree.report.modules.data.beans.NamedStaticReportDataFactory; 041 import org.jfree.report.ReportDataFactory; 042 import org.xml.sax.Attributes; 043 import org.xml.sax.SAXException; 044 045 /** 046 * Creation-Date: 07.04.2006, 17:47:53 047 * 048 * @author Thomas Morgner 049 */ 050 public class StaticDataSourceReadHandler extends AbstractXmlReadHandler 051 implements DataFactoryReadHandler 052 { 053 private ArrayList queries; 054 private ReportDataFactory dataFactory; 055 056 public StaticDataSourceReadHandler() 057 { 058 queries = new ArrayList(); 059 } 060 061 /** 062 * Returns the handler for a child element. 063 * 064 * @param tagName the tag name. 065 * @param atts the attributes. 066 * @return the handler or null, if the tagname is invalid. 067 * @throws org.xml.sax.SAXException if there is a parsing error. 068 * @throws XmlReaderException if there is a reader error. 069 */ 070 protected XmlReadHandler getHandlerForChild(final String uri, 071 final String tagName, 072 final Attributes atts) 073 throws SAXException 074 { 075 if (isSameNamespace(uri) == false) 076 { 077 return null; 078 } 079 080 if ("query".equals(tagName)) 081 { 082 final XmlReadHandler queryReadHandler = new PropertyReadHandler(); 083 queries.add(queryReadHandler); 084 return queryReadHandler; 085 } 086 return null; 087 } 088 089 /** 090 * Done parsing. 091 * 092 * @throws org.xml.sax.SAXException if there is a parsing error. 093 * @throws XmlReaderException if there is a reader error. 094 */ 095 protected void doneParsing() throws SAXException 096 { 097 final NamedStaticReportDataFactory srdf = new NamedStaticReportDataFactory(); 098 for (int i = 0; i < queries.size(); i++) 099 { 100 final PropertyReadHandler handler = (PropertyReadHandler) queries.get(i); 101 srdf.setQuery(handler.getName(), handler.getResult()); 102 } 103 104 srdf.setContentBase(getRootHandler().getSource()); 105 dataFactory = srdf; 106 } 107 108 /** 109 * Returns the object for this element or null, if this element does not 110 * create an object. 111 * 112 * @return the object. 113 * @throws XmlReaderException if there is a parsing error. 114 */ 115 public Object getObject() throws SAXException 116 { 117 return dataFactory; 118 } 119 120 public ReportDataFactory getDataFactory() 121 { 122 return dataFactory; 123 } 124 }