Frames | No Frames |
1: /** 2: * ======================================== 3: * JFreeReport : a free Java report library 4: * ======================================== 5: * 6: * Project Info: http://reporting.pentaho.org/ 7: * 8: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. 9: * 10: * This library is free software; you can redistribute it and/or modify it under the terms 11: * of the GNU Lesser General Public License as published by the Free Software Foundation; 12: * either version 2.1 of the License, or (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16: * See the GNU Lesser General Public License for more details. 17: * 18: * You should have received a copy of the GNU Lesser General Public License along with this 19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20: * Boston, MA 02111-1307, USA. 21: * 22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 23: * in the United States and other countries.] 24: * 25: * ------------ 26: * $Id: DatasourceFactoryReadHandler.java 2725 2007-04-01 18:49:29Z taqua $ 27: * ------------ 28: * (C) Copyright 2000-2005, by Object Refinery Limited. 29: * (C) Copyright 2005-2007, by Pentaho Corporation. 30: */ 31: package org.jfree.report.modules.factories.report.flow; 32: 33: import org.jfree.report.ReportDataFactory; 34: import org.jfree.report.modules.factories.data.base.DataFactoryReadHandler; 35: import org.jfree.resourceloader.Resource; 36: import org.jfree.resourceloader.ResourceCreationException; 37: import org.jfree.resourceloader.ResourceKey; 38: import org.jfree.resourceloader.ResourceKeyCreationException; 39: import org.jfree.resourceloader.ResourceLoadingException; 40: import org.jfree.resourceloader.ResourceManager; 41: import org.jfree.resourceloader.ResourceException; 42: import org.jfree.xmlns.parser.AbstractXmlReadHandler; 43: import org.jfree.xmlns.parser.ParseException; 44: import org.xml.sax.Attributes; 45: import org.xml.sax.SAXException; 46: 47: /** 48: * Creation-Date: 10.04.2006, 13:27:47 49: * 50: * @author Thomas Morgner 51: */ 52: public class DatasourceFactoryReadHandler extends AbstractXmlReadHandler 53: implements DataFactoryReadHandler 54: { 55: private ReportDataFactory dataFactory; 56: 57: public DatasourceFactoryReadHandler() 58: { 59: } 60: 61: /** 62: * Starts parsing. 63: * 64: * @param attrs the attributes. 65: * @throws SAXException if there is a parsing error. 66: */ 67: protected void startParsing(final Attributes attrs) throws SAXException 68: { 69: super.startParsing(attrs); 70: final String href = attrs.getValue(getUri(), "href"); 71: if (href == null) 72: { 73: throw new ParseException("Required attribute 'href' is missing.", getLocator()); 74: } 75: final ResourceKey key = getRootHandler().getSource(); 76: final ResourceManager manager = getRootHandler().getResourceManager(); 77: try 78: { 79: final ResourceKey derivedKey = manager.deriveKey(key, href); 80: final Resource resource = manager.create(derivedKey, null, ReportDataFactory.class); 81: getRootHandler().getDependencyCollector().add(resource); 82: dataFactory = (ReportDataFactory) resource.getResource(); 83: } 84: catch (ResourceKeyCreationException e) 85: { 86: throw new ParseException 87: ("Unable to derive key for " + key + " and " + href, getLocator()); 88: } 89: catch (ResourceCreationException e) 90: { 91: throw new ParseException 92: ("Unable to parse resource for " + key + " and " + href, getLocator()); 93: } 94: catch (ResourceLoadingException e) 95: { 96: throw new ParseException 97: ("Unable to load resource data for " + key + " and " + href, getLocator()); 98: } 99: catch (ResourceException e) 100: { 101: throw new ParseException("Unable to parse resource for " + key + " and " + href, getLocator()); 102: } 103: } 104: 105: public ReportDataFactory getDataFactory() 106: { 107: return dataFactory; 108: } 109: 110: /** 111: * Returns the object for this element or null, if this element does not 112: * create an object. 113: * 114: * @return the object. 115: * @throws SAXException if there is a parsing error. 116: */ 117: public Object getObject() throws SAXException 118: { 119: return dataFactory; 120: } 121: }