001    /* ========================================================================
002     * JCommon : a free general purpose class library for the Java(tm) platform
003     * ========================================================================
004     *
005     * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006     * 
007     * Project Info:  http://www.jfree.org/jcommon/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it 
010     * under the terms of the GNU Lesser General Public License as published by 
011     * the Free Software Foundation; either version 2.1 of the License, or 
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but 
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022     * USA.  
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025     * in the United States and other countries.]
026     * 
027     * ----------------------
028     * ArrayClassFactory.java
029     * ----------------------
030     * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
031     *
032     * Original Author:  Thomas Morgner;
033     * Contributor(s):   David Gilbert (for Object Refinery Limited);
034     *
035     * $Id: ArrayClassFactory.java,v 1.2 2005/10/18 13:31:58 mungady Exp $
036     *
037     * Changes (from 19-Feb-2003)
038     * -------------------------
039     * 06-May-2003 : Initial version
040     */
041    package org.jfree.xml.factory.objects;
042    
043    import java.util.ArrayList;
044    import java.util.Iterator;
045    
046    import org.jfree.util.Configuration;
047    
048    /**
049     * An class that implements the {@link ClassFactory} interface to
050     * create Arrays of objects. The object descriptions are created on
051     * demand.
052     *
053     * @author Thomas Morgner.
054     */
055    public class ArrayClassFactory implements ClassFactory {
056    
057        /**
058         * Default constructor.
059         */
060        public ArrayClassFactory() {
061            super();
062        }
063    
064        /**
065         * Returns an object description for a class.
066         *
067         * @param c  the class.
068         *
069         * @return The object description.
070         */
071        public ObjectDescription getDescriptionForClass(final Class c) {
072            if (!c.isArray()) {
073                return null;
074            }
075            else {
076                return new ArrayObjectDescription(c);
077            }
078        }
079    
080        /**
081         * Returns an object description for the super class of a class.
082         * This method always returns null.
083         *
084         * @param d  the class.
085         * @param knownSuperClass the last known super class or null.
086         *
087         * @return The object description.
088         */
089        public ObjectDescription getSuperClassObjectDescription
090            (final Class d, final ObjectDescription knownSuperClass) {
091            return null;
092        }
093    
094        /**
095         * Returns an iterator for the registered classes. This returns a list
096         * of pre-registered classes known to this ClassFactory. A class may be able
097         * to handle more than the registered classes.
098         * <p>
099         * This method exists to support query tools for UI design, do not rely on it
100         * for day to day work.
101         *
102         * @return The iterator.
103         */
104        public Iterator getRegisteredClasses() {
105            final ArrayList l = new ArrayList();
106            l.add(Object[].class);
107            return l.iterator();
108        }
109    
110        /**
111         * Configures this factory. The configuration contains several keys and
112         * their defined values. The given reference to the configuration object
113         * will remain valid until the report parsing or writing ends.
114         * <p>
115         * The configuration contents may change during the reporting.
116         *
117         * @param config the configuration, never null
118         */
119        public void configure(final Configuration config) {
120            // nothing required
121        }
122    
123        /**
124         * ArrayClassFactories are always equal, there is nothing that could
125         * not be equal :)
126         *
127         * @param o the other object.
128         * @return true, if both object factories describe the same objects, false otherwise.
129         */
130        public boolean equals(final Object o) {
131            if (this == o) {
132                return true;
133            }
134            if (!(o instanceof ArrayClassFactory)) {
135                return false;
136            }
137            return true;
138        }
139    
140        /**
141         * Returns a hash code value for the object. This method is
142         * supported for the benefit of hashtables such as those provided by
143         * <code>java.util.Hashtable</code>.
144         *
145         * @return the computed hashcode.
146         */
147        public int hashCode() {
148            return getClass().hashCode();
149        }
150    }