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
* ClassFactoryCollector.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: ClassFactoryCollector.java,v 1.6 2005/11/14 11:00:23 mungady Exp $
37
* Changes (from 19-Feb-2003)
38
* -------------------------
39
* 19-Feb-2003 : Added standard header and Javadocs (DG);
40
* 29-Apr-2003 : Distilled from the JFreeReport project and moved into JCommon
41
* 03-Jun-2003 : Adding factories configures the new factory.
42
* 29-Jul-2004 : Replaced 'enum' variable name (reserved word in JDK 1.5) (DG);
45
package org.jfree.xml.factory.objects;
47
import java.util.ArrayList;
48
import java.util.Iterator;
50
import org.jfree.util.Configuration;
53
* A class factory collector.
55
* @author Thomas Morgner
57
public class ClassFactoryCollector extends ClassFactoryImpl {
59
/** Storage for the class factories. */
60
private ArrayList factories;
63
* Creates a new class factory collector.
65
public ClassFactoryCollector() {
66
this.factories = new ArrayList();
70
* Adds a class factory to the collection.
72
* @param factory the factory.
74
public void addFactory(final ClassFactory factory) {
75
this.factories.add(factory);
76
if (getConfig() != null) {
77
factory.configure(getConfig());
82
* Returns an iterator the provides access to all the factories in the collection.
84
* @return The iterator.
86
public Iterator getFactories() {
87
return this.factories.iterator();
91
* Returns an object description for a class.
95
* @return The object description.
97
public ObjectDescription getDescriptionForClass(final Class c) {
98
for (int i = 0; i < this.factories.size(); i++) {
99
final ClassFactory f = (ClassFactory) this.factories.get(i);
100
final ObjectDescription od = f.getDescriptionForClass(c);
105
return super.getDescriptionForClass(c);
109
* Returns an object-description for the super class of a class.
111
* @param d the class.
112
* @param knownSuperClass the last known super class or null.
113
* @return The object description.
115
public ObjectDescription getSuperClassObjectDescription
116
(final Class d, ObjectDescription knownSuperClass) {
117
for (int i = 0; i < this.factories.size(); i++) {
118
final ClassFactory f = (ClassFactory) this.factories.get(i);
119
final ObjectDescription od = f.getSuperClassObjectDescription(d, knownSuperClass);
121
if (knownSuperClass == null) {
122
knownSuperClass = od;
125
if (getComparator().isComparable(knownSuperClass.getObjectClass(),
126
od.getObjectClass())) {
127
if (getComparator().compare(knownSuperClass.getObjectClass(),
128
od.getObjectClass()) < 0) {
129
knownSuperClass = od;
135
return super.getSuperClassObjectDescription(d, knownSuperClass);
139
* Returns an iterator that provices access to the registered classes.
141
* @return The iterator.
143
public Iterator getRegisteredClasses() {
144
final ArrayList list = new ArrayList();
145
for (int i = 0; i < this.factories.size(); i++) {
146
final ClassFactory f = (ClassFactory) this.factories.get(i);
147
final Iterator iterator = f.getRegisteredClasses();
148
while (iterator.hasNext()) {
149
list.add(iterator.next());
152
return list.iterator();
156
* Configures this factory. The configuration contains several keys and
157
* their defined values. The given reference to the configuration object
158
* will remain valid until the report parsing or writing ends.
160
* The configuration contents may change during the reporting.
162
* @param config the configuration, never null
164
public void configure(final Configuration config) {
165
if (getConfig() != null) {
166
// already configured ...
169
super.configure(config);
171
final Iterator it = this.factories.iterator();
172
while (it.hasNext()) {
173
final ClassFactory od = (ClassFactory) it.next();
174
od.configure(config);
179
* Tests for equality.
181
* @param o the object to test.
185
public boolean equals(final Object o) {
189
if (!(o instanceof ClassFactoryCollector)) {
192
if (!super.equals(o)) {
196
final ClassFactoryCollector classFactoryCollector = (ClassFactoryCollector) o;
198
if (!this.factories.equals(classFactoryCollector.factories)) {
206
* Returns a hash code for the object.
208
* @return The hash code.
210
public int hashCode() {
211
int result = super.hashCode();
212
result = 29 * result + this.factories.hashCode();