    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 * JavaBaseClassFactory.java
    029 * -------------------------
    030 * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
    031 *
    032 * Original Author:  Thomas Morgner (taquera@sherito.org);
    033 * Contributor(s):   David Gilbert (for Object Refinery Limited);
    034 *
    035 * $Id: JavaBaseClassFactory.java,v 1.3 2005/11/14 11:02:34 mungady Exp $
    036 *
    037 * Changes
    038 * -------
    039 * 14-Apr-2003 : Initial version
    040 * 29-Apr-2003 : Distilled from the JFreeReport project and moved into JCommon
    041 * 13-Jan-2004 : Did not handle java.awt.Dimension objects correctly.
    042 */
    043package org.jfree.xml.factory.objects;
    044
    045import java.awt.BasicStroke;
    046import java.awt.Color;
    047import java.awt.Dimension;
    048import java.awt.geom.Dimension2D;
    049import java.awt.geom.Line2D;
    050import java.awt.geom.Point2D;
    051import java.awt.geom.Rectangle2D;
    052import java.text.DateFormat;
    053import java.text.DateFormatSymbols;
    054import java.text.DecimalFormat;
    055import java.text.DecimalFormatSymbols;
    056import java.text.Format;
    057import java.text.NumberFormat;
    058import java.text.SimpleDateFormat;
    059import java.util.ArrayList;
    060import java.util.Collection;
    061import java.util.Date;
    062import java.util.HashSet;
    063import java.util.List;
    064import java.util.Set;
    065import java.util.TreeSet;
    066import java.util.Vector;
    067
    068import org.jfree.ui.FloatDimension;
    069
    070/**
    071 * A default factory for all commonly used java base classes from java.lang, java.awt
    072 * etc.
    073 *
    074 * @author Thomas Morgner
    075 */
    076public class JavaBaseClassFactory extends ClassFactoryImpl {
    077
    078    /**
    079     * DefaultConstructor. Creates the object factory for all java base classes.
    080     */
    081    public JavaBaseClassFactory() {
    082        registerClass(Dimension.class, new DimensionObjectDescription());
    083        registerClass(Dimension2D.class, new Dimension2DObjectDescription());
    084        registerClass(FloatDimension.class, new BeanObjectDescription(FloatDimension.class));
    085        registerClass(Date.class, new DateObjectDescription());
    086        registerClass(Boolean.TYPE, new BooleanObjectDescription());
    087        registerClass(Byte.TYPE, new ByteObjectDescription());
    088        registerClass(Double.TYPE, new DoubleObjectDescription());
    089        registerClass(Float.TYPE, new FloatObjectDescription());
    090        registerClass(Integer.TYPE, new IntegerObjectDescription());
    091        registerClass(Long.TYPE, new LongObjectDescription());
    092        registerClass(Short.TYPE, new ShortObjectDescription());
    093        registerClass(Character.TYPE, new CharacterObjectDescription());
    094        registerClass(Character.class, new CharacterObjectDescription());
    095        registerClass(Boolean.class, new BooleanObjectDescription());
    096        registerClass(Byte.class, new ByteObjectDescription());
    097        registerClass(Double.class, new DoubleObjectDescription());
    098        registerClass(Float.class, new FloatObjectDescription());
    099        registerClass(Integer.class, new IntegerObjectDescription());
    100        registerClass(Long.class, new LongObjectDescription());
    101        registerClass(Short.class, new ShortObjectDescription());
    102        registerClass(Line2D.class, new Line2DObjectDescription());
    103        registerClass(Point2D.class, new Point2DObjectDescription());
    104        registerClass(Rectangle2D.class, new Rectangle2DObjectDescription());
    105        registerClass(String.class, new StringObjectDescription());
    106        registerClass(Color.class, new ColorObjectDescription());
    107        registerClass(BasicStroke.class, new BasicStrokeObjectDescription());
    108        registerClass(Object.class, new ClassLoaderObjectDescription());
    109
    110        registerClass(Format.class, new ClassLoaderObjectDescription());
    111        registerClass(NumberFormat.class, createNumberFormatDescription());
    112        registerClass(DecimalFormat.class, new DecimalFormatObjectDescription());
    113        registerClass(DecimalFormatSymbols.class, createDecimalFormatSymbols());
    114        registerClass(DateFormat.class, new ClassLoaderObjectDescription());
    115        registerClass(SimpleDateFormat.class, new SimpleDateFormatObjectDescription());
    116        registerClass(DateFormatSymbols.class, new ClassLoaderObjectDescription());
    117
    118        registerClass(ArrayList.class, new CollectionObjectDescription(ArrayList.class));
    119        registerClass(Vector.class, new CollectionObjectDescription(Vector.class));
    120        registerClass(HashSet.class, new CollectionObjectDescription(HashSet.class));
    121        registerClass(TreeSet.class, new CollectionObjectDescription(TreeSet.class));
    122        registerClass(Set.class, new CollectionObjectDescription(HashSet.class));
    123        registerClass(List.class, new CollectionObjectDescription(ArrayList.class));
    124        registerClass(Collection.class, new CollectionObjectDescription(ArrayList.class));
    125    }
    126
    127    private ObjectDescription createNumberFormatDescription () {
    128        final BeanObjectDescription nfDesc =
    129            new BeanObjectDescription(NumberFormat.class, false);
    130        nfDesc.setParameterDefinition("groupingUsed", Boolean.TYPE);
    131        nfDesc.setParameterDefinition("maximumFractionDigits", Integer.TYPE);
    132        nfDesc.setParameterDefinition("minimumFractionDigits", Integer.TYPE);
    133        nfDesc.setParameterDefinition("maximumIntegerDigits", Integer.TYPE);
    134        nfDesc.setParameterDefinition("minimumIntegerDigits", Integer.TYPE);
    135        nfDesc.setParameterDefinition("parseIntegerOnly", Boolean.TYPE);
    136        return nfDesc;
    137    }
    138
    139    private ObjectDescription createDecimalFormatSymbols() {
    140        final BeanObjectDescription dfsDesc =
    141            new BeanObjectDescription(DecimalFormatSymbols.class, false);
    142        dfsDesc.setParameterDefinition("currencySymbol", String.class);
    143        dfsDesc.setParameterDefinition("decimalSeparator", Character.TYPE);
    144        dfsDesc.setParameterDefinition("digit", Character.TYPE);
    145        dfsDesc.setParameterDefinition("groupingSeparator", Character.TYPE);
    146        dfsDesc.setParameterDefinition("infinity", String.class);
    147        dfsDesc.setParameterDefinition("internationalCurrencySymbol", String.class);
    148        dfsDesc.setParameterDefinition("minusSign", Character.TYPE);
    149        dfsDesc.setParameterDefinition("monetaryDecimalSeparator", Character.TYPE);
    150        dfsDesc.setParameterDefinition("naN", String.class);
    151        dfsDesc.setParameterDefinition("patternSeparator", Character.TYPE);
    152        dfsDesc.setParameterDefinition("perMill", Character.TYPE);
    153        dfsDesc.setParameterDefinition("percent", Character.TYPE);
    154        dfsDesc.setParameterDefinition("zeroDigit", Character.TYPE);
    155        return dfsDesc;
    156
    157    }
    158}