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