1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* ------------------------------
28
* RenderingHintsReadHandler.java
29
* ------------------------------
30
* (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: RenderingHintsReadHandler.java,v 1.3 2005/10/18 13:33:32 mungady Exp $
39
* 03-Dec-2003 : Initial version
40
* 11-Feb-2004 : Added missing Javadocs (DG);
44
package org.jfree.xml.parser.coretypes;
46
import java.awt.RenderingHints;
47
import java.util.ArrayList;
49
import org.jfree.xml.parser.AbstractXmlReadHandler;
50
import org.jfree.xml.parser.XmlReadHandler;
51
import org.jfree.xml.parser.XmlReaderException;
52
import org.xml.sax.Attributes;
53
import org.xml.sax.SAXException;
56
* A read handler that can parse the XML element for a {@link RenderingHints} collection.
58
public class RenderingHintsReadHandler extends AbstractXmlReadHandler {
60
/** The subhandlers. */
61
private ArrayList handlers;
63
/** The rendering hints under construction. */
64
private RenderingHints renderingHints;
67
* Creates a new read handler.
69
public RenderingHintsReadHandler() {
76
* @param attrs the attributes.
78
* @throws SAXException never.
80
protected void startParsing(final Attributes attrs) throws SAXException {
81
this.handlers = new ArrayList();
85
* Returns the handler for a child element.
87
* @param tagName the tag name.
88
* @param atts the attributes.
90
* @return the handler.
92
* @throws SAXException if there is a parsing error.
93
* @throws XmlReaderException if there is a reader error.
95
protected XmlReadHandler getHandlerForChild(final String tagName, final Attributes atts)
96
throws XmlReaderException, SAXException {
98
if (!tagName.equals("entry")) {
99
throw new SAXException("Expected 'entry' tag.");
102
final XmlReadHandler handler = new RenderingHintValueReadHandler();
103
this.handlers.add(handler);
110
* @throws SAXException if there is a parsing error.
111
* @throws XmlReaderException if there is a reader error.
113
protected void doneParsing() throws SAXException, XmlReaderException {
114
this.renderingHints = new RenderingHints(null);
116
for (int i = 0; i < this.handlers.size(); i++) {
117
final RenderingHintValueReadHandler rh =
118
(RenderingHintValueReadHandler) this.handlers.get(i);
119
this.renderingHints.put(rh.getKey(), rh.getValue());
124
* Returns the object for this element.
126
* @return the object.
128
* @throws XmlReaderException if there is a parsing error.
130
public Object getObject() throws XmlReaderException {
131
return this.renderingHints;