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 * TypeInfo.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: TypeInfo.java,v 1.2 2005/10/18 13:32:37 mungady Exp $
036 *
037 * Changes 
038 * -------
039 * 21.06.2003 : Initial version
040 *  
041 */
042
043package org.jfree.xml.generator.model;
044
045/**
046 * Retains information about a type.
047 */
048public class TypeInfo {
049    
050    /** The type name. */
051    private String name;
052    
053    /** The class. */
054    private Class type;
055    
056    /** A flag indicating whether or not the type can take a null value. */
057    private boolean nullable;
058    
059    /** ??. */
060    private boolean constrained;
061    
062    /** A description. */
063    private String description;
064    
065    /** Comments. */
066    private Comments comments;
067
068    /**
069     * Creates a new instance.
070     * 
071     * @param name  the type name (<code>null</code> not permitted).
072     * @param type  the class.
073     */
074    public TypeInfo(final String name, final Class type) {
075        if (name == null) {
076            throw new NullPointerException("Name");
077        }
078        this.name = name;
079        this.type = type;
080    }
081
082    /**
083     * Returns the class.
084     * 
085     * @return The class.
086     */
087    public Class getType() {
088        return this.type;
089    }
090
091    /**
092     * Returns the nullable status.
093     * 
094     * @return A boolean.
095     */
096    public boolean isNullable() {
097        return this.nullable;
098    }
099
100    /**
101     * Sets the nullable flag.
102     * 
103     * @param nullable  the flag.
104     */
105    public void setNullable(final boolean nullable) {
106        this.nullable = nullable;
107    }
108
109    /**
110     * Returns <code>true</code> if the type is constrained, and <code>false</code> otherwise.
111     * 
112     * @return A boolean.
113     */
114    public boolean isConstrained() {
115        return this.constrained;
116    }
117
118    /**
119     * Sets the flag that indicates whether or not the type is constrained.
120     * 
121     * @param constrained  the flag.
122     */
123    public void setConstrained(final boolean constrained) {
124        this.constrained = constrained;
125    }
126
127    /**
128     * Returns the type description.
129     * 
130     * @return The type description.
131     */
132    public String getDescription() {
133        return this.description;
134    }
135
136    /**
137     * Sets the type description.
138     * 
139     * @param description  the description.
140     */
141    public void setDescription(final String description) {
142        this.description = description;
143    }
144
145    /**
146     * Returns the type name.
147     * 
148     * @return The type name.
149     */
150    public String getName() {
151        return this.name;
152    }
153
154    /**
155     * Returns the comments for this type info.
156     * 
157     * @return The comments.
158     */
159    public Comments getComments() {
160        return this.comments;
161    }
162
163    /**
164     * Sets the comments for this type info.
165     * 
166     * @param comments  the comments.
167     */
168    public void setComments(final Comments comments) {
169        this.comments = comments;
170    }
171    /**
172     * Tests this object for equality with another object.
173     * 
174     * @param o  the other object.
175     * 
176     * @return A boolean.
177     */
178    public boolean equals(final Object o) {
179        if (this == o) {
180            return true;
181        }
182        if (!(o instanceof TypeInfo)) {
183            return false;
184        }
185
186        final TypeInfo typeInfo = (TypeInfo) o;
187
188        if (!this.name.equals(typeInfo.name)) {
189            return false;
190        }
191        if (!this.type.equals(typeInfo.type)) {
192            return false;
193        }
194
195        return true;
196    }
197
198    /**
199     * Returns a hash code for this object.
200     * 
201     * @return A hash code.
202     */
203    public int hashCode() {
204        int result;
205        result = this.name.hashCode();
206        result = 29 * result + this.type.hashCode();
207        result = 29 * result + (this.nullable ? 1 : 0);
208        result = 29 * result + (this.constrained ? 1 : 0);
209        result = 29 * result + (this.description != null ? this.description.hashCode() : 0);
210        return result;
211    }
212
213}