    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 * ClassDescription.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: ClassDescription.java,v 1.2 2005/10/18 13:32:37 mungady Exp $
    036 *
    037 * Changes
    038 * -------
    039 * 21-Jun-2003 : Initial version (TM);
    040 * 26-Nov-2003 : Updated header and Javadocs (DG);
    041 *
    042 */
    043
    044package org.jfree.xml.generator.model;
    045
    046/**
    047 * A description of a Java class.
    048 */
    049public class ClassDescription {
    050
    051    /** Storage for info about properties. */
    052    private PropertyInfo[] properties;
    053
    054    /** Constructor descriptions. */
    055    private TypeInfo[] constructorDescription;
    056
    057    /** The class. */
    058    private Class objectClass;
    059
    060    /** A description. */
    061    private String description;
    062
    063    /** The register key. */
    064    private String registerKey;
    065
    066    /** The super class. */
    067    private Class superClass;
    068
    069    /** ??. */
    070    private boolean preserve;
    071
    072    /** The comments. */
    073    private Comments comments;
    074
    075    /** The source. */
    076    private String source;
    077
    078    /**
    079     * Creates a new class description.
    080     *
    081     * @param objectClass  the class.
    082     */
    083    public ClassDescription(final Class objectClass) {
    084        if (objectClass == null) {
    085            throw new NullPointerException();
    086        }
    087        this.objectClass = objectClass;
    088    }
    089
    090    /**
    091     * Returns the info about properties.
    092     *
    093     * @return the info about properties.
    094     */
    095    public PropertyInfo[] getProperties() {
    096        return this.properties;
    097    }
    098
    099    /**
    100     * Sets the info about the class properties.
    101     *
    102     * @param properties  the properties.
    103     */
    104    public void setProperties(final PropertyInfo[] properties) {
    105        this.properties = properties;
    106    }
    107
    108    /**
    109     * Returns the object's class.
    110     *
    111     * @return the object's class.
    112     */
    113    public Class getObjectClass() {
    114        return this.objectClass;
    115    }
    116
    117    /**
    118     * Returns the description.
    119     *
    120     * @return the description.
    121     */
    122    public String getDescription() {
    123        return this.description;
    124    }
    125
    126    /**
    127     * Sets the description for the object.
    128     *
    129     * @param description  the description.
    130     */
    131    public void setDescription(final String description) {
    132        this.description = description;
    133    }
    134
    135    /**
    136     * Returns the class name.
    137     *
    138     * @return the class name.
    139     */
    140    public String getName() {
    141        if (getObjectClass() == null) {
    142            return null;
    143        }
    144        return getObjectClass().getName();
    145    }
    146
    147    /**
    148     * Returns the super class.
    149     *
    150     * @return the super class.
    151     */
    152    public Class getSuperClass() {
    153        return this.superClass;
    154    }
    155
    156    /**
    157     * Sets the super class.
    158     *
    159     * @param superClass  the super class.
    160     */
    161    public void setSuperClass(final Class superClass) {
    162        this.superClass = superClass;
    163    }
    164
    165    /**
    166     * Returns the preserve flag.
    167     *
    168     * @return a boolean.
    169     */
    170    public boolean isPreserve() {
    171        return this.preserve;
    172    }
    173
    174    /**
    175     * Sets the preserve flag.
    176     *
    177     * @param preserve  the new value of the flag.
    178     */
    179    public void setPreserve(final boolean preserve) {
    180        this.preserve = preserve;
    181    }
    182
    183    /**
    184     * Returns the register key.
    185     *
    186     * @return the register key.
    187     */
    188    public String getRegisterKey() {
    189        return this.registerKey;
    190    }
    191
    192    /**
    193     * Sets the register key.
    194     *
    195     * @param registerKey the register key.
    196     */
    197    public void setRegisterKey(final String registerKey) {
    198        this.registerKey = registerKey;
    199    }
    200
    201    /**
    202     * Returns the constructor descriptions.
    203     *
    204     * @return the constructor descriptions.
    205     */
    206    public TypeInfo[] getConstructorDescription() {
    207        return this.constructorDescription;
    208    }
    209
    210    /**
    211     * Sets the constructor description.
    212     *
    213     * @param constructorDescription  the constructor description.
    214     */
    215    public void setConstructorDescription(final TypeInfo[] constructorDescription) {
    216        this.constructorDescription = constructorDescription;
    217    }
    218
    219    /**
    220     * Returns a property.
    221     *
    222     * @param name  the property name.
    223     *
    224     * @return a property.
    225     */
    226    public PropertyInfo getProperty (final String name) {
    227        if (this.properties == null) {
    228            return null;
    229        }
    230        for (int i = 0; i < this.properties.length; i++) {
    231            if (this.properties[i].getName().equals(name)) {
    232                return this.properties[i];
    233            }
    234        }
    235        return null;
    236    }
    237
    238    /**
    239     * Returns <code>true</code> if the description is undefined.
    240     *
    241     * @return a boolean.
    242     */
    243    public boolean isUndefined() {
    244        if (this.properties != null) {
    245            if (this.properties.length > 0) {
    246                return false;
    247            }
    248        }
    249        if (isPreserve()) {
    250            return false;
    251        }
    252        if (getRegisterKey() != null) {
    253            return false;
    254        }
    255        if (getConstructorDescription() != null) {
    256            if (getConstructorDescription().length > 0) {
    257                return false;
    258            }
    259        }
    260        return true;
    261    }
    262
    263    /**
    264     * Returns the comments for the class description.
    265     *
    266     * @return The comments.
    267     */
    268    public Comments getComments() {
    269        return this.comments;
    270    }
    271
    272    /**
    273     * Sets the comments for the class description.
    274     *
    275     * @param comments  the comments.
    276     */
    277    public void setComments(final Comments comments) {
    278        this.comments = comments;
    279    }
    280
    281    /**
    282     * Returns the source for the class description.
    283     *
    284     * @return The source.
    285     */
    286    public String getSource() {
    287        return this.source;
    288    }
    289
    290    /**
    291     * Sets the source for the class description.
    292     *
    293     * @param source  the source.
    294     */
    295    public void setSource(final String source) {
    296        this.source = source;
    297    }
    298
    299}
    300